[flang-commits] [flang] [llvm] [clang] [clang][cleanup] simplify ReachableCode scanFromBlock (PR #72257)

via flang-commits flang-commits at lists.llvm.org
Tue Nov 14 07:34:34 PST 2023


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

>From 52b0204fec8394f9c2cfaeb3cc4f28e5d4c16170 Mon Sep 17 00:00:00 2001
From: thyecust <thy at mail.ecust.edu.cn>
Date: Tue, 14 Nov 2023 21:51:55 +0800
Subject: [PATCH 1/3] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

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();

>From e6ff52675af755e442ffd86906097271a7a3f596 Mon Sep 17 00:00:00 2001
From: thyecust <thy at mail.ecust.edu.cn>
Date: Tue, 14 Nov 2023 22:01:14 +0800
Subject: [PATCH 2/3] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp
index 9c9e1a0fffb3c98..0123730d8ff9798 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -60,7 +60,7 @@ static bool isTrivialDoWhile(const CFGBlock *B, const Stmt *S) {
   return false;
 }
 
-static bool isBuiltinUnreachable(const Stmt *S) {
+static isBuiltinUnreachable(const Stmt *S) {
   if (const auto *DRE = dyn_cast<DeclRefExpr>(S))
     if (const auto *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()))
       return FDecl->getIdentifier() &&
@@ -345,7 +345,7 @@ static unsigned scanFromBlock(const CFGBlock *Start,
     if (IncludeSometimesUnreachableEdges) {
       assert(PP);
       TreatAllSuccessorsAsReachable =
-        shouldTreatSuccessorsAsReachable(item, *PP);
+          shouldTreatSuccessorsAsReachable(item, *PP);
     } else {
       TreatAllSuccessorsAsReachable = false;
     }

>From bcb3f98540cefc570432e541a929b61e9b89e08d Mon Sep 17 00:00:00 2001
From: thyecust <thy at mail.ecust.edu.cn>
Date: Tue, 14 Nov 2023 22:09:16 +0800
Subject: [PATCH 3/3] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp
index 0123730d8ff9798..257fb19e0fcfeb9 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -60,7 +60,7 @@ static bool isTrivialDoWhile(const CFGBlock *B, const Stmt *S) {
   return false;
 }
 
-static isBuiltinUnreachable(const Stmt *S) {
+static bool isBuiltinUnreachable(const Stmt *S) {
   if (const auto *DRE = dyn_cast<DeclRefExpr>(S))
     if (const auto *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()))
       return FDecl->getIdentifier() &&



More information about the flang-commits mailing list