1
Fork 0

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
This commit is contained in:
bors 2016-12-14 17:36:01 +00:00
commit b197e4a45f

View file

@ -651,17 +651,32 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable(
bool isLocalToUnit, bool isLocalToUnit,
LLVMValueRef Val, LLVMValueRef Val,
LLVMRustMetadataRef Decl = NULL, LLVMRustMetadataRef Decl = NULL,
uint64_t AlignInBits = 0) uint64_t AlignInBits = 0) {
{ Constant *InitVal = cast<Constant>(unwrap(Val));
return wrap(Builder->createGlobalVariable(
unwrapDI<DIDescriptor>(Context), #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, Name,
LinkageName, LinkageName,
unwrapDI<DIFile>(File), unwrapDI<DIFile>(File),
LineNo, LineNo,
unwrapDI<DIType>(Ty), unwrapDI<DIType>(Ty),
isLocalToUnit, isLocalToUnit,
cast<Constant>(unwrap(Val)), #if LLVM_VERSION_GE(4, 0)
InitExpr,
#else
InitVal,
#endif
unwrapDIptr<MDNode>(Decl) unwrapDIptr<MDNode>(Decl)
#if LLVM_VERSION_GE(4, 0) #if LLVM_VERSION_GE(4, 0)
, AlignInBits , AlignInBits