https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/164204
One iteration of this loop might've already fixed up the pointers of coming globals, so check for that explicitly. Fixes https://github.com/llvm/llvm-project/issues/164151 >From 1bca5e482592617c4cdef9eb55b3f1efc58cbb81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Mon, 20 Oct 2025 07:42:59 +0200 Subject: [PATCH] [clang][bytecode] Fix a crash when redeclaring extern globals One iteration of this loop might've already fixed up the pointers of coming globals, so check for that explicitly. --- clang/lib/AST/ByteCode/Program.cpp | 5 ++++- clang/test/AST/ByteCode/extern.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp index e653782f61fdf..e0b2852f0e906 100644 --- a/clang/lib/AST/ByteCode/Program.cpp +++ b/clang/lib/AST/ByteCode/Program.cpp @@ -226,7 +226,10 @@ UnsignedOrNone Program::createGlobal(const ValueDecl *VD, const Expr *Init) { Globals[PIdx] = NewGlobal; // All pointers pointing to the previous extern decl now point to the // new decl. - RedeclBlock->movePointersTo(NewGlobal->block()); + // A previous iteration might've already fixed up the pointers for this + // global. + if (RedeclBlock != NewGlobal->block()) + RedeclBlock->movePointersTo(NewGlobal->block()); } } PIdx = *Idx; diff --git a/clang/test/AST/ByteCode/extern.cpp b/clang/test/AST/ByteCode/extern.cpp index a616269911a7e..c3215931d41f8 100644 --- a/clang/test/AST/ByteCode/extern.cpp +++ b/clang/test/AST/ByteCode/extern.cpp @@ -1,9 +1,11 @@ // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=both,expected %s -// RUN: %clang_cc1 -verify=both,ref %s - +// RUN: %clang_cc1 -verify=both,ref %s // both-no-diagnostics +extern const double Num; +extern const double Num = 12; + extern const int E; constexpr int getE() { return E; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
