[clang] [Clang] Fix assertion when __block is used on global variables in C mode (PR #194856)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 29 09:12:04 PDT 2026


================
@@ -1711,6 +1711,12 @@ 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;
----------------
AaronBallman wrote:

This is already checked via `Sema::CheckVariableDeclarationType()` and the current behavior shows that we emit the diagnostic before crashing: https://godbolt.org/z/enW1qjccM so I don't think this is necessarily the correct fix.

What's odd is, we set the declaration to be invalid when emitting the diagnostic already, so why do we even get that far into `Sema::CheckCompleteVariableDeclaration()` given that it starts with:
```
  if (var->isInvalidDecl()) return;
```


https://github.com/llvm/llvm-project/pull/194856


More information about the cfe-commits mailing list