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

Invalid codegen for wasm at opt-level=0 #51986

Closed
alexcrichton opened this issue Jul 2, 2018 · 0 comments
Closed

Invalid codegen for wasm at opt-level=0 #51986

alexcrichton opened this issue Jul 2, 2018 · 0 comments
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. O-wasm Target: WASM (WebAssembly), http://webassembly.org/

Comments

@alexcrichton
Copy link
Member

I've reported an upstream LLVM bug for this but I want to track it on our side as well to track pulling in the fix. The gist of the issue is that this code:

extern {
    fn return_one() -> u32;
    fn panic() -> !;
}

#[no_mangle]
pub unsafe extern fn test() {
    let tmp: bool = !(return_one() == 1);
    if tmp { panic() }
    if !tmp { panic() }
}

will execute successfully when compiled at O0:

<html>
  <head>
    <script>
const imports = {
  env: {
    return_one: function() { return 1; },
    panic: function() { throw 'bad'; }
  }
};
fetch('foo.wasm')
  .then(r => r.arrayBuffer())
  .then(r => WebAssembly.instantiate(r, imports))
  .then(m => {
    console.log('start');
    m.instance.exports.test()
    console.log('end');
  })
  .catch(e => console.error(e));
    </script>
  </head>
  <body>
  </body>
</html>

And it should certainly panic!

I'm currently hoping we can fix this upstream in LLVM before we need to work around it in rustc!

@alexcrichton alexcrichton added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. O-wasm Target: WASM (WebAssembly), http://webassembly.org/ labels Jul 2, 2018
alexcrichton referenced this issue in rustwasm/wasm-bindgen Jul 2, 2018
alexcrichton added a commit to alexcrichton/rust that referenced this issue Jul 2, 2018
kennytm added a commit to kennytm/rust that referenced this issue Jul 6, 2018
…r=kennytm

Update LLVM to bring in a wasm codegen fix

Closes rust-lang#51986
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. O-wasm Target: WASM (WebAssembly), http://webassembly.org/
Projects
None yet
Development

No branches or pull requests

1 participant