[clang] [Clang] Don't treat a declaration that declares nothing as an invalid statement (PR #224682)

Akash Manna via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 28 11:46:17 PDT 2026


================
@@ -231,6 +231,11 @@ StmtResult Parser::ParseStatementOrDeclarationAfterAttributes(
                                    GNUAttrs.Range.getBegin());
       } else if (GNUAttrs.Range.getBegin().isValid())
         DeclStart = GNUAttrs.Range.getBegin();
+      // A declaration that declares nothing (`int;`) yields no Decl but still
+      // occupies the statement position; unlike a pragma, ParseStatement() must
+      // not skip it.
+      if (!Decl)
+        return Actions.ActOnNullStmt(PrevTokLocation);
----------------
akash-manna-sky wrote:

> That's a good point; we drop the AST node in this case because it's not valid to emit, but that's still leading to CodeGen crashes: https://godbolt.org/z/58rfvnfhY
> 
> Given the `RecoveryExpr`, we shouldn't be getting that far into codegen in the first place, should we?

Right. `int;` gave an invalid statement with no diagnostic, so the `RecoveryExpr` came with zero errors. With this PR Sema reports the void condition, so CodeGen isn't reached (`d2` in `Sema/GH215454.c`).


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


More information about the cfe-commits mailing list