Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2172,9 +2172,13 @@ unsafe extern "C" {

pub(crate) safe fn LLVMRustCoverageMappingVersion() -> u32;
pub(crate) fn LLVMRustDebugMetadataVersion() -> u32;

/// Returns the LLVM major version that the compiler was built with.
///
/// Note that this is hard-coded as `LLVM_VERSION_MAJOR` when `RustWrapper.cpp` is built. This
/// could be different than what the runtime LLVM library reports in `LLVMGetVersion`, so we
/// assert their equality in `configure_llvm`.
pub(crate) fn LLVMRustVersionMajor() -> u32;
pub(crate) fn LLVMRustVersionMinor() -> u32;
pub(crate) fn LLVMRustVersionPatch() -> u32;

/// Add LLVM module flags.
///
Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ unsafe fn configure_llvm(sess: &Session) {

// Check to ensure we're running against the correct LLVM version.
unsafe {
let mut llvm_major = 0;
let mut llvm_minor = 0;
let mut llvm_patch = 0;
llvm::LLVMGetVersion(&mut llvm_major, &mut llvm_minor, &mut llvm_patch);
let (llvm_major, llvm_minor, llvm_patch) = get_version();
let expected_version = llvm::LLVMRustVersionMajor();
if llvm_major != expected_version {
sess.dcx().emit_fatal(diagnostics::LlvmVersionMismatch {
Expand Down Expand Up @@ -465,7 +462,11 @@ pub(crate) fn print_version() {
pub(crate) fn get_version() -> (u32, u32, u32) {
// Can be called without initializing LLVM
unsafe {
(llvm::LLVMRustVersionMajor(), llvm::LLVMRustVersionMinor(), llvm::LLVMRustVersionPatch())
let mut llvm_major = 0;
let mut llvm_minor = 0;
let mut llvm_patch = 0;
llvm::LLVMGetVersion(&mut llvm_major, &mut llvm_minor, &mut llvm_patch);
(llvm_major, llvm_minor, llvm_patch)
}
}

Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,10 +885,6 @@ extern "C" uint32_t LLVMRustDebugMetadataVersion() {
return DEBUG_METADATA_VERSION;
}

extern "C" uint32_t LLVMRustVersionPatch() { return LLVM_VERSION_PATCH; }

extern "C" uint32_t LLVMRustVersionMinor() { return LLVM_VERSION_MINOR; }

extern "C" uint32_t LLVMRustVersionMajor() { return LLVM_VERSION_MAJOR; }

// FFI equivalent of LLVM's `llvm::Module::ModFlagBehavior`.
Expand Down
Loading