Skip to content

Commit 7b0c51a

Browse files
authored
[clang][bytecode] Fix a crash when redeclaring extern globals (llvm#164204)
One iteration of this loop might've already fixed up the pointers of coming globals, so check for that explicitly. Fixes llvm#164151
1 parent 6d663cd commit 7b0c51a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ UnsignedOrNone Program::createGlobal(const ValueDecl *VD, const Expr *Init) {
226226
Globals[PIdx] = NewGlobal;
227227
// All pointers pointing to the previous extern decl now point to the
228228
// new decl.
229-
RedeclBlock->movePointersTo(NewGlobal->block());
229+
// A previous iteration might've already fixed up the pointers for this
230+
// global.
231+
if (RedeclBlock != NewGlobal->block())
232+
RedeclBlock->movePointersTo(NewGlobal->block());
230233
}
231234
}
232235
PIdx = *Idx;

clang/test/AST/ByteCode/extern.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=both,expected %s
2-
// RUN: %clang_cc1 -verify=both,ref %s
3-
2+
// RUN: %clang_cc1 -verify=both,ref %s
43

54
// both-no-diagnostics
65

6+
extern const double Num;
7+
extern const double Num = 12;
8+
79
extern const int E;
810
constexpr int getE() {
911
return E;

0 commit comments

Comments
 (0)