diff options
| author | Brian Gesiak <modocache@gmail.com> | 2019-03-22 16:08:29 +0000 |
|---|---|---|
| committer | Brian Gesiak <modocache@gmail.com> | 2019-03-22 16:08:29 +0000 |
| commit | e8b3d63dd5bbd011306511a4ae1cdbd8e4915e5e (patch) | |
| tree | da2b81bd001eba70b8bdb601d3ce06263c24e0c0 /clang/lib | |
| parent | 4c2ef9a02be0562c48143b28bd239e8c42df6ce0 (diff) | |
| download | bcm5719-llvm-e8b3d63dd5bbd011306511a4ae1cdbd8e4915e5e.tar.gz bcm5719-llvm-e8b3d63dd5bbd011306511a4ae1cdbd8e4915e5e.zip | |
Revert "[coroutines][PR40978] Emit error for co_yield within catch block"
The commit https://reviews.llvm.org/rC356296 is causing a regression in nested
catch scopes, https://bugs.llvm.org/show_bug.cgi?id=41171. Revert this change
for now in order to un-break that problem report.
llvm-svn: 356774
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Parse/ParseStmt.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/Sema/Scope.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaCoroutine.cpp | 64 |
3 files changed, 19 insertions, 57 deletions
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index fde19b9ad87..267003b5189 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -2260,10 +2260,8 @@ StmtResult Parser::ParseCXXCatchBlock(bool FnCatch) { // C++ 3.3.2p3: // The name in a catch exception-declaration is local to the handler and // shall not be redeclared in the outermost block of the handler. - unsigned ScopeFlags = Scope::DeclScope | Scope::ControlScope | - Scope::CatchScope | - (FnCatch ? Scope::FnTryCatchScope : 0); - ParseScope CatchScope(this, ScopeFlags); + ParseScope CatchScope(this, Scope::DeclScope | Scope::ControlScope | + (FnCatch ? Scope::FnTryCatchScope : 0)); // exception-declaration is equivalent to '...' or a parameter-declaration // without default arguments. @@ -2292,7 +2290,7 @@ StmtResult Parser::ParseCXXCatchBlock(bool FnCatch) { return StmtError(Diag(Tok, diag::err_expected) << tok::l_brace); // FIXME: Possible draft standard bug: attribute-specifier should be allowed? - StmtResult Block(ParseCompoundStatement(/*isStmtExpr=*/false, ScopeFlags)); + StmtResult Block(ParseCompoundStatement()); if (Block.isInvalid()) return Block; diff --git a/clang/lib/Sema/Scope.cpp b/clang/lib/Sema/Scope.cpp index 51b0b24e57b..09940688efa 100644 --- a/clang/lib/Sema/Scope.cpp +++ b/clang/lib/Sema/Scope.cpp @@ -166,9 +166,7 @@ void Scope::dumpImpl(raw_ostream &OS) const { {SEHExceptScope, "SEHExceptScope"}, {SEHFilterScope, "SEHFilterScope"}, {CompoundStmtScope, "CompoundStmtScope"}, - {ClassInheritanceScope, "ClassInheritanceScope"}, - {CatchScope, "CatchScope"}, - }; + {ClassInheritanceScope, "ClassInheritanceScope"}}; for (auto Info : FlagInfo) { if (Flags & Info.first) { diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp index 9d328f4926a..22a12801da6 100644 --- a/clang/lib/Sema/SemaCoroutine.cpp +++ b/clang/lib/Sema/SemaCoroutine.cpp @@ -185,8 +185,21 @@ static QualType lookupCoroutineHandleType(Sema &S, QualType PromiseType, static bool isValidCoroutineContext(Sema &S, SourceLocation Loc, StringRef Keyword) { - // [expr.await]p2 dictates that 'co_await' and 'co_yield' must be used within - // a function body. + // 'co_await' and 'co_yield' are not permitted in unevaluated operands, + // such as subexpressions of \c sizeof. + // + // [expr.await]p2, emphasis added: "An await-expression shall appear only in + // a *potentially evaluated* expression within the compound-statement of a + // function-body outside of a handler [...] A context within a function where + // an await-expression can appear is called a suspension context of the + // function." And per [expr.yield]p1: "A yield-expression shall appear only + // within a suspension context of a function." + if (S.isUnevaluatedContext()) { + S.Diag(Loc, diag::err_coroutine_unevaluated_context) << Keyword; + return false; + } + + // Per [expr.await]p2, any other usage must be within a function. // FIXME: This also covers [expr.await]p2: "An await-expression shall not // appear in a default argument." But the diagnostic QoI here could be // improved to inform the user that default arguments specifically are not @@ -655,57 +668,12 @@ bool Sema::ActOnCoroutineBodyStart(Scope *SC, SourceLocation KWLoc, return true; } -// Recursively walks up the scope hierarchy until either a 'catch' or a function -// scope is found, whichever comes first. -static bool isWithinCatchScope(Scope *S) { - // 'co_await' and 'co_yield' keywords are disallowed within catch blocks, but - // lambdas that use 'co_await' are allowed. The loop below ends when a - // function scope is found in order to ensure the following behavior: - // - // void foo() { // <- function scope - // try { // - // co_await x; // <- 'co_await' is OK within a function scope - // } catch { // <- catch scope - // co_await x; // <- 'co_await' is not OK within a catch scope - // []() { // <- function scope - // co_await x; // <- 'co_await' is OK within a function scope - // }(); - // } - // } - while (S && !(S->getFlags() & Scope::FnScope)) { - if (S->getFlags() & Scope::CatchScope) - return true; - S = S->getParent(); - } - return false; -} - -// [expr.await]p2, emphasis added: "An await-expression shall appear only in -// a *potentially evaluated* expression within the compound-statement of a -// function-body *outside of a handler* [...] A context within a function -// where an await-expression can appear is called a suspension context of the -// function." -static void checkSuspensionContext(Sema &S, SourceLocation Loc, - StringRef Keyword) { - // First emphasis of [expr.await]p2: must be a potentially evaluated context. - // That is, 'co_await' and 'co_yield' cannot appear in subexpressions of - // \c sizeof. - if (S.isUnevaluatedContext()) - S.Diag(Loc, diag::err_coroutine_unevaluated_context) << Keyword; - - // Second emphasis of [expr.await]p2: must be outside of an exception handler. - if (isWithinCatchScope(S.getCurScope())) - S.Diag(Loc, diag::err_coroutine_within_handler) << Keyword; -} - ExprResult Sema::ActOnCoawaitExpr(Scope *S, SourceLocation Loc, Expr *E) { if (!ActOnCoroutineBodyStart(S, Loc, "co_await")) { CorrectDelayedTyposInExpr(E); return ExprError(); } - checkSuspensionContext(*this, Loc, "co_await"); - if (E->getType()->isPlaceholderType()) { ExprResult R = CheckPlaceholderExpr(E); if (R.isInvalid()) return ExprError(); @@ -803,8 +771,6 @@ ExprResult Sema::ActOnCoyieldExpr(Scope *S, SourceLocation Loc, Expr *E) { return ExprError(); } - checkSuspensionContext(*this, Loc, "co_yield"); - // Build yield_value call. ExprResult Awaitable = buildPromiseCall( *this, getCurFunction()->CoroutinePromise, Loc, "yield_value", E); |

