summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-12-16 18:55:01 +0000
committerbors <bors@rust-lang.org>2023-12-16 18:55:01 +0000
commit02ad6676ddc7ea7bc3acd73f383180bc80185aeb (patch)
tree865cd72bb47515e73948e0bc62fcacc495755187 /compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
parente223c41028def5123ffd2a4a51a9109b1aae2c2e (diff)
parent4a8c5cbe7a86079fddb573957aadd8e0dc203bae (diff)
downloadrust-02ad6676ddc7ea7bc3acd73f383180bc80185aeb.tar.gz
rust-02ad6676ddc7ea7bc3acd73f383180bc80185aeb.zip
Auto merge of #110494 - majaha:noTrapAfterNoreturn, r=nikic
Use the LLVM option NoTrapAfterNoreturn

Use this LLVM option: https://llvm.org/doxygen/classllvm_1_1TargetOptions.html#acd83fce25de1ac9f6c975135a8235c22 when TrapUnreachable is enabled. This prevents codegenning unnecessary double-traps in some situations.

See further discussion here: https://github.com/rust-lang/compiler-team/issues/618
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp')
-rw-r--r--compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp8
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 556dc890a84..cf3f526400d 100644
--- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
+++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
@@ -468,6 +468,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) {