https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/182362

>From 4faec39a5b899bdfc743011ccad7b134e99496ca Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk <[email protected]>
Date: Thu, 19 Feb 2026 22:03:09 +0200
Subject: [PATCH 1/2] [Clang] fix crash parsing forbidden attribute args in
 pragma attributes

---
 clang/docs/ReleaseNotes.rst                 | 1 +
 clang/lib/Parse/ParsePragma.cpp             | 3 ++-
 clang/test/FixIt/fixit-pragma-attribute.cpp | 4 ++++
 clang/test/Parser/pragma-attribute.cpp      | 5 +++++
 4 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6e9e5baea2921..533cde545b25b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -273,6 +273,7 @@ Bug Fixes in This Version
 - Fixed an assertion failure when evaluating ``_Countof`` on invalid 
``void``-typed operands. (#GH180893)
 - Fixed a ``-Winvalid-noreturn`` false positive for unreachable ``try`` blocks 
following an unconditional ``throw``. (#GH174822)
 - Fixed an assertion failure caused by error recovery while extending a nested 
name specifier with results from ordinary lookup. (#GH181470)
+- Fixed a crash when parsing ``#pragma clang attribute`` arguments for 
attributes that forbid arguments. (#GH182122)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index def2817c930b2..734d095d74cdf 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -1982,7 +1982,8 @@ void Parser::HandlePragmaAttribute() {
   if ((Tok.is(tok::l_square) && NextToken().is(tok::l_square)) ||
       Tok.isRegularKeywordAttribute()) {
     // Parse the CXX11 style attribute.
-    ParseCXX11AttributeSpecifier(Attrs);
+    SourceLocation EndLoc = Tok.getLocation();
+    ParseCXX11AttributeSpecifier(Attrs, &EndLoc);
   } else if (Tok.is(tok::kw___attribute)) {
     ConsumeToken();
     if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
diff --git a/clang/test/FixIt/fixit-pragma-attribute.cpp 
b/clang/test/FixIt/fixit-pragma-attribute.cpp
index ad233ef067915..ecfd6e60b253e 100644
--- a/clang/test/FixIt/fixit-pragma-attribute.cpp
+++ b/clang/test/FixIt/fixit-pragma-attribute.cpp
@@ -84,3 +84,7 @@
 
 #pragma clang attribute push (__attribute__((objc_externally_retained)), 
apply_to)
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:82-[[@LINE-1]]:82}:" = any(function, 
variable(unless(is_parameter)))"
+
+int x;
+#pragma clang attribute push ([[noreturn (x))
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:42-[[@LINE-1]]:45}:""
diff --git a/clang/test/Parser/pragma-attribute.cpp 
b/clang/test/Parser/pragma-attribute.cpp
index eaf1a775c1c88..0ef630f1cc06f 100644
--- a/clang/test/Parser/pragma-attribute.cpp
+++ b/clang/test/Parser/pragma-attribute.cpp
@@ -217,3 +217,8 @@ _Pragma("clang attribute pop");
 #pragma clang attribute push (__attribute__((disable_tail_calls,)), apply_to = 
function) // expected-error {{expected identifier that represents an attribute 
name}}
 
 #pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // 
expected-error {{expected ','}}
+
+int x;
+#pragma clang attribute push ([[noreturn (x)) // expected-error {{attribute 
'noreturn' cannot have an argument list}} \
+                                              // expected-error {{expected 
']'}} \
+                                              // expected-error {{expected 
']'}}

>From 3771fca54db32be4997acba0479fbacea5b7f87d Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk <[email protected]>
Date: Sun, 22 Feb 2026 23:13:05 +0200
Subject: [PATCH 2/2] add additional test cases

---
 clang/test/FixIt/fixit-pragma-attribute.cpp | 3 +++
 clang/test/Parser/pragma-attribute.cpp      | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/clang/test/FixIt/fixit-pragma-attribute.cpp 
b/clang/test/FixIt/fixit-pragma-attribute.cpp
index ecfd6e60b253e..3824e45d8fca5 100644
--- a/clang/test/FixIt/fixit-pragma-attribute.cpp
+++ b/clang/test/FixIt/fixit-pragma-attribute.cpp
@@ -88,3 +88,6 @@
 int x;
 #pragma clang attribute push ([[noreturn (x))
 // CHECK: fix-it:{{.*}}:{[[@LINE-1]]:42-[[@LINE-1]]:45}:""
+
+#pragma clang attribute push([[noreturn (x)]], apply_to = function)
+// CHECK: fix-it:{{.*}}:{[[@LINE-1]]:41-[[@LINE-1]]:44}:""
diff --git a/clang/test/Parser/pragma-attribute.cpp 
b/clang/test/Parser/pragma-attribute.cpp
index 0ef630f1cc06f..da1b3f3170428 100644
--- a/clang/test/Parser/pragma-attribute.cpp
+++ b/clang/test/Parser/pragma-attribute.cpp
@@ -219,6 +219,8 @@ _Pragma("clang attribute pop");
 #pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // 
expected-error {{expected ','}}
 
 int x;
+#pragma clang attribute push([[noreturn (x)]], apply_to = function) // 
expected-error {{attribute 'noreturn' cannot have an argument list}}
+
 #pragma clang attribute push ([[noreturn (x)) // expected-error {{attribute 
'noreturn' cannot have an argument list}} \
                                               // expected-error {{expected 
']'}} \
                                               // expected-error {{expected 
']'}}

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

Reply via email to