Skip to content

Commit

Permalink
Rollup merge of rust-lang#40581 - TimNN:di-global-40, r=alexcrichton
Browse files Browse the repository at this point in the history
[LLVM 4.0] Add missing debuginfo metadata to globals

Fixes rust-lang#40580.

cc @rkruppe
cc rust-lang#40123
  • Loading branch information
frewsxcv authored Mar 18, 2017
2 parents 4b987ab + 95bd7f2 commit c991ce4
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<Constant>(unwrap(V));
llvm::GlobalVariable *InitVal = cast<llvm::GlobalVariable>(unwrap(V));

#if LLVM_VERSION_GE(4, 0)
llvm::DIExpression *InitExpr = nullptr;
Expand All @@ -606,26 +607,21 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable(
InitExpr = Builder->createConstantValueExpression(
FPVal->getValueAPF().bitcastToAPInt().getZExtValue());
}
#endif

#if LLVM_VERSION_GE(4, 0)
return wrap(Builder->createGlobalVariableExpression(
llvm::DIGlobalVariableExpression *VarExpr = Builder->createGlobalVariableExpression(
unwrapDI<DIDescriptor>(Context), Name, LinkageName,
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), IsLocalToUnit,
InitExpr, unwrapDIPtr<MDNode>(Decl), AlignInBits);

InitVal->setMetadata("dbg", VarExpr);

return wrap(VarExpr);
#else
return wrap(Builder->createGlobalVariable(
#endif
unwrapDI<DIDescriptor>(Context), Name, LinkageName,
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), IsLocalToUnit,
#if LLVM_VERSION_GE(4, 0)
InitExpr,
#else
InitVal,
#endif
unwrapDIPtr<MDNode>(Decl)
#if LLVM_VERSION_GE(4, 0)
,
AlignInBits
InitVal, unwrapDIPtr<MDNode>(Decl)));
#endif
));
}

extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateVariable(
Expand Down

0 comments on commit c991ce4

Please sign in to comment.