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

Incorrect optimization in code fragment #18786

Closed
nstoddard opened this issue Nov 8, 2014 · 6 comments
Closed

Incorrect optimization in code fragment #18786

nstoddard opened this issue Nov 8, 2014 · 6 comments
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.

Comments

@nstoddard
Copy link

I found some code that behaves differently with optimization. With -O0, it prints false; with any higher setting, it prints true.

Sorry about the poor variable names; this is (mostly) a translation from some Javascript code. I've tried to remove as much code as I can, but I'm sure it can still be reduced somewhat and still show the same incorrect behavior.

Edit: the old code sample linked to 'hello world' for some reason. I fixed it.

@sfackler
Copy link
Member

sfackler commented Nov 8, 2014

Is that code sample the right one?

@thomas-huet
Copy link

I have reduced the code to this :

fn main() { 
  for d in range(0u, 1) { 
    let u: uint = (d + 1) % 2;
    let mut x = [0i,..2];
    let mut mask = false;
    while x[u] < 2 { 
      mask = x[1] > 0;
      x[u] += 1;
    } 
    println!("This should be true: {}" , mask);
    if !mask { 
      panic!("Failed!");
    } 
  } 
}

runs fine when compiled with rustc but not when compiled with rustc -O

@nstoddard
Copy link
Author

Whoops, I'm not sure why my link didn't work. Obviously I didn't find a bug in Hello World :). I fixed the link.

@mahkoh
Copy link
Contributor

mahkoh commented Nov 9, 2014

It appears that the code is too long for a get request which is why play doesn't work.

@huonw huonw added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Nov 13, 2014
@nstoddard
Copy link
Author

Is it worth marking this as a release blocker? Incorrect optimizations seem like a big deal that should be fixed before 1.0.

@steveklabnik
Copy link
Member

This code sample now prints 'true' in both cases, with no panic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
Projects
None yet
Development

No branches or pull requests

6 participants