diff options
| author | Dylan McKay <dylanmckay34@gmail.com> | 2016-12-11 22:08:20 +1300 |
|---|---|---|
| committer | Dylan McKay <dylanmckay34@gmail.com> | 2016-12-14 21:39:13 +1300 |
| commit | e080804f72fe937ed36cd6656f5f119959529945 (patch) | |
| tree | bca194bbdcf14d7b84cc9c339fc601fe868124bb /src/rustllvm/RustWrapper.cpp | |
| parent | aa7a2e9e61cfb9469c7eb88308fa2e1a087ebdb4 (diff) | |
| download | rust-e080804f72fe937ed36cd6656f5f119959529945.tar.gz rust-e080804f72fe937ed36cd6656f5f119959529945.zip | |
Update LLVM global variable debug info API for 4.0
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
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
| -rw-r--r-- | src/rustllvm/RustWrapper.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 85749d883d2..f5fa66f1b0e 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -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 |
