https://github.com/tadeuszjt updated 
https://github.com/llvm/llvm-project/pull/219056

>From 895c97e808ec2be21fb4ad68f3f69c78944c8c6e Mon Sep 17 00:00:00 2001
From: Tadeusz Tomoszek <[email protected]>
Date: Wed, 26 Aug 2026 22:02:24 +0200
Subject: [PATCH] [clang] Fixed while condition empty init statement with
 attributes dereferencing nullptr

---
 clang/lib/Parse/ParseExprCXX.cpp   | 2 +-
 clang/test/Parser/c2x-attributes.c | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index f9a0dcc7d53af..4564e4dc364f0 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1936,7 +1936,7 @@ Sema::ConditionResult Parser::ParseCondition(StmtResult 
*InitStmt,
 
     // Handle '(; expr)', '([[...]]; expr)' and '(__attribute__((...)); expr)'
     // when GNU-style attributes are finalized.
-    if (Tok.is(tok::semi)) {
+    if (InitStmt && Tok.is(tok::semi)) {
       StmtResult Null = Actions.ActOnNullStmt(ConsumeToken());
       if (ParsedAttrs) {
         WarnOnInit();
diff --git a/clang/test/Parser/c2x-attributes.c 
b/clang/test/Parser/c2x-attributes.c
index b291cb75818c0..5ecb2ec0dab74 100644
--- a/clang/test/Parser/c2x-attributes.c
+++ b/clang/test/Parser/c2x-attributes.c
@@ -120,6 +120,12 @@ void f11(void) {
 
   [[]] for (;;);
   [[]] while (1);
+
+  while ([[]];) {} // expected-error {{an attribute list cannot appear here}} \
+                   // expected-error {{expected expression}}
+  while (;[[]];;) {} // expected-error {{expected expression}} \
+                     // expected-error {{expected expression}}
+
   [[]] do [[]] { } while(1);
 
   [[]] (void)1;

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to