llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

Avoid the `Redecl == VD` iteration.

---
Full diff: https://github.com/llvm/llvm-project/pull/208477.diff


1 Files Affected:

- (modified) clang/lib/AST/ByteCode/Program.cpp (+11-12) 


``````````diff
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;
   }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/208477
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to