Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug][Compiler-v2] WRITEREF_EXISTS_BORROW_ERROR in the test mutable_borrow_local_twice_invalid #13149

Open
rahxephon89 opened this issue May 1, 2024 · 1 comment
Assignees
Labels
bug Something isn't working compiler-v2-stable compiler-v2 stale-exempt Prevents issues from being automatically marked and closed as stale

Comments

@rahxephon89
Copy link
Contributor

rahxephon89 commented May 1, 2024

🐛 Bug

When compiling the following code from the test mutable_borrow_local_twice_invalid.move:

module 0x8675309::M {
    fun t1() {
        let a = 0;
        let r1 = &mut a;
        let r2 = &mut a;
        *r2 = 2;
        *r1 = 1;
    }
}

V2 generates the following bytecode verification error:

Diagnostics:
bug: BYTECODE VERIFICATION FAILED
  ┌─ tests/reference-safety/v1-borrow-tests/mutable_borrow_local_twice_invalid.move:6:9
  │
6 │         *r2 = 2;
  │         ^^^^^^^ ICE failed bytecode verifier: VMError {
    major_status: WRITEREF_EXISTS_BORROW_ERROR,
    sub_status: None,
    message: None,
    exec_state: None,
    location: Module(
        ModuleId {
            address: 0000000000000000000000000000000000000000000000000000000008675309,
            name: Identifier(
                "M",
            ),
        },
    ),
    indices: [
        (
            FunctionDefinition,
            0,
        ),
    ],
    offsets: [
        (
            FunctionDefinitionIndex(0),
            9,
        ),
    ],
}

While V1 generates the following compilation error:

error[E07003]: invalid operation, could create dangling a reference
  ┌─ tests/move_check/translated_ir_tests/move/borrow_tests/mutable_borrow_local_twice_invalid.move:6:9
  │
4 │         let r1 = &mut a;
  │                  ------ It is still being mutably borrowed by this reference
5 │         let r2 = &mut a;
6 │         *r2 = 2;
  │         ^^^^^^^ Invalid mutation of reference.
@rahxephon89 rahxephon89 added bug Something isn't working stale-exempt Prevents issues from being automatically marked and closed as stale compiler-v2 labels May 1, 2024
@rahxephon89
Copy link
Contributor Author

rahxephon89 commented May 1, 2024

For the following code (from the test writeref_borrow_invalid.move):

module 0x8675309::M {
    struct G has copy, drop { v: u64 }
    struct S has copy, drop { g: G }

    fun t1(root: &mut S) {
        let v_mut = &mut root.g.v;
        let g_mut = &mut root.g;

        // INVALID
        *g_mut = G { v: 0 };
        v_mut;
    }
}

V2 generates the bytecode verification error:

Diagnostics:
bug: BYTECODE VERIFICATION FAILED
   ┌─ tests/reference-safety/v1-borrow-tests/writeref_borrow_invalid.move:10:9
   │
10 │         *g_mut = G { v: 0 };
   │         ^^^^^^^^^^^^^^^^^^^ ICE failed bytecode verifier: VMError {
    major_status: WRITEREF_EXISTS_BORROW_ERROR,
    sub_status: None,
    message: None,
    exec_state: None,
    location: Module(
        ModuleId {
            address: 0000000000000000000000000000000000000000000000000000000008675309,
            name: Identifier(
                "M",
            ),
        },
    ),
    indices: [
        (
            FunctionDefinition,
            0,
        ),
    ],
    offsets: [
        (
            FunctionDefinitionIndex(0),
            14,
        ),
    ],
}

While V1 generates the compilation error:

error[E07003]: invalid operation, could create dangling a reference
   ┌─ tests/move_check/translated_ir_tests/move/borrow_tests/writeref_borrow_invalid.move:10:9
   │
 6 │         let v_mut = &mut root.g.v;
   │                     ------------- Field 'v' is still being mutably borrowed by this reference
   ·
10 │         *g_mut = G { v: 0 };
   │         ^^^^^^^^^^^^^^^^^^^ Invalid mutation of reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler-v2-stable compiler-v2 stale-exempt Prevents issues from being automatically marked and closed as stale
Projects
Status: Assigned
Development

No branches or pull requests

2 participants