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

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 1 06:22:25 PST 2024


================
@@ -493,26 +454,68 @@ bool DeadCodeScan::isDeadCodeRoot(const clang::CFGBlock *Block) {
   return isDeadRoot;
 }
 
-static bool isValidDeadStmt(const Stmt *S) {
+// Check if the given `DeadStmt` is a coroutine statement and is a substmt of
+// the coroutine statement.
+static bool isInCoroutineStmt(const Stmt* DeadStmt, const CFGBlock *Block) {
+  // The coroutine statement, co_return, co_await, or co_yield.
+  const Stmt* CoroStmt = nullptr;
+  // Find the first coroutine statement after the DeadStmt in the block.
+  bool AfterDeadStmt = false;
+  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 (S == DeadStmt)
+        AfterDeadStmt = true;
+      if (AfterDeadStmt &&
+          (llvm::isa<CoreturnStmt>(S) || llvm::isa<CoroutineSuspendExpr>(S))) {
+        CoroStmt = S;
+        break;
+      }
+    }
+  if (!CoroStmt)
+    return false;
+
+  struct Checker : RecursiveASTVisitor<Checker> {
+    const Stmt *StmtToCheck;
----------------
usx95 wrote:

nit: s/StmtToCheck/DeadStmt

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


More information about the cfe-commits mailing list