File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -651,17 +651,32 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable(
651
651
bool isLocalToUnit,
652
652
LLVMValueRef Val,
653
653
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),
658
669
Name,
659
670
LinkageName,
660
671
unwrapDI<DIFile>(File),
661
672
LineNo,
662
673
unwrapDI<DIType>(Ty),
663
674
isLocalToUnit,
664
- cast<Constant>(unwrap (Val)),
675
+ #if LLVM_VERSION_GE(4, 0)
676
+ InitExpr,
677
+ #else
678
+ InitVal,
679
+ #endif
665
680
unwrapDIptr<MDNode>(Decl)
666
681
#if LLVM_VERSION_GE(4, 0)
667
682
, AlignInBits
You can’t perform that action at this time.
0 commit comments