]> git.lizzy.rs Git - rust.git/commitdiff
debuginfo: Fix issue with unique type IDs not being passed to LLVM for LLVM 3.4
authorMichael Woerister <michaelwoerister@posteo>
Thu, 12 Jun 2014 16:06:14 +0000 (18:06 +0200)
committerMichael Woerister <michaelwoerister@posteo>
Thu, 12 Jun 2014 16:48:14 +0000 (18:48 +0200)
src/librustc/lib/llvm.rs
src/librustc/middle/trans/debuginfo.rs
src/rustllvm/RustWrapper.cpp

index 75445a317ecfb6c34fc41b2c8e7a1c5576528363..ac9cec84715264e1f483bedce9a22342f2525054 100644 (file)
@@ -1809,6 +1809,7 @@ pub fn LLVMRustArchiveReadSection(AR: ArchiveRef, name: *c_char,
         pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
 
         pub fn LLVMRustSetDLLExportStorageClass(V: ValueRef);
+        pub fn LLVMVersionMajor() -> c_int;
         pub fn LLVMVersionMinor() -> c_int;
 
         pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
index 33a6068fccad74cd20119168585acd873943737c..0b10db56cc42696eae3b5e68b52f50274e324c32 100644 (file)
@@ -179,7 +179,6 @@ struct List {
 use std::gc::Gc;
 use std::ptr;
 use std::rc::{Rc, Weak};
-use std::sync::atomics;
 use syntax::util::interner::Interner;
 use syntax::codemap::{Span, Pos};
 use syntax::{abi, ast, codemap, ast_util, ast_map};
@@ -2356,9 +2355,22 @@ fn set_members_of_composite_type(cx: &CrateContext,
         let mut composite_types_completed =
             debug_context(cx).composite_types_completed.borrow_mut();
         if composite_types_completed.contains(&composite_type_metadata) {
-            cx.sess().span_bug(definition_span, "debuginfo::set_members_of_composite_type() - \
-                                                 Already completed forward declaration \
-                                                 re-encountered.");
+            let (llvm_version_major, llvm_version_minor) = unsafe {
+                (llvm::LLVMVersionMajor(), llvm::LLVMVersionMinor())
+            };
+
+            let actual_llvm_version = llvm_version_major * 1000000 + llvm_version_minor * 1000;
+            let min_supported_llvm_version = 3 * 1000000 + 4 * 1000;
+
+            if actual_llvm_version < min_supported_llvm_version {
+                cx.sess().warn(format!("This version of rustc was built with LLVM {}.{}. \
+                    Rustc just ran into a known debuginfo corruption problem that \
+                    often occurs with LLVM versions below 3.4. Please use a rustc built with a \
+                    newer version of LLVM.", llvm_version_major, llvm_version_minor).as_slice());
+            } else {
+                cx.sess().bug("debuginfo::set_members_of_composite_type() - \
+                               Already completed forward declaration re-encountered.");
+            }
         } else {
             composite_types_completed.insert(composite_type_metadata);
         }
index 2157aecf37613f18104337eca70833917825ef1f..f42844b9f19d2612e3b7873ab5a344b62556e6c4 100644 (file)
@@ -318,7 +318,7 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateStructType(
         unwrapDI<DIArray>(Elements),
         RunTimeLang,
         unwrapDI<DIType>(VTableHolder)
-#if LLVM_VERSION_MINOR >= 5
+#if LLVM_VERSION_MINOR >= 4
         ,UniqueId
 #endif
         ));
@@ -510,7 +510,7 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateUnionType(
         Flags,
         unwrapDI<DIArray>(Elements),
         RunTimeLang
-#if LLVM_VERSION_MINOR >= 5
+#if LLVM_VERSION_MINOR >= 4
         ,UniqueId
 #endif
         ));
@@ -734,6 +734,11 @@ LLVMVersionMinor() {
     return LLVM_VERSION_MINOR;
 }
 
+extern "C" int
+LLVMVersionMajor() {
+    return LLVM_VERSION_MAJOR;
+}
+
 // Note that the two following functions look quite similar to the
 // LLVMGetSectionName function. Sadly, it appears that this function only
 // returns a char* pointer, which isn't guaranteed to be null-terminated. The