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

Matt Harding via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 04:23:47 PDT 2023


================
@@ -37,6 +37,11 @@ static cl::opt<bool>
     EnableTrapUnreachable("trap-unreachable", cl::Hidden,
                           cl::desc("Enable generating trap for unreachable"));
 
+static cl::opt<bool> EnableNoTrapAfterNoreturn(
+    "no-trap-after-noreturn", cl::Hidden,
+    cl::desc("Do not emit a trap instruction for 'unreachable' IR instructions "
+             "after noreturn calls, even if --trap-unreachable is set."));
----------------
majaha wrote:

> Why is this a bugfix? It has been false so far anyway.

Because it can be passed to us as true by llvm's users (e.g. clang, rustc) because it's part of the public API.

> Can you give an example of when it is safe to set NoTrapAfterNoreturn on and when it is not?

For other backends like x86 or ARM, it should always be safe to use `--trap-unreachable` and `--no-trap-after-noreturn`.

However, the WebAssembly backend is special, because it uses the `TrapUnreachable` option outside of its originally intended purpose.
The WebAssembly backend relies on the fact that `TrapUnreachable` is true to produce correct code, so it forces this option to true. 
However, it *also* relies on `NoTrapAfterNoreturn` being false to produce correct code. The original author of the code didn't realise this, and didn't force it to false. This PR fixes this. 

> Btw the current PR makes setting --no-trap-after-noreturn true impossible, because you overrided it in WebAssemblyTargetMachine.cpp.

Only for the WebAssembly backend (which is kinda the point). For other backends it works as expected.

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


More information about the llvm-commits mailing list