Skip to content

Commit c935604

Browse files
committed
Auto merge of rust-lang#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: rust-lang/compiler-team#618
2 parents 7cc997d + 4a8c5cb commit c935604

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,14 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
480480
// it prevents control flow from "falling through" into whatever code
481481
// happens to be laid out next in memory.
482482
Options.TrapUnreachable = true;
483+
// But don't emit traps after other traps or no-returns unnecessarily.
484+
// ...except for when targeting WebAssembly, because the NoTrapAfterNoreturn
485+
// option causes bugs in the LLVM WebAssembly backend. You should be able to
486+
// remove this check when Rust's minimum supported LLVM version is >= 18
487+
// https://github.com/llvm/llvm-project/pull/65876
488+
if (!Trip.isWasm()) {
489+
Options.NoTrapAfterNoreturn = true;
490+
}
483491
}
484492

485493
if (Singlethread) {

0 commit comments

Comments
 (0)