Skip to content

Commit dfbf610

Browse files
committed
Set LLVM LLVM_UNREACHABLE_OPTIMIZE to OFF
This option was added to LLVM in https://reviews.llvm.org/D121750?id=416339. It makes `llvm_unreachable` in builds without assertions compile to an `LLVM_BUILTIN_TRAP` instead of `LLVM_BUILTIN_UNREACHABLE` (which causes undefined behavior and is equivalent to `std::hint::unreachable_unchecked`). Having compiler bugs triggering undefined behavior generally seems undesirable and inconsistent with Rust's goals. There is a check in `src/tools/tidy/src/style.rs` to reject code using `llvm_unreachable`. But it is used a lot within LLVM itself. For instance, this changes a failure I get compiling `libcore` for m68k from a `SIGSEGV` to `SIGILL`, which seems better though it still doesn't provide a useful message without switching to an LLVM build with asserts. It may be best not to do this if it noticeably degrades compiler performance, but worthwhile if it doesn't do so in any significant way. I haven't looked into what benchmarks there are for Rustc. That should be considered before merging.
1 parent da7c50c commit dfbf610

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/bootstrap/download-ci-llvm-stamp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Change this file to make users of the `download-ci-llvm` configuration download
22
a new version of LLVM from CI, even if the LLVM submodule hasn’t changed.
33

4-
Last change is for: https://github.com/rust-lang/rust/pull/104748
4+
Last change is for: https://github.com/rust-lang/rust/pull/109373

src/bootstrap/native.rs

+1
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ impl Step for Llvm {
309309
cfg.out_dir(&out_dir)
310310
.profile(profile)
311311
.define("LLVM_ENABLE_ASSERTIONS", assertions)
312+
.define("LLVM_UNREACHABLE_OPTIMIZE", "OFF")
312313
.define("LLVM_ENABLE_PLUGINS", plugins)
313314
.define("LLVM_TARGETS_TO_BUILD", llvm_targets)
314315
.define("LLVM_EXPERIMENTAL_TARGETS_TO_BUILD", llvm_exp_targets)

0 commit comments

Comments
 (0)