[PATCH] D70603: Change while to do-while

Seija Kijin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 22 09:58:15 PST 2019


pi1024e created this revision.
pi1024e added a project: LLVM.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
pi1024e added a reviewer: llvm.org.
pi1024e edited reviewers, added: modocache, sammccall, Quuxplusone; removed: llvm.org.

The assert statement says that the location must be a macroID, which is true. However, the while statements checks for that again, which is unnecessary, and gives warnings for returning a potentially non-initialized variable. For this reason, I suggest changing the while to a do-while loop while keeping the assert where it is.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70603

Files:
  clang/lib/Analysis/ReachableCode.cpp


Index: clang/lib/Analysis/ReachableCode.cpp
===================================================================
--- clang/lib/Analysis/ReachableCode.cpp
+++ clang/lib/Analysis/ReachableCode.cpp
@@ -138,10 +138,10 @@
 static SourceLocation getTopMostMacro(SourceLocation Loc, SourceManager &SM) {
   assert(Loc.isMacroID());
   SourceLocation Last;
-  while (Loc.isMacroID()) {
+  do {
     Last = Loc;
     Loc = SM.getImmediateMacroCallerLoc(Loc);
-  }
+  } while (Loc.isMacroID());
   return Last;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70603.230675.patch
Type: text/x-patch
Size: 505 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191122/84c2fe33/attachment.bin>


More information about the cfe-commits mailing list