Skip to content

Commit 2c5bed6

Browse files
tbaederrAlexisPerry
authored andcommitted
[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.
1 parent 739886e commit 2c5bed6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

clang/lib/AST/Interp/Disasm.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "Program.h"
2626
#include "clang/AST/ASTDumperUtils.h"
2727
#include "clang/AST/DeclCXX.h"
28+
#include "clang/AST/ExprCXX.h"
2829
#include "llvm/Support/Compiler.h"
2930
#include "llvm/Support/Format.h"
3031

@@ -154,6 +155,19 @@ LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) const {
154155
OS << (GP.isInitialized() ? "initialized " : "uninitialized ");
155156
}
156157
Desc->dump(OS);
158+
159+
if (Desc->IsTemporary) {
160+
if (const auto *MTE =
161+
dyn_cast_if_present<MaterializeTemporaryExpr>(Desc->asExpr());
162+
MTE && MTE->getLifetimeExtendedTemporaryDecl()) {
163+
const APValue *V = MTE->getLifetimeExtendedTemporaryDecl()->getValue();
164+
if (V->isInt())
165+
OS << " (global temporary value: " << V->getInt() << ")";
166+
else
167+
OS << " (huh?)";
168+
}
169+
}
170+
157171
OS << "\n";
158172
if (GP.isInitialized() && Desc->isPrimitive() && !Desc->isDummy()) {
159173
OS << " ";

0 commit comments

Comments
 (0)