[llvm] Ensure NoTrapAfterNoreturn is false for the wasm backend (PR #65876)

Matt Harding via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 22 06:29:55 PDT 2023


majaha wrote:

Ah, I think you've misunderstood me a little. I didn't quite say that.

The Rust compiler sets `TargetOptions.TrapUnreachable = true` by default, for all targets include x86 and wasm. This was/is a workaround for [a bug](https://bugs.llvm.org//show_bug.cgi?id=965) in LLVM, you can read more about that in the issues I linked. That bug *should* be fixed now, but there may be other bugs like it lurking in LLVM, and the Rust devs are conservatively keeping TrapUnreachable on by default for now.
It's also a hardening measure against any bugs in LLVM, the Rust compiler, or Rust user code that cause an LLVM `unreachable` instruction to be reached, making it likely such bugs will cause a trap instead of execution running off the end of the function.

The Rust compiler *wants* to set `TargetOptions.NoTrapAfterNoretun = true` by default, too. This is because it's a conservative way to reduce the file size impact of TrapUnreachable, without turning it off completely.

The problem is that setting `TargetOptions.NoTrapAfterNoretun = true` causes bugs in the WebAssembly back-end. This PR fixes that.

https://github.com/llvm/llvm-project/pull/65876


More information about the llvm-commits mailing list