diff options
author | ivanaivanovska <iivanovska@google.com> | 2024-08-02 13:49:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-02 13:49:11 +0200 |
commit | db1375f6d907f1af34c03b5174b7e0432f615d21 (patch) | |
tree | 3dd30b5a6f90df11ef305107922155bdf34970ff /clang/lib/Sema/SemaStmt.cpp | |
parent | adac04ffc90adebbaa0661d642f482dab8440df5 (diff) | |
download | llvm-db1375f6d907f1af34c03b5174b7e0432f615d21.zip llvm-db1375f6d907f1af34c03b5174b7e0432f615d21.tar.gz llvm-db1375f6d907f1af34c03b5174b7e0432f615d21.tar.bz2 |
Surface error for plain return statement in coroutine earlier (#100985)
When a plain return statement was used in a coroutine, the error "return
statement not allowed in coroutine" was surfaced too late (e.g. after
other errors in the return statement). Surfacing it earlier now, to make
the issue more obvious.
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
-rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 34d2d39..d283eaa 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -3747,6 +3747,16 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, Diag(ReturnLoc, diag::err_acc_branch_in_out_compute_construct) << /*return*/ 1 << /*out of */ 0); + // using plain return in a coroutine is not allowed. + FunctionScopeInfo *FSI = getCurFunction(); + if (FSI->FirstReturnLoc.isInvalid() && FSI->isCoroutine()) { + assert(FSI->FirstCoroutineStmtLoc.isValid() && + "first coroutine location not set"); + Diag(ReturnLoc, diag::err_return_in_coroutine); + Diag(FSI->FirstCoroutineStmtLoc, diag::note_declared_coroutine_here) + << FSI->getFirstCoroutineStmtKeyword(); + } + StmtResult R = BuildReturnStmt(ReturnLoc, RetVal.get(), /*AllowRecovery=*/true); if (R.isInvalid() || ExprEvalContexts.back().isDiscardedStatementContext()) |