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

Unary minus generates wrong SSA #2412

Closed
alexvitkov opened this issue Aug 23, 2023 · 2 comments
Closed

Unary minus generates wrong SSA #2412

alexvitkov opened this issue Aug 23, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@alexvitkov
Copy link
Contributor

alexvitkov commented Aug 23, 2023

Aim

The following assert fails:

fn main() {
    let x: i32 = -1;
    assert(1 - 2 == x);
}

Here's the generated SSA -- as far as I can see the issue is a missing truncate after the first sub:

    v2 = sub i32 0, i32 1
    v4 = sub i32 1, i32 2
    v5 = truncate v4 to 32 bits, max_bit_size: 33
    v6 = eq v5, v2
    constrain v6
    return

Note that this example succeeds (explicitly state 0-1 instead of -1):

fn main() {
    let x: i32 = 0-1;
    assert(1 - 2 == x);
}

and here's its SSA:

Initial SSA:
acir fn main f0 {
  b0():
    v2 = sub i32 0, i32 1
    v3 = truncate v2 to 32 bits, max_bit_size: 33
    v5 = sub i32 1, i32 2
    v6 = truncate v5 to 32 bits, max_bit_size: 33
    v7 = eq v6, v3
    constrain v7
    return
}

Expected Behavior

assert passes

Bug

it doesn't

To Reproduce

No response

Installation Method

None

Nargo Version

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

Yes

Support Needs

No response

@alexvitkov alexvitkov added the bug Something isn't working label Aug 23, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Aug 23, 2023
@alexvitkov
Copy link
Contributor Author

I've submitted a fix: #2413

@vezenovm
Copy link
Contributor

Resolved by #2413 so closing

@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

2 participants