-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[clang][DebugInfo][NFC] Add createConstantValueExpression helper #70674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
82795f2
96a4333
8117a12
ad67ad1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5580,25 +5580,8 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) { | |
auto &GV = DeclCache[VD]; | ||
if (GV) | ||
return; | ||
llvm::DIExpression *InitExpr = nullptr; | ||
if (CGM.getContext().getTypeSize(VD->getType()) <= 64) { | ||
// FIXME: Add a representation for integer constants wider than 64 bits. | ||
if (Init.isInt()) { | ||
const llvm::APSInt &InitInt = Init.getInt(); | ||
std::optional<uint64_t> InitIntOpt; | ||
if (InitInt.isUnsigned()) | ||
InitIntOpt = InitInt.tryZExtValue(); | ||
else if (auto tmp = InitInt.trySExtValue(); tmp.has_value()) | ||
// Transform a signed optional to unsigned optional. When cpp 23 comes, | ||
// use std::optional::transform | ||
InitIntOpt = (uint64_t)tmp.value(); | ||
if (InitIntOpt) | ||
InitExpr = DBuilder.createConstantValueExpression(InitIntOpt.value()); | ||
} else if (Init.isFloat()) | ||
InitExpr = DBuilder.createConstantValueExpression( | ||
Init.getFloat().bitcastToAPInt().getZExtValue()); | ||
} | ||
|
||
llvm::DIExpression *InitExpr = createConstantValueExpression(VD, Init); | ||
llvm::MDTuple *TemplateParameters = nullptr; | ||
|
||
if (isa<VarTemplateSpecializationDecl>(VD)) | ||
|
@@ -5935,3 +5918,28 @@ llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs() const { | |
|
||
return llvm::DINode::FlagAllCallsDescribed; | ||
} | ||
|
||
llvm::DIExpression * | ||
CGDebugInfo::createConstantValueExpression(clang::ValueDecl const *VD, | ||
const APValue &Val) { | ||
llvm::DIExpression *ValExpr = nullptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is how the original code was written, but since we are making a separate function we are now in a position where we can delete this line, early-return on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will do |
||
if (CGM.getContext().getTypeSize(VD->getType()) <= 64) { | ||
// FIXME: Add a representation for integer constants wider than 64 bits. | ||
if (Val.isInt()) { | ||
const llvm::APSInt &ValInt = Val.getInt(); | ||
std::optional<uint64_t> ValIntOpt; | ||
if (ValInt.isUnsigned()) | ||
ValIntOpt = ValInt.tryZExtValue(); | ||
else if (auto tmp = ValInt.trySExtValue(); tmp.has_value()) | ||
// Transform a signed optional to unsigned optional. When cpp 23 comes, | ||
// use std::optional::transform | ||
ValIntOpt = (uint64_t)tmp.value(); | ||
if (ValIntOpt) | ||
ValExpr = DBuilder.createConstantValueExpression(ValIntOpt.value()); | ||
} else if (Val.isFloat()) | ||
ValExpr = DBuilder.createConstantValueExpression( | ||
Val.getFloat().bitcastToAPInt().getZExtValue()); | ||
} | ||
|
||
return ValExpr; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.