[PATCH] D155396: [Sema][ObjC] Propagating value-dependent errors into BlockExpr
Ding Fei via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 20 09:17:58 PDT 2023
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155396.542559.patch
Type: text/x-patch
Size: 1483 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230720/4a5febc1/attachment.bin>
More information about the cfe-commits
mailing list