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

Zhang Yi via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 29 04:03:51 PST 2024


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

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.

>From b0810e71926a7384b66be1dfed390eec1c98d1d6 Mon Sep 17 00:00:00 2001
From: Zhang Yi <18994118902 at 163.com>
Date: Thu, 29 Feb 2024 03:58:50 -0800
Subject: [PATCH] [Transform][ObjCARC] Change the 'for(;;)' to a do-while

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 commit change the 'for(;;)' to a do-while and eliminate some
discord in the code.
---
 llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

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;



More information about the llvm-commits mailing list