[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:46 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())
----------------
dwblaikie wrote:

This is a bit redundant/equivalent to:
```
else if (auto tmp = ValInt.trySExtValue())
```

https://github.com/llvm/llvm-project/pull/70674


More information about the cfe-commits mailing list