Skip to content

Commit b197e4a

Browse files
committed
Auto merge of #38295 - dylanmckay:llvm-4.0-di-globalvar, r=michaelwoerister
[LLVM 4.0] 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 a 1:1 copy of how clang did it in http://reviews.llvm.org/D20415
2 parents 4cda3b6 + e080804 commit b197e4a

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/rustllvm/RustWrapper.cpp

+20-5
Original file line numberDiff line numberDiff line change
@@ -651,17 +651,32 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable(
651651
bool isLocalToUnit,
652652
LLVMValueRef Val,
653653
LLVMRustMetadataRef Decl = NULL,
654-
uint64_t AlignInBits = 0)
655-
{
656-
return wrap(Builder->createGlobalVariable(
657-
unwrapDI<DIDescriptor>(Context),
654+
uint64_t AlignInBits = 0) {
655+
Constant *InitVal = cast<Constant>(unwrap(Val));
656+
657+
#if LLVM_VERSION_GE(4, 0)
658+
llvm::DIExpression *InitExpr = nullptr;
659+
if (llvm::ConstantInt *IntVal = llvm::dyn_cast<llvm::ConstantInt>(InitVal)) {
660+
InitExpr = Builder->createConstantValueExpression(
661+
IntVal->getValue().getSExtValue());
662+
} else if (llvm::ConstantFP *FPVal = llvm::dyn_cast<llvm::ConstantFP>(InitVal)) {
663+
InitExpr = Builder->createConstantValueExpression(
664+
FPVal->getValueAPF().bitcastToAPInt().getZExtValue());
665+
}
666+
#endif
667+
668+
return wrap(Builder->createGlobalVariable(unwrapDI<DIDescriptor>(Context),
658669
Name,
659670
LinkageName,
660671
unwrapDI<DIFile>(File),
661672
LineNo,
662673
unwrapDI<DIType>(Ty),
663674
isLocalToUnit,
664-
cast<Constant>(unwrap(Val)),
675+
#if LLVM_VERSION_GE(4, 0)
676+
InitExpr,
677+
#else
678+
InitVal,
679+
#endif
665680
unwrapDIptr<MDNode>(Decl)
666681
#if LLVM_VERSION_GE(4, 0)
667682
, AlignInBits

0 commit comments

Comments
 (0)