rust-lang/rust · #162034

Make the LLVM version mismatch ICE a fatal error

saethlin · merged Aug 31, 20263 files · 19 + / 9
compiler/rustc_codegen_llvm/src/diagnostics.rs13 + / 1
@@ -1,4 +1,4 @@-use std::ffi::CString;+use std::ffi::{CString, c_uint}; use std::path::Path;  use rustc_data_structures::small_c_str::SmallCStr;@@ -265,3 +265,15 @@ pub(crate) struct IntrinsicWrongArch<'a> { pub(crate) struct UnknownLlvmTargetFeaturePrefix<'a> {     pub feature: &'a str, }++#[derive(Diagnostic)]+#[diag(+    "LLVM version mismatch: this compiler was built for LLVM {$expected_version}, but LLVM {$llvm_major}.{$llvm_minor}.{$llvm_patch} was found{$dll_loc}"+)]+pub(crate) struct LlvmVersionMismatch<'a> {+    pub expected_version: c_uint,+    pub llvm_major: c_uint,+    pub llvm_minor: c_uint,+    pub llvm_patch: c_uint,+    pub dll_loc: &'a str,+}
compiler/rustc_codegen_llvm/src/llvm_util.rs5 + / 8
@@ -56,20 +56,17 @@ unsafe fn configure_llvm(sess: &Session) {         llvm::LLVMGetVersion(&mut llvm_major, &mut llvm_minor, &mut llvm_patch);         let expected_version = llvm::LLVMRustVersionMajor();         if llvm_major != expected_version {-            panic!(-                concat!(-                    "LLVM version mismatch: this compiler was built for LLVM {}, ",-                    "but LLVM {}.{}.{} was found{}"-                ),+            sess.dcx().emit_fatal(diagnostics::LlvmVersionMismatch {                 expected_version,                 llvm_major,                 llvm_minor,                 llvm_patch,-                match rustc_session::filesearch::dll_path(llvm::LLVMGetVersion as *mut _) {+                dll_loc: &match rustc_session::filesearch::dll_path(llvm::LLVMGetVersion as *mut _)+                {                     Ok(path) => format!(" at {}", path.display()),                     Err(_) => String::new(),-                }-            );+                },+            })         }     } 
compiler/rustc_macros/src/diagnostics/message.rs1 + / 0
@@ -133,6 +133,7 @@ const ALLOWED_CAPITALIZED_WORDS: &[&str] = &[     "Cargo",     "Ferris",     "GCC",+    "LLVM",     "MIR",     "NaNs",     "OK",