https://github.com/erichkeane created 
https://github.com/llvm/llvm-project/pull/137880

These two don't result in a statement, so the attempt to apply the attributes 
to them was crashing.  This patch correctly prohibits the use of attributes on 
these clauses.

Fixes: #137861

>From be6d7e3fcf4ef53bdf0dce7ff1b541f9de33c81f Mon Sep 17 00:00:00 2001
From: erichkeane <eke...@nvidia.com>
Date: Tue, 29 Apr 2025 14:32:32 -0700
Subject: [PATCH] Fix crash when an attribute is applied to pragma
 attribute/pragma dump

These two don't result in a statement, so the attempt to apply the
attributes to them was crashing.  This patch correctly prohibits the use
of attributes on these clauses.

Fixes: #137861
---
 clang/lib/Parse/ParseStmt.cpp  |  4 ++++
 clang/test/Parser/gh137861.cpp | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)
 create mode 100644 clang/test/Parser/gh137861.cpp

diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 4e801f4ef890f..97924f093240f 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -526,10 +526,14 @@ StmtResult 
Parser::ParseStatementOrDeclarationAfterAttributes(
     return ParsePragmaLoopHint(Stmts, StmtCtx, TrailingElseLoc, CXX11Attrs);
 
   case tok::annot_pragma_dump:
+    ProhibitAttributes(CXX11Attrs);
+    ProhibitAttributes(GNUAttrs);
     HandlePragmaDump();
     return StmtEmpty();
 
   case tok::annot_pragma_attribute:
+    ProhibitAttributes(CXX11Attrs);
+    ProhibitAttributes(GNUAttrs);
     HandlePragmaAttribute();
     return StmtEmpty();
   }
diff --git a/clang/test/Parser/gh137861.cpp b/clang/test/Parser/gh137861.cpp
new file mode 100644
index 0000000000000..9354aef919650
--- /dev/null
+++ b/clang/test/Parser/gh137861.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 %s -verify 
+
+void foo() {
+  // expected-error@+1{{an attribute list cannot appear here}}
+__attribute__((aligned(64)))
+#pragma clang attribute push(__attribute__((uninitialized)), apply_to = 
any(variable(is_local)))
+{
+  int f;
+}
+#pragma clang attribute pop
+}
+
+void foo2() {
+  // expected-error@+1{{an attribute list cannot appear here}}
+__attribute__((aligned(64)))
+#pragma clang __debug dump foo
+}
+
+void foo3() {
+  // expected-error@+1{{an attribute list cannot appear here}}
+  [[nodiscard]]
+#pragma clang attribute push(__attribute__((uninitialized)), apply_to = 
any(variable(is_local)))
+{
+  int f;
+}
+#pragma clang attribute pop
+}
+
+void foo4() {
+  // expected-error@+1{{an attribute list cannot appear here}}
+  [[nodiscard]]
+#pragma clang __debug dump foo
+}

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to