danix800 updated this revision to Diff 542559. danix800 edited the summary of this revision. danix800 added a comment.
Invalidate `BlockDecl` with implicit return type, in case any of the return value exprs is invalid. Propagating the error info up by replacing `BlockExpr` with a `RecoveryExpr`. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D155396/new/ https://reviews.llvm.org/D155396 Files: clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaStmt.cpp clang/test/SemaObjC/crash-on-val-dep-block-expr.m Index: clang/test/SemaObjC/crash-on-val-dep-block-expr.m =================================================================== --- /dev/null +++ clang/test/SemaObjC/crash-on-val-dep-block-expr.m @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s +// no crash + +int (^a)() = ^() { + return c; // expected-error {{use of undeclared identifier 'c'}} +}; + +int (^b)() = (^() { + return c; // expected-error {{use of undeclared identifier 'c'}} +}); Index: clang/lib/Sema/SemaStmt.cpp =================================================================== --- clang/lib/Sema/SemaStmt.cpp +++ clang/lib/Sema/SemaStmt.cpp @@ -3730,6 +3730,13 @@ if (FunctionScopes.back()->FirstReturnLoc.isInvalid()) FunctionScopes.back()->FirstReturnLoc = ReturnLoc; + BlockScopeInfo *CurBlock = dyn_cast<BlockScopeInfo>(CurCap); + if (CurBlock && CurCap->HasImplicitReturnType) { + BlockDecl *BD = CurBlock->TheDecl; + if (!BD->isInvalidDecl() && RetValExp && RetValExp->containsErrors()) + BD->setInvalidDecl(); + } + return Result; } Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -17159,6 +17159,9 @@ if (getCurFunction()) getCurFunction()->addBlock(BD); + if (BD->isInvalidDecl()) + return CreateRecoveryExpr(Result->getBeginLoc(), Result->getEndLoc(), + {Result}, Result->getType()); return Result; }
Index: clang/test/SemaObjC/crash-on-val-dep-block-expr.m =================================================================== --- /dev/null +++ clang/test/SemaObjC/crash-on-val-dep-block-expr.m @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s +// no crash + +int (^a)() = ^() { + return c; // expected-error {{use of undeclared identifier 'c'}} +}; + +int (^b)() = (^() { + return c; // expected-error {{use of undeclared identifier 'c'}} +}); Index: clang/lib/Sema/SemaStmt.cpp =================================================================== --- clang/lib/Sema/SemaStmt.cpp +++ clang/lib/Sema/SemaStmt.cpp @@ -3730,6 +3730,13 @@ if (FunctionScopes.back()->FirstReturnLoc.isInvalid()) FunctionScopes.back()->FirstReturnLoc = ReturnLoc; + BlockScopeInfo *CurBlock = dyn_cast<BlockScopeInfo>(CurCap); + if (CurBlock && CurCap->HasImplicitReturnType) { + BlockDecl *BD = CurBlock->TheDecl; + if (!BD->isInvalidDecl() && RetValExp && RetValExp->containsErrors()) + BD->setInvalidDecl(); + } + return Result; } Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -17159,6 +17159,9 @@ if (getCurFunction()) getCurFunction()->addBlock(BD); + if (BD->isInvalidDecl()) + return CreateRecoveryExpr(Result->getBeginLoc(), Result->getEndLoc(), + {Result}, Result->getType()); return Result; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits