Skip to content

Commit 95bd7f2

Browse files
committed
add missing global metadata
1 parent 222ca3c commit 95bd7f2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/rustllvm/RustWrapper.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#include "rustllvm.h"
12+
#include "llvm/IR/DebugInfoMetadata.h"
1213
#include "llvm/IR/DiagnosticInfo.h"
1314
#include "llvm/IR/DiagnosticPrinter.h"
1415
#include "llvm/IR/Instructions.h"
@@ -594,7 +595,7 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable(
594595
const char *LinkageName, LLVMRustMetadataRef File, unsigned LineNo,
595596
LLVMRustMetadataRef Ty, bool IsLocalToUnit, LLVMValueRef V,
596597
LLVMRustMetadataRef Decl = nullptr, uint32_t AlignInBits = 0) {
597-
Constant *InitVal = cast<Constant>(unwrap(V));
598+
llvm::GlobalVariable *InitVal = cast<llvm::GlobalVariable>(unwrap(V));
598599

599600
#if LLVM_VERSION_GE(4, 0)
600601
llvm::DIExpression *InitExpr = nullptr;
@@ -607,10 +608,14 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable(
607608
FPVal->getValueAPF().bitcastToAPInt().getZExtValue());
608609
}
609610

610-
return wrap(Builder->createGlobalVariableExpression(
611+
llvm::DIGlobalVariableExpression *VarExpr = Builder->createGlobalVariableExpression(
611612
unwrapDI<DIDescriptor>(Context), Name, LinkageName,
612613
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), IsLocalToUnit,
613-
InitExpr, unwrapDIPtr<MDNode>(Decl), AlignInBits));
614+
InitExpr, unwrapDIPtr<MDNode>(Decl), AlignInBits);
615+
616+
InitVal->setMetadata("dbg", VarExpr);
617+
618+
return wrap(VarExpr);
614619
#else
615620
return wrap(Builder->createGlobalVariable(
616621
unwrapDI<DIDescriptor>(Context), Name, LinkageName,

0 commit comments

Comments
 (0)