]> git.lizzy.rs Git - rust.git/commitdiff
Update LLVM global variable debug info API for 4.0
authorDylan McKay <dylanmckay34@gmail.com>
Sun, 11 Dec 2016 09:08:20 +0000 (22:08 +1300)
committerDylan McKay <dylanmckay34@gmail.com>
Wed, 14 Dec 2016 08:39:13 +0000 (21:39 +1300)
This teaches Rust about an LLVM 4.0 API change for creating debug info
for global variables.

This change was made in upstream LLVM patch https://reviews.llvm.org/D20147

This is almost 1:1 copy of how clang did it in http://reviews.llvm.org/D20415

src/rustllvm/RustWrapper.cpp

index 85749d883d2f303ed3330a02ad3acac98416493e..f5fa66f1b0e5ae79ed948db604cca268696355a6 100644 (file)
@@ -651,17 +651,32 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable(
     bool isLocalToUnit,
     LLVMValueRef Val,
     LLVMRustMetadataRef Decl = NULL,
-    uint64_t AlignInBits = 0)
-{
-    return wrap(Builder->createGlobalVariable(
-        unwrapDI<DIDescriptor>(Context),
+    uint64_t AlignInBits = 0) {
+    Constant *InitVal = cast<Constant>(unwrap(Val));
+
+#if LLVM_VERSION_GE(4, 0)
+    llvm::DIExpression *InitExpr = nullptr;
+    if (llvm::ConstantInt *IntVal = llvm::dyn_cast<llvm::ConstantInt>(InitVal)) {
+      InitExpr = Builder->createConstantValueExpression(
+          IntVal->getValue().getSExtValue());
+    } else if (llvm::ConstantFP *FPVal = llvm::dyn_cast<llvm::ConstantFP>(InitVal)) {
+        InitExpr = Builder->createConstantValueExpression(
+                FPVal->getValueAPF().bitcastToAPInt().getZExtValue());
+    }
+#endif
+
+    return wrap(Builder->createGlobalVariable(unwrapDI<DIDescriptor>(Context),
         Name,
         LinkageName,
         unwrapDI<DIFile>(File),
         LineNo,
         unwrapDI<DIType>(Ty),
         isLocalToUnit,
-        cast<Constant>(unwrap(Val)),
+#if LLVM_VERSION_GE(4, 0)
+        InitExpr,
+#else
+        InitVal,
+#endif
         unwrapDIptr<MDNode>(Decl)
 #if LLVM_VERSION_GE(4, 0)
         , AlignInBits