https://github.com/TPPPP72 created https://github.com/llvm/llvm-project/pull/183988
I added an extra check in handleBlocksAttr to ensure that illegal Decl values are not passed to downstream functions. >From ab4b2fb8efd5407adcb032de0ef52b8e9022dbb6 Mon Sep 17 00:00:00 2001 From: TPPPP <[email protected]> Date: Sun, 1 Mar 2026 15:43:47 +0800 Subject: [PATCH] [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)); } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
