[clang] [Clang] Warn about `[[noreturn]]` on coroutines (PR #127623)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 18 11:33:47 PST 2025
================
@@ -3910,8 +3910,13 @@ StmtResult Sema::BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
FnRetType = FD->getReturnType();
if (FD->hasAttrs())
Attrs = &FD->getAttrs();
- if (FD->isNoReturn())
- Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr) << FD;
+ if (FD->isNoReturn()) {
+ const FunctionScopeInfo *Scope = getEnclosingFunction();
+ if (Scope && Scope->isCoroutine())
+ Diag(ReturnLoc, diag::warn_noreturn_coroutine) << FD;
+ else
+ Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr) << FD;
+ }
----------------
Sirraide wrote:
```suggestion
if (FD->isNoReturn() && !getCurFunction()->isCoroutine())
Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr) << FD;
```
As is, this would have the effect of emitting a warning on every `return` statement; I don’t think that’s what we want given that the problem is not that we’re returning from a noreturn function, but rather that the function shouldn’t be noreturn to begin with, so I’d do something like this instead.
(also, `getCurFunction()` should be slightly faster than `getEnclosingFunction()` here and is equivalent because we’ve already handled capturing function scopes)
https://github.com/llvm/llvm-project/pull/127623
More information about the cfe-commits
mailing list