[llvm] [Transform][ObjCARC] Change the 'for(; ; )' to a do-while (PR #83416)

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 29 04:04:46 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Zhang Yi (zhanyi22333)

<details>
<summary>Changes</summary>

At the moment, there is a TODO item in ObjCARC just to change 'for (;;)' to a do-while. And it is the only place using 'for (;;)' in llvm. In contrary, there are many places using the do-while. It is reasonable to change the 'for(;;)' to a do-while.

This PR change the 'for(;;)' to a do-while and eliminate some discord in the code.

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


1 Files Affected:

- (modified) llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp (+2-3) 


``````````diff
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
index c397ab63f388c4..63b91524763456 100644
--- a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
+++ b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
@@ -659,8 +659,7 @@ bool ObjCARCContract::run(Function &F, AAResults *A, DominatorTree *D) {
     Value *Arg = cast<CallInst>(Inst)->getArgOperand(0);
     Value *OrigArg = Arg;
 
-    // TODO: Change this to a do-while.
-    for (;;) {
+    do {
       ReplaceArgUses(Arg);
 
       // If Arg is a no-op casted pointer, strip one level of casts and iterate.
@@ -683,7 +682,7 @@ bool ObjCARCContract::run(Function &F, AAResults *A, DominatorTree *D) {
         }
         break;
       }
-    }
+    } while (true);
 
     // Replace bitcast users of Arg that are dominated by Inst.
     SmallVector<BitCastInst *, 2> BitCastUsers;

``````````

</details>


https://github.com/llvm/llvm-project/pull/83416


More information about the llvm-commits mailing list