[clang] df067e5 - [clang][Interp][NFC] Pretty-print global temporary APValues
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 29 09:29:46 PDT 2024
Author: Timm Bäder
Date: 2024-06-29T18:29:02+02:00
New Revision: df067e567f7793a7c82096df0387a6e6dd31a828
URL: https://github.com/llvm/llvm-project/commit/df067e567f7793a7c82096df0387a6e6dd31a828
DIFF: https://github.com/llvm/llvm-project/commit/df067e567f7793a7c82096df0387a6e6dd31a828.diff
LOG: [clang][Interp][NFC] Pretty-print global temporary APValues
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 56c2b7032f6d5..d946a10c22dc3 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -156,15 +156,28 @@ LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) const {
}
Desc->dump(OS);
- if (Desc->IsTemporary) {
+ if (GP.isInitialized() && 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?)";
+ if (const APValue *V =
+ MTE->getLifetimeExtendedTemporaryDecl()->getValue()) {
+ OS << " (global temporary value: ";
+ {
+ ColorScope SC(OS, true, {llvm::raw_ostream::BRIGHT_MAGENTA, true});
+ std::string VStr;
+ llvm::raw_string_ostream SS(VStr);
+ V->dump(SS, Ctx.getASTContext());
+
+ for (unsigned I = 0; I != VStr.size(); ++I) {
+ if (VStr[I] == '\n')
+ VStr[I] = ' ';
+ }
+ VStr.pop_back(); // Remove the newline (or now space) at the end.
+ OS << VStr;
+ }
+ OS << ')';
+ }
}
}
More information about the cfe-commits
mailing list