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

Const eval incorrectly computes that mutable param is zero #64970

Closed
rinon opened this issue Oct 1, 2019 · 3 comments · Fixed by #64991
Closed

Const eval incorrectly computes that mutable param is zero #64970

rinon opened this issue Oct 1, 2019 · 3 comments · Fixed by #64991
Assignees
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@rinon
Copy link
Contributor

rinon commented Oct 1, 2019

The following code results in a const eval divide by zero error, when it cannot actually error at runtime:

pub fn foo(mut n: i32) {
  if n < 0i32 { n = 0i32 }
  if n > 0i32 {
    dbg!((1i32) / n);
  }
}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=ee4964acbb7fe290cfdaa573fddf5195

@jonas-schievink jonas-schievink added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 1, 2019
@ecstatic-morse
Copy link
Contributor

ecstatic-morse commented Oct 2, 2019

Bisected to 488381c, which corresponds to #64419. cc @wesleywiser @oli-obk

BTW, you need to actually use foo (e.g. by calling it in main) to trigger the error. Just adding fn main() {} won't do it.

@hellow554
Copy link
Contributor

Fun thing, it doesn't even depend on the conditions in the if clause:

pub fn foo(mut n: i32) {
    if false {
        n = 0i32
    }
    if false {
        dbg!((1i32) / n);
    }
}

also ICEs

@rinon
Copy link
Contributor Author

rinon commented Oct 2, 2019

Thanks @wesleywiser!

@bors bors closed this as completed in 34ea559 Oct 2, 2019
rinon added a commit to immunant/c2rust-testsuite that referenced this issue Oct 3, 2019
We need rust-lang/rust#64970 fixed before python will
work again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants