[clang] [coroutine] Suppress unreachable-code warning on coroutine statements. (PR #77454)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 19 06:30:15 PST 2024
================
@@ -60,6 +61,45 @@ static bool isTrivialDoWhile(const CFGBlock *B, const Stmt *S) {
return false;
}
+// Check if the block starts with a coroutine statement and see if the given
+// unreachable 'S' is the substmt of the coroutine statement.
+//
+// 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) {
----------------
usx95 wrote:
I do not think this works for more interesting cases when coroutine statements are before the `abort`.
Eg:
```cpp
task test() {
co_await 1;
abort();
co_await 2; // expected-warning {{code will never be executed}}
}
```
would fail. We would want a warning in this case.
`co_await 2` has its own block which would be passed to this function (B1 in [CFG](https://godbolt.org/z/Ed3hhzce9))
More test ideas:
```cpp
bool foo();
task test() {
if (foo()) {
std::abort();
co_await 1; // expected-warning {{code will never be executed}}
}
co_await 2;
}
```
https://github.com/llvm/llvm-project/pull/77454
More information about the cfe-commits
mailing list