[clang] [Clang] disallow attributes on void parameters (PR #124920)
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 Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH 01/13] [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 7fafe2807bd3883..0c87e52007d5463 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 f136d5007e8a5f0..0b88dd4449b1e28 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 fad3010c98b9c28..13fcdd142fa841f 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 Date: Wed, 29 Jan 2025 15:54:48 +0200 Subject: [PATCH 02/13] 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 0b88dd4449b1e28..934c16c95915203 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 Date: Wed, 29 Jan 2025 16:07:18 +0200 Subject: [PATCH 03/13] 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 934c16c95915203..963b59565953d45 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; >From 9919006df9ec32023b2bf179b72f9ebaf977bd08
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -53,3 +53,14 @@ alignas(4) auto PR19252 = 0; // Check the diagnostic message class alignas(void) AlignasVoid {}; // expected-error {{invalid application of 'alignas' to an incomplete type 'void'}} + +namespace GH108819 { +void a([[maybe_unused]] void) {} // expected-warning {{attribute 'maybe_unused' cannot be applied to a 'void' parameter}}\ AaronBallman wrote: Shafik's availability may be odd this week because of WG21 meetings in Hagenberg. The new test cases look good to me, so I think you're fine to land the PR and we can address any additional test coverage needs post-commit if Shafik has other cases in mind. https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
https://github.com/a-tarasyuk deleted https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -53,3 +53,14 @@ alignas(4) auto PR19252 = 0; // Check the diagnostic message class alignas(void) AlignasVoid {}; // expected-error {{invalid application of 'alignas' to an incomplete type 'void'}} + +namespace GH108819 { +void a([[maybe_unused]] void) {} // expected-warning {{attribute 'maybe_unused' cannot be applied to a 'void' parameter}}\ a-tarasyuk wrote: @shafik Thanks for the feedback. I've added more test cases. Could you take a look? https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
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 Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH 01/13] [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 7fafe2807bd3883..0c87e52007d5463 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 f136d5007e8a5f0..0b88dd4449b1e28 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 fad3010c98b9c28..13fcdd142fa841f 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 Date: Wed, 29 Jan 2025 15:54:48 +0200 Subject: [PATCH 02/13] 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 0b88dd4449b1e28..934c16c95915203 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 Date: Wed, 29 Jan 2025 16:07:18 +0200 Subject: [PATCH 03/13] 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 934c16c95915203..963b59565953d45 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; >From 9919006df9ec32023b2bf179b72f9ebaf977bd08
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -53,3 +53,14 @@ alignas(4) auto PR19252 = 0; // Check the diagnostic message class alignas(void) AlignasVoid {}; // expected-error {{invalid application of 'alignas' to an incomplete type 'void'}} + +namespace GH108819 { +void a([[maybe_unused]] void) {} // expected-warning {{attribute 'maybe_unused' cannot be applied to a 'void' parameter}}\ a-tarasyuk wrote: @shafik Thanks for the feedback. I've added more test cases. Could you take a look? https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
https://github.com/AaronBallman approved this pull request. LGTM! https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
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 Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH 01/13] [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 7fafe2807bd3883..0c87e52007d5463 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 f136d5007e8a5f0..0b88dd4449b1e28 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 fad3010c98b9c28..13fcdd142fa841f 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 Date: Wed, 29 Jan 2025 15:54:48 +0200 Subject: [PATCH 02/13] 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 0b88dd4449b1e28..934c16c95915203 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 Date: Wed, 29 Jan 2025 16:07:18 +0200 Subject: [PATCH 03/13] 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 934c16c95915203..963b59565953d45 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; >From 9919006df9ec32023b2bf179b72f9ebaf977bd08
[clang] [Clang] disallow attributes on void parameters (PR #124920)
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 Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH 01/13] [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 Date: Wed, 29 Jan 2025 15:54:48 +0200 Subject: [PATCH 02/13] 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 Date: Wed, 29 Jan 2025 16:07:18 +0200 Subject: [PATCH 03/13] 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; >From 9919006df9ec32023b2bf179b72f9ebaf977bd08 Mon Sep 1
[clang] [Clang] disallow attributes on void parameters (PR #124920)
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 Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH 01/13] [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 Date: Wed, 29 Jan 2025 15:54:48 +0200 Subject: [PATCH 02/13] 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 Date: Wed, 29 Jan 2025 16:07:18 +0200 Subject: [PATCH 03/13] 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; >From 9919006df9ec32023b2bf179b72f9ebaf977bd08 Mon Sep 1
[clang] [Clang] disallow attributes on void parameters (PR #124920)
https://github.com/shafik edited https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
https://github.com/shafik commented: This makes sense but we should have been coverage in testing. https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -53,3 +53,14 @@ alignas(4) auto PR19252 = 0; // Check the diagnostic message class alignas(void) AlignasVoid {}; // expected-error {{invalid application of 'alignas' to an incomplete type 'void'}} + +namespace GH108819 { +void a([[maybe_unused]] void) {} // expected-warning {{attribute 'maybe_unused' cannot be applied to a 'void' parameter}}\ shafik wrote: Can we add a test for a member function. also a templated function as well. Other combination if you can come up w/ them should also be tested. We need to do a better job of covering as much as possible. https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
https://github.com/shafik edited https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -10329,6 +10329,13 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, } } +if (FTIHasSingleVoidParameter(FTI)) { + ParmVarDecl *Param = cast(FTI.Params[0].Param); AaronBallman wrote: ```suggestion const auto *Param = cast(FTI.Params[0].Param); ``` https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
https://github.com/AaronBallman approved this pull request. LGTM, thank you for the fix! https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
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 Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH 01/11] [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 7fafe2807bd3883..0c87e52007d5463 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 f136d5007e8a5f0..0b88dd4449b1e28 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 fad3010c98b9c28..13fcdd142fa841f 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 Date: Wed, 29 Jan 2025 15:54:48 +0200 Subject: [PATCH 02/11] 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 0b88dd4449b1e28..934c16c95915203 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 Date: Wed, 29 Jan 2025 16:07:18 +0200 Subject: [PATCH 03/11] 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 934c16c95915203..963b59565953d45 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; >From 9919006df9ec32023b2bf179b72f9ebaf977bd08
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -3832,6 +3832,9 @@ def warn_type_attribute_wrong_type : Warning< "'%0' only applies to %select{function|pointer|" "Objective-C object or block pointer}1 types; type here is %2">, InGroup; +def warn_attribute_on_void_param: Warning< + "attribute %0 cannot be applied to a 'void' parameter">, erichkeane wrote: disregard, in the C++ grammar it is a special case in as a parameter. https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -3832,6 +3832,9 @@ def warn_type_attribute_wrong_type : Warning< "'%0' only applies to %select{function|pointer|" "Objective-C object or block pointer}1 types; type here is %2">, InGroup; +def warn_attribute_on_void_param: Warning< + "attribute %0 cannot be applied to a 'void' parameter">, erichkeane wrote: Is `'void' parameter` technically correct here? Isn't `(void)` technically an empty parameter list? Can we word this better, or are we ok with the term? https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
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 Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH 01/10] [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 7fafe2807bd3883..0c87e52007d5463 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 f136d5007e8a5f0..0b88dd4449b1e28 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 fad3010c98b9c28..13fcdd142fa841f 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 Date: Wed, 29 Jan 2025 15:54:48 +0200 Subject: [PATCH 02/10] 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 0b88dd4449b1e28..934c16c95915203 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 Date: Wed, 29 Jan 2025 16:07:18 +0200 Subject: [PATCH 03/10] 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 934c16c95915203..963b59565953d45 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; >From 9919006df9ec32023b2bf179b72f9ebaf977bd08
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -1190,6 +1190,11 @@ void Sema::ActOnPragmaAttributePop(SourceLocation PragmaLoc, void Sema::AddPragmaAttributes(Scope *S, Decl *D) { if (PragmaAttributeStack.empty()) return; + + if (ParmVarDecl *P = dyn_cast(D)) +if (P->getIdentifier() == nullptr && P->getType()->isVoidType()) erichkeane wrote: is the identifier-check necessary? Identifier on a void parameter is invalid. https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -1190,6 +1190,11 @@ void Sema::ActOnPragmaAttributePop(SourceLocation PragmaLoc, void Sema::AddPragmaAttributes(Scope *S, Decl *D) { if (PragmaAttributeStack.empty()) return; + + if (ParmVarDecl *P = dyn_cast(D)) +if (P->getIdentifier() == nullptr && P->getType()->isVoidType()) AaronBallman wrote: ```suggestion if (P->getType()->isVoidType()) ``` I don't think we need to look at the identifier; a `void` parameter has to be unnamed anyway. https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -1190,6 +1190,11 @@ void Sema::ActOnPragmaAttributePop(SourceLocation PragmaLoc, void Sema::AddPragmaAttributes(Scope *S, Decl *D) { if (PragmaAttributeStack.empty()) return; + + if (ParmVarDecl *P = dyn_cast(D)) AaronBallman wrote: ```suggestion if (const auto *P = dyn_cast(D)) ``` https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
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 Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH 1/9] [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 7fafe2807bd3883..0c87e52007d5463 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 f136d5007e8a5f0..0b88dd4449b1e28 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 fad3010c98b9c28..13fcdd142fa841f 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 Date: Wed, 29 Jan 2025 15:54:48 +0200 Subject: [PATCH 2/9] 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 0b88dd4449b1e28..934c16c95915203 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 Date: Wed, 29 Jan 2025 16:07:18 +0200 Subject: [PATCH 3/9] 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 934c16c95915203..963b59565953d45 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; >From 9919006df9ec32023b2bf179b72f9ebaf977bd08 Mon S
[clang] [Clang] disallow attributes on void parameters (PR #124920)
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 Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH 1/9] [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 Date: Wed, 29 Jan 2025 15:54:48 +0200 Subject: [PATCH 2/9] 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 Date: Wed, 29 Jan 2025 16:07:18 +0200 Subject: [PATCH 3/9] 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; >From 9919006df9ec32023b2bf179b72f9ebaf977bd08 Mon Sep 17 00:0
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -50,8 +50,8 @@ struct testRecoverStrictnessStruct { }; #pragma clang attribute pop -#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), variable, enum)) -// expected-error@-1 {{attribute 'abi_tag' cannot be applied to 'enum'}} +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), variable, enum)) // expected-warning {{attribute 'abi_tag' cannot be applied to a 'void' parameter}} + // expected-error@-1 {{attribute 'abi_tag' cannot be applied to 'enum'}} AaronBallman wrote: > @AaronBallman if we're considering changes to `Attr.td`, I don't think we need changes in Attr.td itself; the changes should be limited to just the tablegen bits (or the part consuming the tablegen bits). > it seems that `[Var]` and `[ParmVar]` should be extended to `AttrSubject`, > since `AttrSubjectMatcherRule` only accepts a list of `AttrSubject`. I'm > unsure if this qualifies as a `Subject`, though... Those already are an `AttrSubject`; we have attributes using them already. > https://github.com/llvm/llvm-project/blob/50082773223b9eced296d8223ca4e4a79ecdeb9b/clang/include/clang/Basic/Attr.td#L560-L567 I think that's correct as-is. > or explicitly add a helper to exclude void parameters and use it with > > https://github.com/llvm/llvm-project/blob/d00579be39e8a470d7a0ff79ff6deadf9e003781/clang/lib/Sema/ParsedAttr.cpp#L172-L175 I think that's what needs to be changed to exclude `void` parameters (or somewhere nearby that call). > > Side note: pragma clang attribute push diagnostics are THE WORST here... > > I suppose the diagnostic for void parameters will be skipped if the rules > exclude them, or should the diagnostic still handle this case? The goal is to get rid of the diagnostics about `void` parameters. e.g., `// expected-warning {{attribute 'abi_tag' cannot be applied to a 'void' parameter}}` shouldn't be fired. https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -50,8 +50,8 @@ struct testRecoverStrictnessStruct { }; #pragma clang attribute pop -#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), variable, enum)) -// expected-error@-1 {{attribute 'abi_tag' cannot be applied to 'enum'}} +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), variable, enum)) // expected-warning {{attribute 'abi_tag' cannot be applied to a 'void' parameter}} + // expected-error@-1 {{attribute 'abi_tag' cannot be applied to 'enum'}} a-tarasyuk wrote: @AaronBallman if we're considering changes to `Attr.td`, it seems that `[Var]` and `[ParmVar]` should be extended to `AttrSubject`, since `AttrSubjectMatcherRule` only accepts a list of `AttrSubject`. I'm unsure if this qualifies as a `Subject`, though... https://github.com/llvm/llvm-project/blob/50082773223b9eced296d8223ca4e4a79ecdeb9b/clang/include/clang/Basic/Attr.td#L560-L567 or explicitly add a helper to exclude void parameters and use it with https://github.com/llvm/llvm-project/blob/d00579be39e8a470d7a0ff79ff6deadf9e003781/clang/lib/Sema/ParsedAttr.cpp#L172-L175 > Side note: pragma clang attribute push diagnostics are THE WORST here... I suppose the diagnostic for void parameters will be skipped if the rules exclude them, or should the diagnostic still handle this case? https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -50,8 +50,8 @@ struct testRecoverStrictnessStruct { }; #pragma clang attribute pop -#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), variable, enum)) -// expected-error@-1 {{attribute 'abi_tag' cannot be applied to 'enum'}} +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), variable, enum)) // expected-warning {{attribute 'abi_tag' cannot be applied to a 'void' parameter}} + // expected-error@-1 {{attribute 'abi_tag' cannot be applied to 'enum'}} AaronBallman wrote: I think we can fix the behavior here by updating somewhere around https://github.com/llvm/llvm-project/blob/eb0af4e48d0e039849c6bbf36e791610e7ef9a06/clang/utils/TableGen/ClangAttrEmitter.cpp#L4473 That's what gets used by `ParsedAttr::appliesToDecl()` which is called by `Sema::AddPragmaAttributes()`. https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -50,8 +50,8 @@ struct testRecoverStrictnessStruct { }; #pragma clang attribute pop -#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), variable, enum)) -// expected-error@-1 {{attribute 'abi_tag' cannot be applied to 'enum'}} +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), variable, enum)) // expected-warning {{attribute 'abi_tag' cannot be applied to a 'void' parameter}} + // expected-error@-1 {{attribute 'abi_tag' cannot be applied to 'enum'}} erichkeane wrote: Ah, yeah. I think we need to fix this ASAP. the `push` pragma needs to not consider `void` to be a `parameter` (even if it is a `ParmVarDecl` at one point). Whether it needs to be fixed in THIS patch, or a followup (since we jsut did the branch, we at least have some time), I'll leave up to the author. Side note: `pragma clang attribute push` diagnostics are THE WORST here. The fact that the error/warning is on the attribute location, but doesn't point out which declaration is causing it is awful. We should probably find some way to intuit that we should probably have a 'note' here that ALSO points out which declaration it applies to. https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
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 Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH 1/8] [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 Date: Wed, 29 Jan 2025 15:54:48 +0200 Subject: [PATCH 2/8] 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 Date: Wed, 29 Jan 2025 16:07:18 +0200 Subject: [PATCH 3/8] 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; >From 9919006df9ec32023b2bf179b72f9ebaf977bd08 Mon Sep 17 00:0
[clang] [Clang] disallow attributes on void parameters (PR #124920)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff b3458fdec5e183b49c634b72b828630bb6972400 afe40bf1b7095c3758f98327205ea39a1740f48d --extensions cpp,c -- clang/lib/Sema/SemaDecl.cpp clang/test/Misc/pragma-attribute-strict-subjects.c clang/test/SemaCXX/attr-cxx0x.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 9d269f2e4d..63f176f44e 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -10331,8 +10331,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, for (const auto *A : Param->attrs()) Diag(A->getLoc(), diag::warn_attribute_on_void_param) << A << A->getRange(); - } } + } if (!getLangOpts().CPlusPlus) { // In C, find all the tag declarations from the prototype and move them `` https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
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 Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH 1/7] [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 Date: Wed, 29 Jan 2025 15:54:48 +0200 Subject: [PATCH 2/7] 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 Date: Wed, 29 Jan 2025 16:07:18 +0200 Subject: [PATCH 3/7] 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; >From 9919006df9ec32023b2bf179b72f9ebaf977bd08 Mon Sep 17 00:0
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -90,7 +90,7 @@ struct testSubset1Struct { }; #pragma clang attribute pop -#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = variable) +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = variable) // expected-warning {{attribute 'abi_tag' cannot be applied to a 'void' parameter}} AaronBallman wrote: ```suggestion #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = variable) // expected-warning@-1 {{attribute 'abi_tag' cannot be applied to a 'void' parameter}} ``` Same changes elsewhere; just keeps the line length more reasonable when reading the tests. https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -3830,6 +3830,8 @@ def warn_type_attribute_wrong_type : Warning< "'%0' only applies to %select{function|pointer|" "Objective-C object or block pointer}1 types; type here is %2">, InGroup; +def warn_attribute_on_void_param: Warning< + "attribute %0 cannot be applied to a 'void' parameter">, InGroup; AaronBallman wrote: ```suggestion "attribute %0 cannot be applied to a 'void' parameter">, InGroup; ``` https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -10326,6 +10326,15 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, } } +if (FTIHasSingleVoidParameter(FTI)) { + ParmVarDecl *Param = cast(FTI.Params[0].Param); + if (Param->hasAttrs()) { +for (const auto *A : Param->attrs()) + Diag(A->getLoc(), diag::warn_attribute_on_void_param) + << A << A->getRange(); + } AaronBallman wrote: ```suggestion for (const auto *A : Param->attrs()) Diag(A->getLoc(), diag::warn_attribute_on_void_param) << A << A->getRange(); ``` I forgot that `attrs()` handles the no-attributes case gracefully (it's `getAttrs()` that doesn't), so we don't need the extra check. https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -50,8 +50,8 @@ struct testRecoverStrictnessStruct { }; #pragma clang attribute pop -#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), variable, enum)) -// expected-error@-1 {{attribute 'abi_tag' cannot be applied to 'enum'}} +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), variable, enum)) // expected-warning {{attribute 'abi_tag' cannot be applied to a 'void' parameter}} + // expected-error@-1 {{attribute 'abi_tag' cannot be applied to 'enum'}} AaronBallman wrote: ```suggestion #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), variable, enum)) // expected-warning@-1 {{attribute 'abi_tag' cannot be applied to a 'void' parameter}} // expected-error@-2 {{attribute 'abi_tag' cannot be applied to 'enum'}} ``` I *think* this is actually a bug with the way `clang attribute push` works. A `void` parameter is not a variable because it doesn't really declare a parameter (there's no object backing the parameter like there is for other cases). WDYT @erichkeane? https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -107,6 +107,8 @@ Removed Compiler Flags Attribute Changes in Clang -- +- Clang now disallows the use of attributes on void parameters. (#GH108819) AaronBallman wrote: ```suggestion - Clang now diagnoses use of declaration attributes on void parameters. (#GH108819) ``` https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
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 Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH 1/4] [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 Date: Wed, 29 Jan 2025 15:54:48 +0200 Subject: [PATCH 2/4] 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 Date: Wed, 29 Jan 2025 16:07:18 +0200 Subject: [PATCH 3/4] 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; >From 9919006df9ec32023b2bf179b72f9ebaf977bd08 Mon Sep 17 00:0
[clang] [Clang] disallow attributes on void parameters (PR #124920)
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 Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH 1/4] [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 Date: Wed, 29 Jan 2025 15:54:48 +0200 Subject: [PATCH 2/4] 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 Date: Wed, 29 Jan 2025 16:07:18 +0200 Subject: [PATCH 3/4] 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; >From 9919006df9ec32023b2bf179b72f9ebaf977bd08 Mon Sep 17 00:0
[clang] [Clang] disallow attributes on void parameters (PR #124920)
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 Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH 1/4] [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 7fafe2807bd3883..0c87e52007d5463 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 f136d5007e8a5f0..0b88dd4449b1e28 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 fad3010c98b9c28..13fcdd142fa841f 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 Date: Wed, 29 Jan 2025 15:54:48 +0200 Subject: [PATCH 2/4] 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 0b88dd4449b1e28..934c16c95915203 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 Date: Wed, 29 Jan 2025 16:07:18 +0200 Subject: [PATCH 3/4] 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 934c16c95915203..963b59565953d45 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; >From 9919006df9ec32023b2bf179b72f9ebaf977bd08 Mon S
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -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}} \ a-tarasyuk wrote: Thanks for the feedback, I'll check `SemaDeclAttr`. should a different message be used here instead? https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -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}} \ AaronBallman wrote: I think this is a confusing diagnostic -- an attribute list *can* appear here. The problem is that an attribute which appertains to a declaration cannot appertain to a void parameter. I think that should be handled in SemaDeclAttr.cpp when doing the usual appertainment checks. https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
https://github.com/AaronBallman requested changes to this pull request. https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
https://github.com/AaronBallman commented: This is a semantic restriction, not a parsing restriction, right? https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -7986,6 +7986,12 @@ void Parser::ParseParameterDeclarationClause( if (getLangOpts().HLSL) MaybeParseHLSLAnnotations(DS.getAttributes()); +if (ParmDeclarator.getDeclarationAttributes().size() && a-tarasyuk wrote: @erichkeane thanks. changed to use `empty` https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
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 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 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 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 ma
[clang] [Clang] disallow attributes on void parameters (PR #124920)
https://github.com/cor3ntin approved this pull request. https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -7986,6 +7986,12 @@ void Parser::ParseParameterDeclarationClause( if (getLangOpts().HLSL) MaybeParseHLSLAnnotations(DS.getAttributes()); +if (ParmDeclarator.getDeclarationAttributes().size() && erichkeane wrote: ```suggestion if (!ParmDeclarator.getDeclarationAttributes().empty() && ``` https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
https://github.com/erichkeane edited https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
https://github.com/erichkeane approved this pull request. 1 nit, else LGTM. https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -7986,6 +7986,13 @@ void Parser::ParseParameterDeclarationClause( if (getLangOpts().HLSL) MaybeParseHLSLAnnotations(DS.getAttributes()); +if (ParmDeclarator.getIdentifier() == nullptr && a-tarasyuk wrote: @cor3ntin thanks for the feedback. I've removed it. https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
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 Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH 1/2] [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 Date: Wed, 29 Jan 2025 15:54:48 +0200 Subject: [PATCH 2/2] 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; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
@@ -7986,6 +7986,13 @@ void Parser::ParseParameterDeclarationClause( if (getLangOpts().HLSL) MaybeParseHLSLAnnotations(DS.getAttributes()); +if (ParmDeclarator.getIdentifier() == nullptr && cor3ntin wrote: I don't think checking checking for an identifier makes sense, the type is enough https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Oleksandr T. (a-tarasyuk) Changes Fixes #108819 --- This PR introduces diagnostics to disallow the use of attributes on void parameters ```cpp void f([[deprecated]] void) {} ``` --- Full diff: https://github.com/llvm/llvm-project/pull/124920.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+2) - (modified) clang/lib/Parse/ParseDecl.cpp (+7) - (modified) clang/test/Parser/cxx0x-attributes.cpp (+9) ``diff 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}} +} `` https://github.com/llvm/llvm-project/pull/124920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/124920 Fixes #108819 --- This PR introduces diagnostics to disallow the use of attributes on void parameters ```cpp void f([[deprecated]] void) {} ``` >From bd731e4be65fc9c1746aa6a8f63d206eb54bb2be Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH] [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}} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits