Skip to content

Commit df067e5

Browse files
committed
[clang][Interp][NFC] Pretty-print global temporary APValues
1 parent 9efa633 commit df067e5

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

clang/lib/AST/Interp/Disasm.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,28 @@ LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) const {
156156
}
157157
Desc->dump(OS);
158158

159-
if (Desc->IsTemporary) {
159+
if (GP.isInitialized() && Desc->IsTemporary) {
160160
if (const auto *MTE =
161161
dyn_cast_if_present<MaterializeTemporaryExpr>(Desc->asExpr());
162162
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?)";
163+
if (const APValue *V =
164+
MTE->getLifetimeExtendedTemporaryDecl()->getValue()) {
165+
OS << " (global temporary value: ";
166+
{
167+
ColorScope SC(OS, true, {llvm::raw_ostream::BRIGHT_MAGENTA, true});
168+
std::string VStr;
169+
llvm::raw_string_ostream SS(VStr);
170+
V->dump(SS, Ctx.getASTContext());
171+
172+
for (unsigned I = 0; I != VStr.size(); ++I) {
173+
if (VStr[I] == '\n')
174+
VStr[I] = ' ';
175+
}
176+
VStr.pop_back(); // Remove the newline (or now space) at the end.
177+
OS << VStr;
178+
}
179+
OS << ')';
180+
}
168181
}
169182
}
170183

0 commit comments

Comments
 (0)