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

>From bd731e4be65fc9c1746aa6a8f63d206eb54bb2be Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.taras...@outlook.com>
Date: Wed, 29 Jan 2025 15:17:06 +0200
Subject: [PATCH 1/3] [Clang] disallow attributes on void parameters

---
 clang/docs/ReleaseNotes.rst            | 2 ++
 clang/lib/Parse/ParseDecl.cpp          | 7 +++++++
 clang/test/Parser/cxx0x-attributes.cpp | 9 +++++++++
 3 files changed, 18 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fafe2807bd388..0c87e52007d546 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -100,6 +100,8 @@ Removed Compiler Flags
 Attribute Changes in Clang
 --------------------------
 
+- Clang now disallows the use of attributes on void parameters. (#GH108819)
+
 Improvements to Clang's diagnostics
 -----------------------------------
 
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index f136d5007e8a5f..0b88dd4449b1e2 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7986,6 +7986,13 @@ void Parser::ParseParameterDeclarationClause(
     if (getLangOpts().HLSL)
       MaybeParseHLSLAnnotations(DS.getAttributes());
 
+    if (ParmDeclarator.getIdentifier() == nullptr &&
+        ParmDeclarator.getDeclarationAttributes().size() &&
+        ParmDeclarator.getDeclSpec().getTypeSpecType() == DeclSpec::TST_void) {
+      SourceRange AttrRange = ParmDeclarator.getDeclarationAttributes().Range;
+      Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) << 
AttrRange;
+    }
+
     if (Tok.is(tok::kw_requires)) {
       // User tried to define a requires clause in a parameter declaration,
       // which is surely not a function declaration.
diff --git a/clang/test/Parser/cxx0x-attributes.cpp 
b/clang/test/Parser/cxx0x-attributes.cpp
index fad3010c98b9c2..13fcdd142fa841 100644
--- a/clang/test/Parser/cxx0x-attributes.cpp
+++ b/clang/test/Parser/cxx0x-attributes.cpp
@@ -453,3 +453,12 @@ namespace P2361 {
 }
 
 alignas(int) struct AlignAsAttribute {}; // expected-error {{misplaced 
attributes; expected attributes here}}
+
+namespace GH108819 {
+void a([[maybe_unused]] void) {}                 // expected-error {{an 
attribute list cannot appear here}} \
+                                                 // expected-warning {{use of 
the 'maybe_unused' attribute is a C++17 extension}}
+void b([[deprecated]] void) {}                   // expected-error {{an 
attribute list cannot appear here}} \
+                                                 // expected-warning {{use of 
the 'deprecated' attribute is a C++14 extension}}
+void c([[clang::lifetimebound]] void) {}         // expected-error {{an 
attribute list cannot appear here}}
+void d([[clang::annotate("a", "b", 1)]] void) {} // expected-error {{an 
attribute list cannot appear here}}
+}

>From 063f76730ebfd289f5340d0d8477a43a5ea965c2 Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.taras...@outlook.com>
Date: Wed, 29 Jan 2025 15:54:48 +0200
Subject: [PATCH 2/3] remove unnecessary name check

---
 clang/lib/Parse/ParseDecl.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 0b88dd4449b1e2..934c16c9591520 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7986,8 +7986,7 @@ void Parser::ParseParameterDeclarationClause(
     if (getLangOpts().HLSL)
       MaybeParseHLSLAnnotations(DS.getAttributes());
 
-    if (ParmDeclarator.getIdentifier() == nullptr &&
-        ParmDeclarator.getDeclarationAttributes().size() &&
+    if (ParmDeclarator.getDeclarationAttributes().size() &&
         ParmDeclarator.getDeclSpec().getTypeSpecType() == DeclSpec::TST_void) {
       SourceRange AttrRange = ParmDeclarator.getDeclarationAttributes().Range;
       Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) << 
AttrRange;

>From 3f3431513ad59111794953d27e64608b3ce2e6e1 Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.taras...@outlook.com>
Date: Wed, 29 Jan 2025 16:07:18 +0200
Subject: [PATCH 3/3] use empty instead of size

---
 clang/lib/Parse/ParseDecl.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 934c16c9591520..963b59565953d4 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7986,7 +7986,7 @@ void Parser::ParseParameterDeclarationClause(
     if (getLangOpts().HLSL)
       MaybeParseHLSLAnnotations(DS.getAttributes());
 
-    if (ParmDeclarator.getDeclarationAttributes().size() &&
+    if (!ParmDeclarator.getDeclarationAttributes().empty() &&
         ParmDeclarator.getDeclSpec().getTypeSpecType() == DeclSpec::TST_void) {
       SourceRange AttrRange = ParmDeclarator.getDeclarationAttributes().Range;
       Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) << 
AttrRange;

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

Reply via email to