summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2024-02-23 11:19:30 +0100
committerTimm Bäder <tbaeder@redhat.com>2024-02-23 11:59:32 +0100
commit404854ee2018489c15c3454857d92e3bab7c1672 (patch)
treee536eea7401ec2f6e857cfc215ad8b8615c8234c
parent7bb08ee8260c825eb5af4824bc62f73155b4b592 (diff)
[clang][Interp][NFC] Print global variable initialization state
-rw-r--r--clang/lib/AST/Interp/Disasm.cpp8
-rw-r--r--clang/lib/AST/Interp/Program.cpp2
-rw-r--r--clang/lib/AST/Interp/Program.h2
3 files changed, 10 insertions, 2 deletions
diff --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index 3bc9312debeb..315ddb293044 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 61293a3fef47..86e18ede6381 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 7922eafbeb2d..045bf7ab7745 100644
--- a/clang/lib/AST/Interp/Program.h
+++ b/clang/lib/AST/Interp/Program.h
@@ -67,7 +67,7 @@ public:
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) {