@@ -5580,25 +5580,8 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) {
5580
5580
auto &GV = DeclCache[VD];
5581
5581
if (GV)
5582
5582
return ;
5583
- llvm::DIExpression *InitExpr = nullptr ;
5584
- if (CGM.getContext ().getTypeSize (VD->getType ()) <= 64 ) {
5585
- // FIXME: Add a representation for integer constants wider than 64 bits.
5586
- if (Init.isInt ()) {
5587
- const llvm::APSInt &InitInt = Init.getInt ();
5588
- std::optional<uint64_t > InitIntOpt;
5589
- if (InitInt.isUnsigned ())
5590
- InitIntOpt = InitInt.tryZExtValue ();
5591
- else if (auto tmp = InitInt.trySExtValue (); tmp.has_value ())
5592
- // Transform a signed optional to unsigned optional. When cpp 23 comes,
5593
- // use std::optional::transform
5594
- InitIntOpt = (uint64_t )tmp.value ();
5595
- if (InitIntOpt)
5596
- InitExpr = DBuilder.createConstantValueExpression (InitIntOpt.value ());
5597
- } else if (Init.isFloat ())
5598
- InitExpr = DBuilder.createConstantValueExpression (
5599
- Init.getFloat ().bitcastToAPInt ().getZExtValue ());
5600
- }
5601
5583
5584
+ llvm::DIExpression *InitExpr = createConstantValueExpression (VD, Init);
5602
5585
llvm::MDTuple *TemplateParameters = nullptr ;
5603
5586
5604
5587
if (isa<VarTemplateSpecializationDecl>(VD))
@@ -5935,3 +5918,32 @@ llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs() const {
5935
5918
5936
5919
return llvm::DINode::FlagAllCallsDescribed;
5937
5920
}
5921
+
5922
+ llvm::DIExpression *
5923
+ CGDebugInfo::createConstantValueExpression (const clang::ValueDecl *VD,
5924
+ const APValue &Val) {
5925
+ // FIXME: Add a representation for integer constants wider than 64 bits.
5926
+ if (CGM.getContext ().getTypeSize (VD->getType ()) > 64 )
5927
+ return nullptr ;
5928
+
5929
+ if (Val.isFloat ())
5930
+ return DBuilder.createConstantValueExpression (
5931
+ Val.getFloat ().bitcastToAPInt ().getZExtValue ());
5932
+
5933
+ if (!Val.isInt ())
5934
+ return nullptr ;
5935
+
5936
+ llvm::APSInt const &ValInt = Val.getInt ();
5937
+ std::optional<uint64_t > ValIntOpt;
5938
+ if (ValInt.isUnsigned ())
5939
+ ValIntOpt = ValInt.tryZExtValue ();
5940
+ else if (auto tmp = ValInt.trySExtValue ())
5941
+ // Transform a signed optional to unsigned optional. When cpp 23 comes,
5942
+ // use std::optional::transform
5943
+ ValIntOpt = static_cast <uint64_t >(*tmp);
5944
+
5945
+ if (ValIntOpt)
5946
+ return DBuilder.createConstantValueExpression (ValIntOpt.value ());
5947
+
5948
+ return nullptr ;
5949
+ }
0 commit comments