diff options
| author | Matt Harding <majaharding@gmail.com> | 2023-04-18 12:24:22 +0100 |
|---|---|---|
| committer | Matt Harding <majaharding@gmail.com> | 2023-11-03 02:36:49 +0000 |
| commit | 4a8c5cbe7a86079fddb573957aadd8e0dc203bae (patch) | |
| tree | d3a69adcfe7d939a59e26230bd8f7c72330baa70 /compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | |
| parent | 50be22964035027398754e54cd3a497efb00f83e (diff) | |
| download | rust-4a8c5cbe7a86079fddb573957aadd8e0dc203bae.tar.gz rust-4a8c5cbe7a86079fddb573957aadd8e0dc203bae.zip | |
Use the LLVM option NoTrapAfterNoreturn
Use the LLVM option NoTrapAfterNoreturn: https://llvm.org/doxygen/classllvm_1_1TargetOptions.html#acd83fce25de1ac9f6c975135a8235c22 when TrapUnreachable is enabled. This prevents codegenning unnecessary double-traps in some situations. Also, ensure NoTrapAfterNoreturn is set to false when targeting WebAssembly, as it is known to cause bugs.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp')
| -rw-r--r-- | compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 31565db1b79..01ad5e2c770 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -480,6 +480,14 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine( // it prevents control flow from "falling through" into whatever code // happens to be laid out next in memory. Options.TrapUnreachable = true; + // But don't emit traps after other traps or no-returns unnecessarily. + // ...except for when targeting WebAssembly, because the NoTrapAfterNoreturn + // option causes bugs in the LLVM WebAssembly backend. You should be able to + // remove this check when Rust's minimum supported LLVM version is >= 18 + // https://github.com/llvm/llvm-project/pull/65876 + if (!Trip.isWasm()) { + Options.NoTrapAfterNoreturn = true; + } } if (Singlethread) { |
