From 449219ab2bf65f465b18c0841d7f8d9d3b958943 Mon Sep 17 00:00:00 2001 From: Tim Neumann Date: Thu, 16 Mar 2017 21:01:05 +0100 Subject: [PATCH 1/3] isolate llvm 4.0 code path --- src/rustllvm/RustWrapper.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index e89f48b4105d3..714fd2459da10 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -606,26 +606,20 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable( InitExpr = Builder->createConstantValueExpression( FPVal->getValueAPF().bitcastToAPInt().getZExtValue()); } -#endif -#if LLVM_VERSION_GE(4, 0) return wrap(Builder->createGlobalVariableExpression( -#else - return wrap(Builder->createGlobalVariable( -#endif unwrapDI(Context), Name, LinkageName, unwrapDI(File), LineNo, unwrapDI(Ty), IsLocalToUnit, -#if LLVM_VERSION_GE(4, 0) InitExpr, + unwrapDIPtr(Decl), + AlignInBits)); #else + return wrap(Builder->createGlobalVariable( + unwrapDI(Context), Name, LinkageName, + unwrapDI(File), LineNo, unwrapDI(Ty), IsLocalToUnit, InitVal, + unwrapDIPtr(Decl))); #endif - unwrapDIPtr(Decl) -#if LLVM_VERSION_GE(4, 0) - , - AlignInBits -#endif - )); } extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateVariable( From 222ca3c4a550e001e0b1bb957f0035d6bd753d4a Mon Sep 17 00:00:00 2001 From: Tim Neumann Date: Thu, 16 Mar 2017 21:03:22 +0100 Subject: [PATCH 2/3] clang-format --- src/rustllvm/RustWrapper.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 714fd2459da10..bb0a44cef672b 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -610,15 +610,12 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable( return wrap(Builder->createGlobalVariableExpression( unwrapDI(Context), Name, LinkageName, unwrapDI(File), LineNo, unwrapDI(Ty), IsLocalToUnit, - InitExpr, - unwrapDIPtr(Decl), - AlignInBits)); + InitExpr, unwrapDIPtr(Decl), AlignInBits)); #else return wrap(Builder->createGlobalVariable( unwrapDI(Context), Name, LinkageName, unwrapDI(File), LineNo, unwrapDI(Ty), IsLocalToUnit, - InitVal, - unwrapDIPtr(Decl))); + InitVal, unwrapDIPtr(Decl))); #endif } From 95bd7f2e013ad79d857ac54b42b362b36ae8806d Mon Sep 17 00:00:00 2001 From: Tim Neumann Date: Thu, 16 Mar 2017 21:10:04 +0100 Subject: [PATCH 3/3] add missing global metadata --- src/rustllvm/RustWrapper.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index bb0a44cef672b..5ab786f40b933 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -9,6 +9,7 @@ // except according to those terms. #include "rustllvm.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/Instructions.h" @@ -594,7 +595,7 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable( const char *LinkageName, LLVMRustMetadataRef File, unsigned LineNo, LLVMRustMetadataRef Ty, bool IsLocalToUnit, LLVMValueRef V, LLVMRustMetadataRef Decl = nullptr, uint32_t AlignInBits = 0) { - Constant *InitVal = cast(unwrap(V)); + llvm::GlobalVariable *InitVal = cast(unwrap(V)); #if LLVM_VERSION_GE(4, 0) llvm::DIExpression *InitExpr = nullptr; @@ -607,10 +608,14 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable( FPVal->getValueAPF().bitcastToAPInt().getZExtValue()); } - return wrap(Builder->createGlobalVariableExpression( + llvm::DIGlobalVariableExpression *VarExpr = Builder->createGlobalVariableExpression( unwrapDI(Context), Name, LinkageName, unwrapDI(File), LineNo, unwrapDI(Ty), IsLocalToUnit, - InitExpr, unwrapDIPtr(Decl), AlignInBits)); + InitExpr, unwrapDIPtr(Decl), AlignInBits); + + InitVal->setMetadata("dbg", VarExpr); + + return wrap(VarExpr); #else return wrap(Builder->createGlobalVariable( unwrapDI(Context), Name, LinkageName,