[clang] [clang][cleanup] simplify ReachableCode scanFromBlock (PR #72257)

via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 14 05:55:29 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: thyecust (thyecust)

<details>
<summary>Changes</summary>

We can simplify this function and move some calculations out of loop.

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


1 Files Affected:

- (modified) clang/lib/Analysis/ReachableCode.cpp (+9-12) 


``````````diff
diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp
index 1bf0d9aec8620e1..9c9e1a0fffb3c98 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -341,30 +341,27 @@ static unsigned scanFromBlock(const CFGBlock *Start,
     // This allows us to potentially uncover some "always unreachable" code
     // within the "sometimes unreachable" code.
     // Look at the successors and mark then reachable.
-    std::optional<bool> TreatAllSuccessorsAsReachable;
-    if (!IncludeSometimesUnreachableEdges)
+    bool TreatAllSuccessorsAsReachable;
+    if (IncludeSometimesUnreachableEdges) {
+      assert(PP);
+      TreatAllSuccessorsAsReachable =
+        shouldTreatSuccessorsAsReachable(item, *PP);
+    } else {
       TreatAllSuccessorsAsReachable = false;
+    }
 
     for (CFGBlock::const_succ_iterator I = item->succ_begin(),
          E = item->succ_end(); I != E; ++I) {
       const CFGBlock *B = *I;
-      if (!B) do {
+      if (!B) {
         const CFGBlock *UB = I->getPossiblyUnreachableBlock();
         if (!UB)
           break;
 
-        if (!TreatAllSuccessorsAsReachable) {
-          assert(PP);
-          TreatAllSuccessorsAsReachable =
-            shouldTreatSuccessorsAsReachable(item, *PP);
-        }
-
-        if (*TreatAllSuccessorsAsReachable) {
+        if (TreatAllSuccessorsAsReachable) {
           B = UB;
-          break;
         }
       }
-      while (false);
 
       if (B) {
         unsigned blockID = B->getBlockID();

``````````

</details>


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


More information about the cfe-commits mailing list