From 3cb16f6d2ddd030c35df7ad3eb7985f1947173cb Mon Sep 17 00:00:00 2001 From: dingfei Date: Mon, 24 Jul 2023 18:31:01 +0800 Subject: [PATCH] [Sema][ObjC] Invalidate BlockDecl with invalid ParmVarDecl BlockDecl should be invalidated because of its invalid ParmVarDecl. Fixes #1 of https://github.com/llvm/llvm-project/issues/64005 Differential Revision: https://reviews.llvm.org/D155984 --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaExpr.cpp | 3 +++ clang/test/AST/ast-dump-recovery.m | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e686e83583919f..5d09c454dea290 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -674,6 +674,8 @@ Bug Fixes in This Version value exprs is invalid. Propagating the error info up by replacing BlockExpr with a RecoveryExpr. This fixes: (`#63863 _`) +- Invalidate BlockDecl with invalid ParmVarDecl + (`#64005 _`) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 3c9d0efca8a1ee..716383412cc58c 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -16959,6 +16959,9 @@ void Sema::ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, PushOnScopeChains(AI, CurBlock->TheScope); } + + if (AI->isInvalidDecl()) + CurBlock->TheDecl->setInvalidDecl(); } } diff --git a/clang/test/AST/ast-dump-recovery.m b/clang/test/AST/ast-dump-recovery.m index c2bd078959aba1..37fa8045c0b941 100644 --- a/clang/test/AST/ast-dump-recovery.m +++ b/clang/test/AST/ast-dump-recovery.m @@ -24,3 +24,9 @@ void k(Foo *foo) { int (^gh63863)() = ^() { return undef; }; + +// CHECK: `-BlockExpr {{.*}} 'int (^)(int, int)' +// CHECK-NEXT: `-BlockDecl {{.*}} invalid +int (^gh64005)(int, int) = ^(int, undefined b) { + return 1; +};