https://github.com/TPPPP72 updated https://github.com/llvm/llvm-project/pull/183988
>From ab4b2fb8efd5407adcb032de0ef52b8e9022dbb6 Mon Sep 17 00:00:00 2001 From: TPPPP <[email protected]> Date: Sun, 1 Mar 2026 15:43:47 +0800 Subject: [PATCH 1/5] [Clang] Fix crash when __block is used on global variables in C mode --- clang/lib/Sema/SemaObjC.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/clang/lib/Sema/SemaObjC.cpp b/clang/lib/Sema/SemaObjC.cpp index dae30b7e941d1..d6969646ad5a2 100644 --- a/clang/lib/Sema/SemaObjC.cpp +++ b/clang/lib/Sema/SemaObjC.cpp @@ -1711,6 +1711,14 @@ void SemaObjC::handleBlocksAttr(Decl *D, const ParsedAttr &AL) { return; } + VarDecl *VD = dyn_cast<VarDecl>(D); + if (!VD || !VD->hasLocalStorage()) { + Diag(AL.getLoc(), diag::err_block_on_nonlocal) + << AL; + D->setInvalidDecl(); + return; + } + D->addAttr(::new (getASTContext()) BlocksAttr(getASTContext(), AL, type)); } >From c3e37351a4806a2b0777f4674c9bc3ea849c27f1 Mon Sep 17 00:00:00 2001 From: TPPPP <[email protected]> Date: Sun, 1 Mar 2026 15:50:21 +0800 Subject: [PATCH 2/5] clang formatted --- clang/lib/Sema/SemaObjC.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaObjC.cpp b/clang/lib/Sema/SemaObjC.cpp index d6969646ad5a2..582e3db98b682 100644 --- a/clang/lib/Sema/SemaObjC.cpp +++ b/clang/lib/Sema/SemaObjC.cpp @@ -1713,8 +1713,7 @@ void SemaObjC::handleBlocksAttr(Decl *D, const ParsedAttr &AL) { VarDecl *VD = dyn_cast<VarDecl>(D); if (!VD || !VD->hasLocalStorage()) { - Diag(AL.getLoc(), diag::err_block_on_nonlocal) - << AL; + Diag(AL.getLoc(), diag::err_block_on_nonlocal) << AL; D->setInvalidDecl(); return; } >From 1b79dfccf0ee6d3eaab7a00f8164ce332cc3280c Mon Sep 17 00:00:00 2001 From: TPPPP <[email protected]> Date: Sun, 1 Mar 2026 17:28:21 +0800 Subject: [PATCH 3/5] update test --- clang/docs/ReleaseNotes.rst | 1 + clang/test/Sema/gh183974.c | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 clang/test/Sema/gh183974.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index cb1010aee1edd..ca78fa296e456 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -317,6 +317,7 @@ Bug Fixes to C++ Support Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ - Fixed a bug where explicit nullability property attributes were not stored in AST nodes in Objective-C. (#GH179703) +- Fixed a crash when __block is used on global variables in C mode. (#GH183974) Miscellaneous Bug Fixes ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/test/Sema/gh183974.c b/clang/test/Sema/gh183974.c new file mode 100644 index 0000000000000..0999dc18a1e03 --- /dev/null +++ b/clang/test/Sema/gh183974.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s + +__block int x; // expected-error {{__block attribute not allowed, only allowed on local variables}} + +int x[0]; \ No newline at end of file >From 7eabc3330ed10e88cfbad5226866eb36f5b85077 Mon Sep 17 00:00:00 2001 From: TPPPP <[email protected]> Date: Mon, 2 Mar 2026 12:57:11 +0800 Subject: [PATCH 4/5] Change the description from "crash" to "assertion" --- clang/docs/ReleaseNotes.rst | 2 +- clang/test/Sema/gh183974.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ca78fa296e456..581bf61977d54 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -317,7 +317,7 @@ Bug Fixes to C++ Support Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ - Fixed a bug where explicit nullability property attributes were not stored in AST nodes in Objective-C. (#GH179703) -- Fixed a crash when __block is used on global variables in C mode. (#GH183974) +- Fixed a assertion when __block is used on global variables in C mode. (#GH183974) Miscellaneous Bug Fixes ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/test/Sema/gh183974.c b/clang/test/Sema/gh183974.c index 0999dc18a1e03..642a622761f69 100644 --- a/clang/test/Sema/gh183974.c +++ b/clang/test/Sema/gh183974.c @@ -2,4 +2,4 @@ __block int x; // expected-error {{__block attribute not allowed, only allowed on local variables}} -int x[0]; \ No newline at end of file +int x; >From 5cfcb6ffe25daecf0734921e6405ab1811162adb Mon Sep 17 00:00:00 2001 From: TPPPP <[email protected]> Date: Mon, 2 Mar 2026 14:13:29 +0800 Subject: [PATCH 5/5] remove marking invalid --- clang/lib/Sema/SemaObjC.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/lib/Sema/SemaObjC.cpp b/clang/lib/Sema/SemaObjC.cpp index 582e3db98b682..dcd1b35e8fbc7 100644 --- a/clang/lib/Sema/SemaObjC.cpp +++ b/clang/lib/Sema/SemaObjC.cpp @@ -1714,7 +1714,6 @@ void SemaObjC::handleBlocksAttr(Decl *D, const ParsedAttr &AL) { VarDecl *VD = dyn_cast<VarDecl>(D); if (!VD || !VD->hasLocalStorage()) { Diag(AL.getLoc(), diag::err_block_on_nonlocal) << AL; - D->setInvalidDecl(); return; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
