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

Wrong SSA generated for mutable parameters of type MutableReference #2255

Closed
alexvitkov opened this issue Aug 10, 2023 · 0 comments · Fixed by #2264
Closed

Wrong SSA generated for mutable parameters of type MutableReference #2255

alexvitkov opened this issue Aug 10, 2023 · 0 comments · Fixed by #2264
Assignees
Labels
bug Something isn't working ssa

Comments

@alexvitkov
Copy link
Contributor

Aim

The following code should set x to 100 and the assert should pass. However, x's value remains unchanged.
This only happens if the a parameter of become_100 is declared as mutable.

fn become_100(mut a: &mut u32) {
    *a = 100;
}

fn main() {
    let mut x: u32 = 50;
    become_100(&mut x);
    assert(x == 100);
}

Expected Behavior

Assert should pass

Bug

SSA generated if the parameter is declared as mutable (incorrect):

acir fn become_100 f1 {
  b0(v0: reference):
    v1 = allocate
    store v0 at v1
    store u32 100 at v1
    return
}

SSA if the parameter is immutable (correct)

acir fn become_100 f1 {
  b0(v0: reference):
    store u32 100 at v0
    return
}

To Reproduce

Installation Method

Compiled from source

Nargo Version

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ssa
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants