Skip to content

Commit c7426cf

Browse files
debuginfo: Fix issue with unique type IDs not being passed to LLVM for LLVM 3.4
1 parent 0a98a4e commit c7426cf

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/librustc/lib/llvm.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,7 @@ pub mod llvm {
18091809
pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
18101810

18111811
pub fn LLVMRustSetDLLExportStorageClass(V: ValueRef);
1812+
pub fn LLVMVersionMajor() -> c_int;
18121813
pub fn LLVMVersionMinor() -> c_int;
18131814

18141815
pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,

src/librustc/middle/trans/debuginfo.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ use std::collections::HashSet;
179179
use std::gc::Gc;
180180
use std::ptr;
181181
use std::rc::{Rc, Weak};
182-
use std::sync::atomics;
183182
use syntax::util::interner::Interner;
184183
use syntax::codemap::{Span, Pos};
185184
use syntax::{abi, ast, codemap, ast_util, ast_map};
@@ -2356,9 +2355,22 @@ fn set_members_of_composite_type(cx: &CrateContext,
23562355
let mut composite_types_completed =
23572356
debug_context(cx).composite_types_completed.borrow_mut();
23582357
if composite_types_completed.contains(&composite_type_metadata) {
2359-
cx.sess().span_bug(definition_span, "debuginfo::set_members_of_composite_type() - \
2360-
Already completed forward declaration \
2361-
re-encountered.");
2358+
let (llvm_version_major, llvm_version_minor) = unsafe {
2359+
(llvm::LLVMVersionMajor(), llvm::LLVMVersionMinor())
2360+
};
2361+
2362+
let actual_llvm_version = llvm_version_major * 1000000 + llvm_version_minor * 1000;
2363+
let min_supported_llvm_version = 3 * 1000000 + 4 * 1000;
2364+
2365+
if actual_llvm_version < min_supported_llvm_version {
2366+
cx.sess().warn(format!("This version of rustc was built with LLVM {}.{}. \
2367+
Rustc just ran into a known debuginfo corruption problem that \
2368+
often occurs with LLVM versions below 3.4. Please use a rustc built with a \
2369+
newer version of LLVM.", llvm_version_major, llvm_version_minor).as_slice());
2370+
} else {
2371+
cx.sess().bug("debuginfo::set_members_of_composite_type() - \
2372+
Already completed forward declaration re-encountered.");
2373+
}
23622374
} else {
23632375
composite_types_completed.insert(composite_type_metadata);
23642376
}

src/rustllvm/RustWrapper.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateStructType(
318318
unwrapDI<DIArray>(Elements),
319319
RunTimeLang,
320320
unwrapDI<DIType>(VTableHolder)
321-
#if LLVM_VERSION_MINOR >= 5
321+
#if LLVM_VERSION_MINOR >= 4
322322
,UniqueId
323323
#endif
324324
));
@@ -510,7 +510,7 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateUnionType(
510510
Flags,
511511
unwrapDI<DIArray>(Elements),
512512
RunTimeLang
513-
#if LLVM_VERSION_MINOR >= 5
513+
#if LLVM_VERSION_MINOR >= 4
514514
,UniqueId
515515
#endif
516516
));
@@ -734,6 +734,11 @@ LLVMVersionMinor() {
734734
return LLVM_VERSION_MINOR;
735735
}
736736

737+
extern "C" int
738+
LLVMVersionMajor() {
739+
return LLVM_VERSION_MAJOR;
740+
}
741+
737742
// Note that the two following functions look quite similar to the
738743
// LLVMGetSectionName function. Sadly, it appears that this function only
739744
// returns a char* pointer, which isn't guaranteed to be null-terminated. The

0 commit comments

Comments
 (0)