[clang] 61975cd - [clang][Interp][NFC] Print global temporary value in Program::dump()

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 27 10:25:01 PDT 2024


Author: Timm Bäder
Date: 2024-06-27T19:24:35+02:00
New Revision: 61975cdf44a75917a738ca7fa9971b03f6d4fad8

URL: https://github.com/llvm/llvm-project/commit/61975cdf44a75917a738ca7fa9971b03f6d4fad8
DIFF: https://github.com/llvm/llvm-project/commit/61975cdf44a75917a738ca7fa9971b03f6d4fad8.diff

LOG: [clang][Interp][NFC] Print global temporary value in Program::dump()

There is quite a problem here, so print both the value we have in
Program as well as the value from the LifetimeExtendedTemporaryDecl.

Added: 
    

Modified: 
    clang/lib/AST/Interp/Disasm.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index 0ab84d159c58b..8204fd1bc040c 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -25,6 +25,7 @@
 #include "Program.h"
 #include "clang/AST/ASTDumperUtils.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/ExprCXX.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Format.h"
 
@@ -154,6 +155,19 @@ LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) const {
       OS << (GP.isInitialized() ? "initialized " : "uninitialized ");
     }
     Desc->dump(OS);
+
+    if (Desc->IsTemporary) {
+      if (const auto *MTE =
+              dyn_cast_if_present<MaterializeTemporaryExpr>(Desc->asExpr());
+          MTE && MTE->getLifetimeExtendedTemporaryDecl()) {
+        const APValue *V = MTE->getLifetimeExtendedTemporaryDecl()->getValue();
+        if (V->isInt())
+          OS << " (global temporary value: " << V->getInt() << ")";
+        else
+          OS << " (huh?)";
+      }
+    }
+
     OS << "\n";
     if (GP.isInitialized() && Desc->isPrimitive() && !Desc->isDummy()) {
       OS << "   ";


        


More information about the cfe-commits mailing list