https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/208477
Avoid the `Redecl == VD` iteration. >From 9648e47249a59cd6d0d79a80958d91c202cc45fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Thu, 9 Jul 2026 15:39:15 +0200 Subject: [PATCH] Redecl loop --- clang/lib/AST/ByteCode/Program.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp index d73011a8d8dc4..378a190184be9 100644 --- a/clang/lib/AST/ByteCode/Program.cpp +++ b/clang/lib/AST/ByteCode/Program.cpp @@ -200,9 +200,10 @@ UnsignedOrNone Program::createGlobal(const ValueDecl *VD, const Expr *Init, return std::nullopt; Global *NewGlobal = Globals[*Idx]; - // Note that this loop has one iteration where Redecl == VD. - for (const Decl *Redecl : VD->redecls()) { + GlobalIndices[VD] = *Idx; + for (const Decl *Redecl = VD->getPreviousDecl(); Redecl; + Redecl = Redecl->getPreviousDecl()) { // If this redecl was registered as a dummy variable, it is now a proper // global variable and points to the block we just created. if (auto DummyIt = DummyVariables.find(Redecl); @@ -222,17 +223,15 @@ UnsignedOrNone Program::createGlobal(const ValueDecl *VD, const Expr *Init, continue; } - if (Redecl != VD) { - Block *RedeclBlock = Globals[Iter->second]->block(); - // All pointers pointing to the previous extern decl now point to the - // new decl. - // A previous iteration might've already fixed up the pointers for this - // global. - if (RedeclBlock != NewGlobal->block()) - RedeclBlock->movePointersTo(NewGlobal->block()); + Block *RedeclBlock = Globals[Iter->second]->block(); + // All pointers pointing to the previous extern decl now point to the + // new decl. + // A previous iteration might've already fixed up the pointers for this + // global. + if (RedeclBlock != NewGlobal->block()) + RedeclBlock->movePointersTo(NewGlobal->block()); - Globals[Iter->second] = NewGlobal; - } + Globals[Iter->second] = NewGlobal; Iter->second = *Idx; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
