================
@@ -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();
+
+    if (ValIntOpt)
+      return DBuilder.createConstantValueExpression(ValIntOpt.value());
+  } else if (Val.isFloat())
+    return DBuilder.createConstantValueExpression(
+        Val.getFloat().bitcastToAPInt().getZExtValue());
+
+  return nullptr;
----------------
dwblaikie wrote:

could modify this a bit to simplify indentation, maye:

```
if (Val.isFloat())
  return DBUilder.createConstantValueExpression(...);
const llvm::APSInt &ValInt = Val.getInt();
...
if (ValIntOpt)
  return DBuilder.createConstantValueExpression(*ValIntOpt);
return nullptr;
```

https://github.com/llvm/llvm-project/pull/70674
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to