Skip to content

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

Closed
@alexcrichton

Description

@alexcrichton

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.O-wasmTarget: WASM (WebAssembly), http://webassembly.org/

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions