[clang] d0339ae - [clang][bytecode][NFC] Simplify redecl loop (#208477)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 9 21:01:19 PDT 2026
Author: Timm Baeder
Date: 2026-07-10T06:01:14+02:00
New Revision: d0339aef5f4648106de6ad34932adfb011204772
URL: https://github.com/llvm/llvm-project/commit/d0339aef5f4648106de6ad34932adfb011204772
DIFF: https://github.com/llvm/llvm-project/commit/d0339aef5f4648106de6ad34932adfb011204772.diff
LOG: [clang][bytecode][NFC] Simplify redecl loop (#208477)
Avoid the `Redecl == VD` iteration.
Added:
Modified:
clang/lib/AST/ByteCode/Program.cpp
Removed:
################################################################################
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;
}
More information about the cfe-commits
mailing list