[clang] [coroutine] Suppress unreachable-code warning on coroutine statements. (PR #77454)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 9 04:30:34 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff a529b6eaf05d24518bbe0f0a5539c378252d2671 3d7d3e5e5bc613637cb019e5e370654e0c58b5cd -- clang/test/SemaCXX/coroutine-unreachable-warning.cpp clang/lib/Analysis/ReachableCode.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp
index d839d2f999..ef40432531 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -67,16 +67,16 @@ static bool isTrivialDoWhile(const CFGBlock *B, const Stmt *S) {
 // We suppress the unreachable warning for cases where an unreachable code is
 // a substmt of the coroutine statement, becase removing it will change the
 // function semantic if this is the only coroutine statement of the coroutine.
-static bool isInCoroutineStmt(const CFGBlock *Block, const Stmt* S) {
+static bool isInCoroutineStmt(const CFGBlock *Block, const Stmt *S) {
   // The coroutine statement, co_return, co_await, or co_yield.
-  const Stmt* CoroStmt = nullptr;
+  const Stmt *CoroStmt = nullptr;
   // Find the first coroutine statement in the block.
   for (CFGBlock::const_iterator I = Block->begin(), E = Block->end(); I != E;
        ++I)
     if (std::optional<CFGStmt> CS = I->getAs<CFGStmt>()) {
       const Stmt *S = CS->getStmt();
       if (llvm::isa<CoreturnStmt>(S) || llvm::isa<CoroutineSuspendExpr>(S)) {
-        CoroStmt = S ;
+        CoroStmt = S;
         break;
       }
     }
@@ -665,8 +665,7 @@ void DeadCodeScan::reportDeadCode(const CFGBlock *B,
   } else if (isTrivialDoWhile(B, S) || isBuiltinUnreachable(S) ||
              isBuiltinAssumeFalse(B, S, C) || isInCoroutineStmt(B, S)) {
     return;
-  }
-  else if (isDeadReturn(B, S)) {
+  } else if (isDeadReturn(B, S)) {
     UK = reachable_code::UK_Return;
   }
 

``````````

</details>


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


More information about the cfe-commits mailing list