Skip to content

Commit 404854e

Browse files
committed
[clang][Interp][NFC] Print global variable initialization state
1 parent 7bb08ee commit 404854e

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

clang/lib/AST/Interp/Disasm.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ LLVM_DUMP_METHOD void Program::dump(llvm::raw_ostream &OS) const {
101101
for (const Global *G : Globals) {
102102
const Descriptor *Desc = G->block()->getDescriptor();
103103
OS << GI << ": " << (void *)G->block() << " ";
104+
{
105+
Pointer GP = getPtrGlobal(GI);
106+
ColorScope SC(OS, true,
107+
GP.isInitialized()
108+
? TerminalColor{llvm::raw_ostream::GREEN, false}
109+
: TerminalColor{llvm::raw_ostream::RED, false});
110+
OS << (GP.isInitialized() ? "initialized " : "uninitialized ");
111+
}
104112
Desc->dump(OS);
105113
OS << "\n";
106114
++GI;

clang/lib/AST/Interp/Program.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ unsigned Program::createGlobalString(const StringLiteral *S) {
102102
return I;
103103
}
104104

105-
Pointer Program::getPtrGlobal(unsigned Idx) {
105+
Pointer Program::getPtrGlobal(unsigned Idx) const {
106106
assert(Idx < Globals.size());
107107
return Pointer(Globals[Idx]->block());
108108
}

clang/lib/AST/Interp/Program.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Program final {
6767
unsigned createGlobalString(const StringLiteral *S);
6868

6969
/// Returns a pointer to a global.
70-
Pointer getPtrGlobal(unsigned Idx);
70+
Pointer getPtrGlobal(unsigned Idx) const;
7171

7272
/// Returns the value of a global.
7373
Block *getGlobal(unsigned Idx) {

0 commit comments

Comments
 (0)