[clang] [clang][DebugInfo][NFC] Add createConstantValueExpression helper (PR #70674)
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 30 11:04:47 PDT 2023
================
@@ -5935,3 +5918,29 @@ llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs() const {
return llvm::DINode::FlagAllCallsDescribed;
}
+
+llvm::DIExpression *
+CGDebugInfo::createConstantValueExpression(const clang::ValueDecl *VD,
+ const APValue &Val) {
+ // FIXME: Add a representation for integer constants wider than 64 bits.
+ if (CGM.getContext().getTypeSize(VD->getType()) > 64)
+ return nullptr;
+
+ 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();
----------------
dwblaikie wrote:
I'd probably write this as `(uint64_t)*tmp`
https://github.com/llvm/llvm-project/pull/70674
More information about the cfe-commits
mailing list