https://github.com/jerinphilip updated https://github.com/llvm/llvm-project/pull/65638
>From 941af68ab8dad68ed8df65f6e0559476f137bfe2 Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Sat, 19 Aug 2023 16:43:53 +0530 Subject: [PATCH 01/18] Fix `Form` to recognize `_Alignas` in addition to `alignas` --- clang/include/clang/Basic/AttributeCommonInfo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h b/clang/include/clang/Basic/AttributeCommonInfo.h index e57adc4bf5b99a2..36f4eb885cf12f8 100644 --- a/clang/include/clang/Basic/AttributeCommonInfo.h +++ b/clang/include/clang/Basic/AttributeCommonInfo.h @@ -94,7 +94,7 @@ class AttributeCommonInfo { IsRegularKeywordAttribute(IsRegularKeywordAttribute) {} constexpr Form(tok::TokenKind Tok) : SyntaxUsed(AS_Keyword), SpellingIndex(SpellingNotCalculated), - IsAlignas(Tok == tok::kw_alignas), + IsAlignas(Tok == tok::kw_alignas || Tok == tok::kw__Alignas), IsRegularKeywordAttribute(tok::isRegularKeywordAttribute(Tok)) {} Syntax getSyntax() const { return Syntax(SyntaxUsed); } >From 8c0bfe350dfa2d4d24988eb544f5c1a9eb1aec6d Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Thu, 7 Sep 2023 18:53:57 +0530 Subject: [PATCH 02/18] Avoid mixing `isCXX11Attribute` with `isAlignAs` --- clang/include/clang/Basic/AttributeCommonInfo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h b/clang/include/clang/Basic/AttributeCommonInfo.h index 36f4eb885cf12f8..669227589dfacd5 100644 --- a/clang/include/clang/Basic/AttributeCommonInfo.h +++ b/clang/include/clang/Basic/AttributeCommonInfo.h @@ -186,14 +186,14 @@ class AttributeCommonInfo { bool isGNUScope() const; bool isClangScope() const; - bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11 || IsAlignas; } + bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11; } bool isC23Attribute() const { return SyntaxUsed == AS_C23; } /// The attribute is spelled [[]] in either C or C++ mode, including standard /// attributes spelled with a keyword, like alignas. bool isStandardAttributeSyntax() const { - return isCXX11Attribute() || isC23Attribute(); + return isCXX11Attribute() || isC23Attribute() || IsAlignas; } bool isGNUAttribute() const { return SyntaxUsed == AS_GNU; } >From 8f699d5dfe62b2a1eb1f67f37ffa3d4ba1f2bfce Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Thu, 7 Sep 2023 19:15:03 +0530 Subject: [PATCH 03/18] Fix diagnostic warning post `isAlignAs` decoupling --- clang/include/clang/Basic/AttributeCommonInfo.h | 2 +- clang/lib/Parse/ParseDecl.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h b/clang/include/clang/Basic/AttributeCommonInfo.h index 669227589dfacd5..f1e3325d44f0e1a 100644 --- a/clang/include/clang/Basic/AttributeCommonInfo.h +++ b/clang/include/clang/Basic/AttributeCommonInfo.h @@ -186,8 +186,8 @@ class AttributeCommonInfo { bool isGNUScope() const; bool isClangScope() const; + bool isAlignas() const { return IsAlignas; } bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11; } - bool isC23Attribute() const { return SyntaxUsed == AS_C23; } /// The attribute is spelled [[]] in either C or C++ mode, including standard diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 4a9f2caf654713e..f91141f7cd39cbf 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -3405,8 +3405,8 @@ void Parser::ParseDeclarationSpecifiers( else { // Reject C++11 / C23 attributes that aren't type attributes. for (const ParsedAttr &PA : attrs) { - if (!PA.isCXX11Attribute() && !PA.isC23Attribute() && - !PA.isRegularKeywordAttribute()) + if (!PA.isAlignas() && !PA.isCXX11Attribute() && + !PA.isC23Attribute() && !PA.isRegularKeywordAttribute()) continue; if (PA.getKind() == ParsedAttr::UnknownAttribute) // We will warn about the unknown attribute elsewhere (in >From e7ddd755f1a873421809a05a4d5d999b7a15f62e Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Sat, 19 Aug 2023 16:44:51 +0530 Subject: [PATCH 04/18] Add attribute-ignored diagnostic warning variant --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 0ac4df8edb242f6..f76f872a98288f7 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3491,10 +3491,14 @@ def err_attribute_invalid_on_decl : Error< def warn_type_attribute_deprecated_on_decl : Warning< "applying attribute %0 to a declaration is deprecated; apply it to the type instead">, InGroup<DeprecatedAttributes>; -def warn_declspec_attribute_ignored : Warning< +def warn_declspec_attribute_ignored_place_after : Warning< "attribute %0 is ignored, place it after " "\"%select{class|struct|interface|union|enum|enum class|enum struct}1\" to apply attribute to " "type declaration">, InGroup<IgnoredAttributes>; +def warn_declspec_attribute_ignored : Warning< + "attribute %0 before " + "\"%select{class|struct|interface|union|enum|enum class|enum struct}1\" " + "is ignored">, InGroup<IgnoredAttributes>; def err_declspec_keyword_has_no_effect : Error< "%0 cannot appear here, place it after " "\"%select{class|struct|interface|union|enum}1\" to apply it to the " >From ca03b9efbd0eaec1904656ce16f2d47915a26f17 Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Wed, 16 Aug 2023 16:09:52 +0530 Subject: [PATCH 05/18] Fix diagnostic emission for C Alignas --- clang/lib/Sema/SemaDecl.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d94366dac102a2a..97d74b413d3f911 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -27,6 +27,7 @@ #include "clang/AST/Randstruct.h" #include "clang/AST/StmtCXX.h" #include "clang/Basic/Builtins.h" +#include "clang/Basic/DiagnosticSema.h" #include "clang/Basic/HLSLRuntime.h" #include "clang/Basic/PartialDiagnostic.h" #include "clang/Basic/SourceManager.h" @@ -5339,16 +5340,23 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, TypeSpecType == DeclSpec::TST_interface || TypeSpecType == DeclSpec::TST_union || TypeSpecType == DeclSpec::TST_enum) { - for (const ParsedAttr &AL : DS.getAttributes()) - Diag(AL.getLoc(), AL.isRegularKeywordAttribute() - ? diag::err_declspec_keyword_has_no_effect - : diag::warn_declspec_attribute_ignored) - << AL << GetDiagnosticTypeSpecifierID(DS); - for (const ParsedAttr &AL : DeclAttrs) - Diag(AL.getLoc(), AL.isRegularKeywordAttribute() - ? diag::err_declspec_keyword_has_no_effect - : diag::warn_declspec_attribute_ignored) - << AL << GetDiagnosticTypeSpecifierID(DS); + + auto EmitAttributeDiagnostic = [this, &DS](const ParsedAttr &AL) { + if (AL.isAlignas() && !getLangOpts().CPlusPlus) { + Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored) + << AL << GetDiagnosticTypeSpecifierID(DS); + + } else { + Diag(AL.getLoc(), + AL.isRegularKeywordAttribute() + ? diag::err_declspec_keyword_has_no_effect + : diag::warn_declspec_attribute_ignored_place_after) + << AL << GetDiagnosticTypeSpecifierID(DS); + } + }; + + llvm::for_each(DS.getAttributes(), EmitAttributeDiagnostic); + llvm::for_each(DeclAttrs, EmitAttributeDiagnostic); } } >From 1c1d4c60ee6cf4349b6ff0aa41a11603022aa425 Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Thu, 7 Sep 2023 20:06:40 +0530 Subject: [PATCH 06/18] Fix test for C files --- clang/test/C/drs/dr4xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/C/drs/dr4xx.c b/clang/test/C/drs/dr4xx.c index b8ccceaad12c59f..0e25952be26f50d 100644 --- a/clang/test/C/drs/dr4xx.c +++ b/clang/test/C/drs/dr4xx.c @@ -168,7 +168,7 @@ void dr444(void) { * where the diagnostic recommends causes a different, more inscrutable error * about anonymous structures. */ - _Alignas(int) struct T { /* expected-warning {{attribute '_Alignas' is ignored, place it after "struct" to apply attribute to type declaration}} */ + _Alignas(int) struct T { /* expected-warning {{attribute '_Alignas' before "struct" is ignored}} */ int i; }; >From bc968c4c16c1b309e06df457b4c546956b06e6f6 Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Mon, 16 Oct 2023 12:41:50 +0530 Subject: [PATCH 07/18] Remove accidental header inclusion --- clang/lib/Sema/SemaDecl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 97d74b413d3f911..5ed2073eea3d6d7 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -27,7 +27,6 @@ #include "clang/AST/Randstruct.h" #include "clang/AST/StmtCXX.h" #include "clang/Basic/Builtins.h" -#include "clang/Basic/DiagnosticSema.h" #include "clang/Basic/HLSLRuntime.h" #include "clang/Basic/PartialDiagnostic.h" #include "clang/Basic/SourceManager.h" >From e45c9534cae9bc94e2d3aa1dc0abb4c1ffde42d2 Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Mon, 16 Oct 2023 22:01:19 +0530 Subject: [PATCH 08/18] Simplify DiagnosticId extraction and printing --- clang/lib/Sema/SemaDecl.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 5ed2073eea3d6d7..9f5aebe5a0fb37f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5341,17 +5341,18 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, TypeSpecType == DeclSpec::TST_enum) { auto EmitAttributeDiagnostic = [this, &DS](const ParsedAttr &AL) { + unsigned DiagnosticId; if (AL.isAlignas() && !getLangOpts().CPlusPlus) { - Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored) - << AL << GetDiagnosticTypeSpecifierID(DS); - + // Don't use the message with placement with _Alignas. + // This is because C doesnt let you use _Alignas on type declarations. + DiagnosticId = diag::warn_declspec_attribute_ignored; + } else if (AL.isRegularKeywordAttribute()) { + DiagnosticId = diag::err_declspec_keyword_has_no_effect; } else { - Diag(AL.getLoc(), - AL.isRegularKeywordAttribute() - ? diag::err_declspec_keyword_has_no_effect - : diag::warn_declspec_attribute_ignored_place_after) - << AL << GetDiagnosticTypeSpecifierID(DS); + DiagnosticId = diag::warn_declspec_attribute_ignored_place_after; } + Diag(AL.getLoc(), DiagnosticId) + << AL << GetDiagnosticTypeSpecifierID(DS); }; llvm::for_each(DS.getAttributes(), EmitAttributeDiagnostic); >From eb5523dfd4c38e14568b4a3137352a1211c7db0e Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Tue, 17 Oct 2023 00:16:52 +0530 Subject: [PATCH 09/18] Add more tests: cxx0x, c1x-alignas --- clang/test/Parser/c1x-alignas.c | 1 + clang/test/Parser/cxx0x-attributes.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/clang/test/Parser/c1x-alignas.c b/clang/test/Parser/c1x-alignas.c index 8f3d9bdb62d477a..76ad9873c37e224 100644 --- a/clang/test/Parser/c1x-alignas.c +++ b/clang/test/Parser/c1x-alignas.c @@ -9,5 +9,6 @@ char c4 _Alignas(32); // expected-error {{expected ';' after top level declarato char _Alignas(_Alignof(int)) c5; +_Alignas(int) struct c6; // expected-warning {{attribute '_Alignas' before "struct" is ignored}} // CHECK-EXT: '_Alignas' is a C11 extension // CHECK-EXT: '_Alignof' is a C11 extension diff --git a/clang/test/Parser/cxx0x-attributes.cpp b/clang/test/Parser/cxx0x-attributes.cpp index 10c5bbcac10227b..fad3010c98b9c28 100644 --- a/clang/test/Parser/cxx0x-attributes.cpp +++ b/clang/test/Parser/cxx0x-attributes.cpp @@ -451,3 +451,5 @@ namespace P2361 { // expected-warning {{use of the 'deprecated' attribute is a C++14 extension}} [[nodiscard("\123")]] int b(); // expected-error{{invalid escape sequence '\123' in an unevaluated string literal}} } + +alignas(int) struct AlignAsAttribute {}; // expected-error {{misplaced attributes; expected attributes here}} >From f8a294e095ee12762a0ac877670212ee6a6eb96c Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Tue, 17 Oct 2023 01:07:02 +0530 Subject: [PATCH 10/18] Add c2x-alignas tests --- clang/test/Parser/c2x-alignas.c | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 clang/test/Parser/c2x-alignas.c diff --git a/clang/test/Parser/c2x-alignas.c b/clang/test/Parser/c2x-alignas.c new file mode 100644 index 000000000000000..447afa28dd682be --- /dev/null +++ b/clang/test/Parser/c2x-alignas.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -std=c23 -fsyntax-only -verify %s +// RUN: not %clang_cc1 -std=c99 -pedantic -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-EXT %s + +_Alignas(int) struct c1; // expected-warning {{attribute '_Alignas' before "struct" is ignored}} +alignas(int) struct c1; // expected-warning {{attribute 'alignas' before "struct" is ignored}} >From 4345baaa02c5e2d27a727e8b2cf22d95b2842cd9 Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Tue, 17 Oct 2023 12:18:51 +0530 Subject: [PATCH 11/18] Incorporate Release Note --- clang/docs/ReleaseNotes.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index acce35e231e714d..fe0f452c5fd9573 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -145,6 +145,11 @@ Attribute Changes in Clang supports but that are never the result of default argument promotion, such as ``float``. (`#59824: <https://github.com/llvm/llvm-project/issues/59824>`_) +- Clang now warns you that the ``_Alignas`` attribute on declaration specifiers + is ignored, changed from the former incorrect suggestion to move it past + declaration specifiers. + + Improvements to Clang's diagnostics ----------------------------------- - Clang constexpr evaluator now prints template arguments when displaying >From 5041d7beeae97fbff450056f9b2b5935eb15a88b Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Sun, 22 Oct 2023 18:48:23 +0530 Subject: [PATCH 12/18] Restore old behaviour for other functions to optimize min-diff --- clang/include/clang/Basic/AttributeCommonInfo.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h b/clang/include/clang/Basic/AttributeCommonInfo.h index f1e3325d44f0e1a..102b1f272b6082c 100644 --- a/clang/include/clang/Basic/AttributeCommonInfo.h +++ b/clang/include/clang/Basic/AttributeCommonInfo.h @@ -94,7 +94,7 @@ class AttributeCommonInfo { IsRegularKeywordAttribute(IsRegularKeywordAttribute) {} constexpr Form(tok::TokenKind Tok) : SyntaxUsed(AS_Keyword), SpellingIndex(SpellingNotCalculated), - IsAlignas(Tok == tok::kw_alignas || Tok == tok::kw__Alignas), + IsAlignas(Tok == tok::kw_alignas), IsRegularKeywordAttribute(tok::isRegularKeywordAttribute(Tok)) {} Syntax getSyntax() const { return Syntax(SyntaxUsed); } @@ -186,14 +186,20 @@ class AttributeCommonInfo { bool isGNUScope() const; bool isClangScope() const; - bool isAlignas() const { return IsAlignas; } - bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11; } + bool isAlignas() const { + // In the current state of code, IsAlignas is only configured to return + // true on C++ `alignas` keyword and alternate spellings, not `_Alignas`. + // The following evaluation includes otherwise lost `_Alignas` information. + return (getParsedKind() == AT_Aligned && isKeywordAttribute()); + } + + bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11 || IsAlignas; } bool isC23Attribute() const { return SyntaxUsed == AS_C23; } /// The attribute is spelled [[]] in either C or C++ mode, including standard /// attributes spelled with a keyword, like alignas. bool isStandardAttributeSyntax() const { - return isCXX11Attribute() || isC23Attribute() || IsAlignas; + return isCXX11Attribute() || isC23Attribute(); } bool isGNUAttribute() const { return SyntaxUsed == AS_GNU; } >From bbc7637524dcbd15a0f6c36500b859080a36857e Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Sun, 22 Oct 2023 18:56:03 +0530 Subject: [PATCH 13/18] Restore old behaviour, use existing warning --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 +----- clang/lib/Sema/SemaDecl.cpp | 8 +++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index f76f872a98288f7..0ac4df8edb242f6 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3491,14 +3491,10 @@ def err_attribute_invalid_on_decl : Error< def warn_type_attribute_deprecated_on_decl : Warning< "applying attribute %0 to a declaration is deprecated; apply it to the type instead">, InGroup<DeprecatedAttributes>; -def warn_declspec_attribute_ignored_place_after : Warning< +def warn_declspec_attribute_ignored : Warning< "attribute %0 is ignored, place it after " "\"%select{class|struct|interface|union|enum|enum class|enum struct}1\" to apply attribute to " "type declaration">, InGroup<IgnoredAttributes>; -def warn_declspec_attribute_ignored : Warning< - "attribute %0 before " - "\"%select{class|struct|interface|union|enum|enum class|enum struct}1\" " - "is ignored">, InGroup<IgnoredAttributes>; def err_declspec_keyword_has_no_effect : Error< "%0 cannot appear here, place it after " "\"%select{class|struct|interface|union|enum}1\" to apply it to the " diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 9f5aebe5a0fb37f..e4e116eabef5369 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5342,14 +5342,12 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, auto EmitAttributeDiagnostic = [this, &DS](const ParsedAttr &AL) { unsigned DiagnosticId; - if (AL.isAlignas() && !getLangOpts().CPlusPlus) { - // Don't use the message with placement with _Alignas. - // This is because C doesnt let you use _Alignas on type declarations. - DiagnosticId = diag::warn_declspec_attribute_ignored; + if (AL.isAlignas() && getLangOpts().C11) { + DiagnosticId = diag::warn_attribute_ignored; } else if (AL.isRegularKeywordAttribute()) { DiagnosticId = diag::err_declspec_keyword_has_no_effect; } else { - DiagnosticId = diag::warn_declspec_attribute_ignored_place_after; + DiagnosticId = diag::warn_declspec_attribute_ignored; } Diag(AL.getLoc(), DiagnosticId) << AL << GetDiagnosticTypeSpecifierID(DS); >From 9a9c5ca592723010eea6bcb6dc86683d0714278f Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Sun, 22 Oct 2023 19:02:07 +0530 Subject: [PATCH 14/18] Update C23 alignas test with a FIXME note --- clang/test/Parser/c2x-alignas.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/clang/test/Parser/c2x-alignas.c b/clang/test/Parser/c2x-alignas.c index 447afa28dd682be..6b02b94c0a295b0 100644 --- a/clang/test/Parser/c2x-alignas.c +++ b/clang/test/Parser/c2x-alignas.c @@ -1,5 +1,11 @@ // RUN: %clang_cc1 -std=c23 -fsyntax-only -verify %s -// RUN: not %clang_cc1 -std=c99 -pedantic -fsyntax-only %s 2>&1 | FileCheck -check-prefix=CHECK-EXT %s -_Alignas(int) struct c1; // expected-warning {{attribute '_Alignas' before "struct" is ignored}} -alignas(int) struct c1; // expected-warning {{attribute 'alignas' before "struct" is ignored}} +_Alignas(int) struct c1; // expected-warning {{'_Alignas' attribute ignored}} + +// FIXME: `alignas` enters into C++ parsing code and never reaches the +// declaration specifier attribute diagnostic infrastructure. +// +// Fixing this will require the C23 notions of `alignas` being a keyword and +// `_Alignas` being an alternate spelling integrated into the parsing +// infrastructure. +alignas(int) struct c1; // expected-error {{misplaced attributes; expected attributes here}} >From 53c382a7c9cdcbfdc82ea9c8d29959b669a12ac5 Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Sun, 22 Oct 2023 19:14:02 +0530 Subject: [PATCH 15/18] Reset ParseDecl to old state --- clang/lib/Parse/ParseDecl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index f91141f7cd39cbf..4a9f2caf654713e 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -3405,8 +3405,8 @@ void Parser::ParseDeclarationSpecifiers( else { // Reject C++11 / C23 attributes that aren't type attributes. for (const ParsedAttr &PA : attrs) { - if (!PA.isAlignas() && !PA.isCXX11Attribute() && - !PA.isC23Attribute() && !PA.isRegularKeywordAttribute()) + if (!PA.isCXX11Attribute() && !PA.isC23Attribute() && + !PA.isRegularKeywordAttribute()) continue; if (PA.getKind() == ParsedAttr::UnknownAttribute) // We will warn about the unknown attribute elsewhere (in >From 31a5d599129a691fa5c614408e412233c1443353 Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Sun, 22 Oct 2023 19:18:18 +0530 Subject: [PATCH 16/18] Fix remaining warnings with `_Alignas` to the new message --- clang/test/C/drs/dr4xx.c | 2 +- clang/test/Parser/c1x-alignas.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/test/C/drs/dr4xx.c b/clang/test/C/drs/dr4xx.c index 0e25952be26f50d..0b492d03b1a1c6b 100644 --- a/clang/test/C/drs/dr4xx.c +++ b/clang/test/C/drs/dr4xx.c @@ -168,7 +168,7 @@ void dr444(void) { * where the diagnostic recommends causes a different, more inscrutable error * about anonymous structures. */ - _Alignas(int) struct T { /* expected-warning {{attribute '_Alignas' before "struct" is ignored}} */ + _Alignas(int) struct T { /* expected-warning {{'_Alignas' attribute is ignored}} */ int i; }; diff --git a/clang/test/Parser/c1x-alignas.c b/clang/test/Parser/c1x-alignas.c index 76ad9873c37e224..bf08aabc94a8d09 100644 --- a/clang/test/Parser/c1x-alignas.c +++ b/clang/test/Parser/c1x-alignas.c @@ -9,6 +9,6 @@ char c4 _Alignas(32); // expected-error {{expected ';' after top level declarato char _Alignas(_Alignof(int)) c5; -_Alignas(int) struct c6; // expected-warning {{attribute '_Alignas' before "struct" is ignored}} +_Alignas(int) struct c6; // expected-warning {{'_Alignas' attribute ignored}} // CHECK-EXT: '_Alignas' is a C11 extension // CHECK-EXT: '_Alignof' is a C11 extension >From 323a5baccb7af6a6c4d5ec3e83f1a0d4975455ae Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Sun, 22 Oct 2023 20:03:36 +0530 Subject: [PATCH 17/18] Restore !CPlusPlus --- clang/lib/Sema/SemaDecl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index e4e116eabef5369..20460eeb3926e77 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5342,7 +5342,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, auto EmitAttributeDiagnostic = [this, &DS](const ParsedAttr &AL) { unsigned DiagnosticId; - if (AL.isAlignas() && getLangOpts().C11) { + if (AL.isAlignas() && !getLangOpts().CPlusPlus) { DiagnosticId = diag::warn_attribute_ignored; } else if (AL.isRegularKeywordAttribute()) { DiagnosticId = diag::err_declspec_keyword_has_no_effect; >From 34a21ae5ef2fc363ebd4f7baefc6780a0e2d7142 Mon Sep 17 00:00:00 2001 From: Jerin Philip <jerinphi...@live.in> Date: Sun, 22 Oct 2023 20:03:49 +0530 Subject: [PATCH 18/18] Update dr4xx.c to match --- clang/test/C/drs/dr4xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/C/drs/dr4xx.c b/clang/test/C/drs/dr4xx.c index 0b492d03b1a1c6b..d4d212d680862a4 100644 --- a/clang/test/C/drs/dr4xx.c +++ b/clang/test/C/drs/dr4xx.c @@ -168,7 +168,7 @@ void dr444(void) { * where the diagnostic recommends causes a different, more inscrutable error * about anonymous structures. */ - _Alignas(int) struct T { /* expected-warning {{'_Alignas' attribute is ignored}} */ + _Alignas(int) struct T { /* expected-warning {{'_Alignas' attribute ignored}} */ int i; }; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits