[clang] 404854e - [clang][Interp][NFC] Print global variable initialization state
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 23 02:59:58 PST 2024
Author: Timm Bäder
Date: 2024-02-23T11:59:32+01:00
New Revision: 404854ee2018489c15c3454857d92e3bab7c1672
URL: https://github.com/llvm/llvm-project/commit/404854ee2018489c15c3454857d92e3bab7c1672
DIFF: https://github.com/llvm/llvm-project/commit/404854ee2018489c15c3454857d92e3bab7c1672.diff
LOG: [clang][Interp][NFC] Print global variable initialization state
Added:
Modified:
clang/lib/AST/Interp/Disasm.cpp
clang/lib/AST/Interp/Program.cpp
clang/lib/AST/Interp/Program.h
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index 3bc9312debeb7e..315ddb293044b7 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -101,6 +101,14 @@ LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) const {
for (const Global *G : Globals) {
const Descriptor *Desc = G->block()->getDescriptor();
OS << GI << ": " << (void *)G->block() << " ";
+ {
+ Pointer GP = getPtrGlobal(GI);
+ ColorScope SC(OS, true,
+ GP.isInitialized()
+ ? TerminalColor{llvm::raw_ostream::GREEN, false}
+ : TerminalColor{llvm::raw_ostream::RED, false});
+ OS << (GP.isInitialized() ? "initialized " : "uninitialized ");
+ }
Desc->dump(OS);
OS << "\n";
++GI;
diff --git a/clang/lib/AST/Interp/Program.cpp b/clang/lib/AST/Interp/Program.cpp
index 61293a3fef4709..86e18ede638114 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -102,7 +102,7 @@ unsigned Program::createGlobalString(const StringLiteral *S) {
return I;
}
-Pointer Program::getPtrGlobal(unsigned Idx) {
+Pointer Program::getPtrGlobal(unsigned Idx) const {
assert(Idx < Globals.size());
return Pointer(Globals[Idx]->block());
}
diff --git a/clang/lib/AST/Interp/Program.h b/clang/lib/AST/Interp/Program.h
index 7922eafbeb2d03..045bf7ab7745b1 100644
--- a/clang/lib/AST/Interp/Program.h
+++ b/clang/lib/AST/Interp/Program.h
@@ -67,7 +67,7 @@ class Program final {
unsigned createGlobalString(const StringLiteral *S);
/// Returns a pointer to a global.
- Pointer getPtrGlobal(unsigned Idx);
+ Pointer getPtrGlobal(unsigned Idx) const;
/// Returns the value of a global.
Block *getGlobal(unsigned Idx) {
More information about the cfe-commits
mailing list