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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 22 13:12:53 PDT 2023


nikic wrote:

> > 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.
> 
> What you did was to silently ignore `NoTrapAfterNoreturn = true` by overriding it to be `false`. Then how can we support the Rust dev who wants to set `NoTrapAfterNoreturn = true`?

The option works for non-wasm targets. Wasm needs to force-disable the option for the same reason it force-enables TrapUnreachable (which is otherwise disabled by default): You would get invalid wasm otherwise.

> Also, my original question was, if setting `NoTrapAfterNoretun` to true causes invalid code as you pointed out in [#65876 (comment)](https://github.com/llvm/llvm-project/pull/65876#issuecomment-1730511244), why does the Rust dev wants to set it to true?

To reduce code size on targets that *do* support the option.

Of course the frontend could instead handle this itself and say that it will set NoTrapAfterNoreturn to true for all targets, but to false for wasm. But it's more robust if targets explicitly ignore the options they cannot support (same as wasm already does for TrapUnreachable itself).

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


More information about the llvm-commits mailing list