Skip to content

Commit

Permalink
Auto merge of rust-lang#110494 - majaha:noTrapAfterNoreturn, r=nikic
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Dec 16, 2023
2 parents e223c41 + 4a8c5cb commit 02ad667
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 02ad667

Please sign in to comment.