[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-26 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb893368fd4fd: Fix the diagnostic about attribute placement 
for scoped enumerations (authored by ipriyanshi1708, committed by 
aaron.ballman).

Changed prior to commit:
  https://reviews.llvm.org/D147989?vs=517207=517266#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/attr-declspec-ignored.cpp

Index: clang/test/SemaCXX/attr-declspec-ignored.cpp
===
--- clang/test/SemaCXX/attr-declspec-ignored.cpp
+++ clang/test/SemaCXX/attr-declspec-ignored.cpp
@@ -9,6 +9,10 @@
   // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
   __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
   // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+  // expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum struct ES {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum struct" to apply attribute to type declaration}} \
+  // expected-warning{{attribute 'aligned' is ignored, place it after "enum struct" to apply attribute to type declaration}}
 
   // Test that we get the same warnings for type declarations nested in a record.
   struct X {
@@ -20,7 +24,11 @@
 // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
 __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
-
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum struct ES {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum struct" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum struct" to apply attribute to type declaration}}
+  
 // Also test [[]] attribute syntax. (On a non-nested declaration, these
 // generate a hard "misplaced attributes" error, which we test for
 // elsewhere.)
@@ -32,6 +40,10 @@
 // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] enum H {H}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+[[gnu::visibility("hidden")]]  [[gnu::aligned]] enum class I {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
+[[gnu::visibility("hidden")]]  [[gnu::aligned]] enum struct J {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum struct" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum struct" to apply attribute to type declaration}}
   };
 }
 
@@ -40,16 +52,22 @@
   __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B {} b;
   __attribute__((visibility("hidden")))  __attribute__((aligned)) union C {} c;
   __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D} d;
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {} ec;
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum struct ES {} es;
 
   struct X {
 

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-26 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 added a comment.

In D147989#4299722 , @aaron.ballman 
wrote:

> LGTM! Do you need someone to land this on your behalf? If so, what name and 
> email address would you like used for patch attribution?

Yes, I need someone who can commit it for me. 
Username: ipriyanshi1708
Email address: priyanshiagarwal1...@gmail.com
Please commit it for me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM! Do you need someone to land this on your behalf? If so, what name and 
email address would you like used for patch attribution?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-26 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 added a comment.

In D147989#4295928 , @aaron.ballman 
wrote:

> The issue is that `GetDiagnosticTypeSpecifierID()` is called for more 
> diagnostics than just `warn_declspec_attribute_ignored`. You need to also 
> update the `err_constexpr_tag` and 
> `err_standalone_class_nested_name_specifier` to add `enum class` and `enum 
> struct` as well.

Okay! Thanks. I have updated the code now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-26 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 updated this revision to Diff 517207.
ipriyanshi1708 added a comment.

Fixed the code


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/attr-declspec-ignored.cpp

Index: clang/test/SemaCXX/attr-declspec-ignored.cpp
===
--- clang/test/SemaCXX/attr-declspec-ignored.cpp
+++ clang/test/SemaCXX/attr-declspec-ignored.cpp
@@ -9,6 +9,10 @@
   // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
   __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
   // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+  // expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum struct ES {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum struct" to apply attribute to type declaration}} \
+  // expected-warning{{attribute 'aligned' is ignored, place it after "enum struct" to apply attribute to type declaration}}
 
   // Test that we get the same warnings for type declarations nested in a record.
   struct X {
@@ -20,7 +24,11 @@
 // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
 __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
-
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum struct ES {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum struct" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum struct" to apply attribute to type declaration}}
+  
 // Also test [[]] attribute syntax. (On a non-nested declaration, these
 // generate a hard "misplaced attributes" error, which we test for
 // elsewhere.)
@@ -32,6 +40,10 @@
 // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] enum H {H}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+[[gnu::visibility("hidden")]]  [[gnu::aligned]] enum class I {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
+[[gnu::visibility("hidden")]]  [[gnu::aligned]] enum struct J {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum struct" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum struct" to apply attribute to type declaration}}
   };
 }
 
@@ -40,16 +52,22 @@
   __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B {} b;
   __attribute__((visibility("hidden")))  __attribute__((aligned)) union C {} c;
   __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D} d;
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {} ec;
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum struct ES {} es;
 
   struct X {
 __attribute__((visibility("hidden")))  __attribute__((aligned)) class A {} a;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B {} b;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) union C {} 

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

The issue is that `GetDiagnosticTypeSpecifierID()` is called for more 
diagnostics than just `warn_declspec_attribute_ignored`. You need to also 
update the `err_constexpr_tag` and `err_standalone_class_nested_name_specifier` 
to add `enum class` and `enum struct` as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-25 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 marked an inline comment as done.
ipriyanshi1708 added a comment.

In D147989#4293278 , @aaron.ballman 
wrote:

> Oops, I spoke too soon -- it looks like the precommit CI failure is related 
> to this patch. This is what I get when I tested locally:
>
>   Assertion failed: NextVal != ArgumentEnd && "Value for integer select 
> modifier was" " larger than the number of options in the diagnostic string!", 
> file F:\source\llvm-project\clang\lib\Basic\Diagnostic.cpp, line 623
>   PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
> and include the crash backtrace, preprocessed source, and associated run 
> script.
>   Stack dump:
>   0.  Program arguments: 
> f:\\source\\llvm-project\\llvm\\out\\build\\x64-debug\\bin\\clang.exe -cc1 
> -internal-isystem 
> f:\\source\\llvm-project\\llvm\\out\\build\\x64-debug\\lib\\clang\\17\\include
>  -nostdsysteminc -std=c++11 -triple x86_64-unknown-unknown 
> F:\\source\\llvm-project\\clang\\test\\CXX\\drs\\dr16xx.cpp -verify 
> -fexceptions -fcxx-exceptions -pedantic-errors
>   1.  F:\source\llvm-project\clang\test\CXX\drs\dr16xx.cpp:91:3: current 
> parser token 'template'
>   2.  F:\source\llvm-project\clang\test\CXX\drs\dr16xx.cpp:71:1: parsing 
> namespace 'dr1638'
>   Exception Code: 0x8003
>#0 0x7ff6625ea26c HandleAbort 
> F:\source\llvm-project\llvm\lib\Support\Windows\Signals.inc:419:0
>#1 0x7ffa9b23bc31 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x6bc31)
>#2 0x7ffa9b23d889 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x6d889)
>#3 0x7ffa9b2430bf (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x730bf)
>#4 0x7ffa9b241091 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x71091)
>#5 0x7ffa9b243a1f (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x73a1f)
>#6 0x7ff662a19b8c HandleSelectModifier 
> F:\source\llvm-project\clang\lib\Basic\Diagnostic.cpp:622:0
>#7 0x7ff662a17137 clang::Diagnostic::FormatDiagnostic(char const *, 
> char const *, class llvm::SmallVectorImpl &) const 
> F:\source\llvm-project\clang\lib\Basic\Diagnostic.cpp:1005:0
>#8 0x7ff662a16518 clang::Diagnostic::FormatDiagnostic(class 
> llvm::SmallVectorImpl &) const 
> F:\source\llvm-project\clang\lib\Basic\Diagnostic.cpp:805:0
>#9 0x7ff663e5bcc9 clang::TextDiagnosticBuffer::HandleDiagnostic(enum 
> clang::DiagnosticsEngine::Level, class clang::Diagnostic const &) 
> F:\source\llvm-project\clang\lib\Frontend\TextDiagnosticBuffer.cpp:30:0
>   #10 0x7ff663ef2d71 
> clang::VerifyDiagnosticConsumer::HandleDiagnostic(enum 
> clang::DiagnosticsEngine::Level, class clang::Diagnostic const &) 
> F:\source\llvm-project\clang\lib\Frontend\VerifyDiagnosticConsumer.cpp:757:0
>   #11 0x7ff662a0b66f clang::DiagnosticIDs::EmitDiag(class 
> clang::DiagnosticsEngine &, enum clang::DiagnosticIDs::Level) const 
> F:\source\llvm-project\clang\lib\Basic\DiagnosticIDs.cpp:839:0
>   #12 0x7ff662a0b597 clang::DiagnosticIDs::ProcessDiag(class 
> clang::DiagnosticsEngine &) const 
> F:\source\llvm-project\clang\lib\Basic\DiagnosticIDs.cpp:831:0
>   #13 0x7ff662a267ef clang::DiagnosticsEngine::ProcessDiag(void) 
> F:\source\llvm-project\clang\include\clang\Basic\Diagnostic.h:1038:0
>   #14 0x7ff662a15f64 
> clang::DiagnosticsEngine::EmitCurrentDiagnostic(bool) 
> F:\source\llvm-project\clang\lib\Basic\Diagnostic.cpp:549:0
>   #15 0x7ff667b47cbc clang::Sema::EmitCurrentDiagnostic(unsigned int) 
> F:\source\llvm-project\clang\lib\Sema\Sema.cpp:1575:0
>   #16 0x7ff667b89d97 
> clang::Sema::ImmediateDiagBuilder::~ImmediateDiagBuilder(void) 
> F:\source\llvm-project\clang\include\clang\Sema\Sema.h:1726:0
>   #17 0x7ff667b8e9e8 clang::Sema::ImmediateDiagBuilder::`scalar deleting 
> dtor'(unsigned int) 
> (f:\source\llvm-project\llvm\out\build\x64-debug\bin\clang.exe+0x81fe9e8)
>   #18 0x7ff667b72b06 std::_Destroy_in_place clang::Sema::ImmediateDiagBuilder>(class clang::Sema::ImmediateDiagBuilder &) 
> C:\Program Files\Microsoft Visual 
> Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\xmemory:300:0
>   #19 0x7ff667bac5b4 std::_Optional_destruct_base clang::Sema::ImmediateDiagBuilder, 0>::reset(void) C:\Program Files\Microsoft 
> Visual 
> Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\optional:133:0
>   #20 0x7ff667b53424 
> clang::Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder(void) 
> F:\source\llvm-project\clang\lib\Sema\Sema.cpp:1859:0
>   #21 0x7ff668618b4a clang::Sema::ParsedFreeStandingDeclSpec(class 
> clang::Scope *, enum clang::AccessSpecifier, class clang::DeclSpec &, class 
> clang::ParsedAttributesView const &, class llvm::MutableArrayRef clang::TemplateParameterList *>, bool, class clang::RecordDecl *&) 
> F:\source\llvm-project\clang\lib\Sema\SemaDecl.cpp:5151:0
>   #22 0x7ff668618545 clang::Sema::ParsedFreeStandingDeclSpec(class 
> clang::Scope *, enum clang::AccessSpecifier, class clang::DeclSpec &, class 
> 

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

Oops, I spoke too soon -- it looks like the precommit CI failure is related to 
this patch. This is what I get when I tested locally:

  Assertion failed: NextVal != ArgumentEnd && "Value for integer select 
modifier was" " larger than the number of options in the diagnostic string!", 
file F:\source\llvm-project\clang\lib\Basic\Diagnostic.cpp, line 623
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
and include the crash backtrace, preprocessed source, and associated run script.
  Stack dump:
  0.  Program arguments: 
f:\\source\\llvm-project\\llvm\\out\\build\\x64-debug\\bin\\clang.exe -cc1 
-internal-isystem 
f:\\source\\llvm-project\\llvm\\out\\build\\x64-debug\\lib\\clang\\17\\include 
-nostdsysteminc -std=c++11 -triple x86_64-unknown-unknown 
F:\\source\\llvm-project\\clang\\test\\CXX\\drs\\dr16xx.cpp -verify 
-fexceptions -fcxx-exceptions -pedantic-errors
  1.  F:\source\llvm-project\clang\test\CXX\drs\dr16xx.cpp:91:3: current 
parser token 'template'
  2.  F:\source\llvm-project\clang\test\CXX\drs\dr16xx.cpp:71:1: parsing 
namespace 'dr1638'
  Exception Code: 0x8003
   #0 0x7ff6625ea26c HandleAbort 
F:\source\llvm-project\llvm\lib\Support\Windows\Signals.inc:419:0
   #1 0x7ffa9b23bc31 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x6bc31)
   #2 0x7ffa9b23d889 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x6d889)
   #3 0x7ffa9b2430bf (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x730bf)
   #4 0x7ffa9b241091 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x71091)
   #5 0x7ffa9b243a1f (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x73a1f)
   #6 0x7ff662a19b8c HandleSelectModifier 
F:\source\llvm-project\clang\lib\Basic\Diagnostic.cpp:622:0
   #7 0x7ff662a17137 clang::Diagnostic::FormatDiagnostic(char const *, char 
const *, class llvm::SmallVectorImpl &) const 
F:\source\llvm-project\clang\lib\Basic\Diagnostic.cpp:1005:0
   #8 0x7ff662a16518 clang::Diagnostic::FormatDiagnostic(class 
llvm::SmallVectorImpl &) const 
F:\source\llvm-project\clang\lib\Basic\Diagnostic.cpp:805:0
   #9 0x7ff663e5bcc9 clang::TextDiagnosticBuffer::HandleDiagnostic(enum 
clang::DiagnosticsEngine::Level, class clang::Diagnostic const &) 
F:\source\llvm-project\clang\lib\Frontend\TextDiagnosticBuffer.cpp:30:0
  #10 0x7ff663ef2d71 clang::VerifyDiagnosticConsumer::HandleDiagnostic(enum 
clang::DiagnosticsEngine::Level, class clang::Diagnostic const &) 
F:\source\llvm-project\clang\lib\Frontend\VerifyDiagnosticConsumer.cpp:757:0
  #11 0x7ff662a0b66f clang::DiagnosticIDs::EmitDiag(class 
clang::DiagnosticsEngine &, enum clang::DiagnosticIDs::Level) const 
F:\source\llvm-project\clang\lib\Basic\DiagnosticIDs.cpp:839:0
  #12 0x7ff662a0b597 clang::DiagnosticIDs::ProcessDiag(class 
clang::DiagnosticsEngine &) const 
F:\source\llvm-project\clang\lib\Basic\DiagnosticIDs.cpp:831:0
  #13 0x7ff662a267ef clang::DiagnosticsEngine::ProcessDiag(void) 
F:\source\llvm-project\clang\include\clang\Basic\Diagnostic.h:1038:0
  #14 0x7ff662a15f64 clang::DiagnosticsEngine::EmitCurrentDiagnostic(bool) 
F:\source\llvm-project\clang\lib\Basic\Diagnostic.cpp:549:0
  #15 0x7ff667b47cbc clang::Sema::EmitCurrentDiagnostic(unsigned int) 
F:\source\llvm-project\clang\lib\Sema\Sema.cpp:1575:0
  #16 0x7ff667b89d97 
clang::Sema::ImmediateDiagBuilder::~ImmediateDiagBuilder(void) 
F:\source\llvm-project\clang\include\clang\Sema\Sema.h:1726:0
  #17 0x7ff667b8e9e8 clang::Sema::ImmediateDiagBuilder::`scalar deleting 
dtor'(unsigned int) 
(f:\source\llvm-project\llvm\out\build\x64-debug\bin\clang.exe+0x81fe9e8)
  #18 0x7ff667b72b06 std::_Destroy_in_place(class clang::Sema::ImmediateDiagBuilder &) 
C:\Program Files\Microsoft Visual 
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\xmemory:300:0
  #19 0x7ff667bac5b4 std::_Optional_destruct_base::reset(void) C:\Program Files\Microsoft 
Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\optional:133:0
  #20 0x7ff667b53424 
clang::Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder(void) 
F:\source\llvm-project\clang\lib\Sema\Sema.cpp:1859:0
  #21 0x7ff668618b4a clang::Sema::ParsedFreeStandingDeclSpec(class 
clang::Scope *, enum clang::AccessSpecifier, class clang::DeclSpec &, class 
clang::ParsedAttributesView const &, class llvm::MutableArrayRef, bool, class clang::RecordDecl *&) 
F:\source\llvm-project\clang\lib\Sema\SemaDecl.cpp:5151:0
  #22 0x7ff668618545 clang::Sema::ParsedFreeStandingDeclSpec(class 
clang::Scope *, enum clang::AccessSpecifier, class clang::DeclSpec &, class 
clang::ParsedAttributesView const &, class clang::RecordDecl *&) 
F:\source\llvm-project\clang\lib\Sema\SemaDecl.cpp:4844:0
  #23 0x7ff66797e8e2 clang::Parser::ParseDeclOrFunctionDefInternal(class 
clang::ParsedAttributes &, class clang::ParsedAttributes &, class 
clang::ParsingDeclSpec &, enum 

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

Do you need someone to land this on your behalf? If so, what name and email 
address would you like used for patch attribution? (I can fix the tiny style 
nit myself when landing, so don't feel obligated to make the change yourself 
unless you're committing the patch.)




Comment at: clang/lib/Sema/SemaDecl.cpp:5045
+return 5;
+  else if (ED->isScoped())
+return 6;

Tiny style nit; NFC (we have a rule about using `else` after a `return`).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-22 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 updated this revision to Diff 516037.
ipriyanshi1708 marked 4 inline comments as done.
ipriyanshi1708 added a comment.

Removed unwanted changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/attr-declspec-ignored.cpp

Index: clang/test/SemaCXX/attr-declspec-ignored.cpp
===
--- clang/test/SemaCXX/attr-declspec-ignored.cpp
+++ clang/test/SemaCXX/attr-declspec-ignored.cpp
@@ -9,6 +9,10 @@
   // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
   __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
   // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+  // expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum struct ES {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum struct" to apply attribute to type declaration}} \
+  // expected-warning{{attribute 'aligned' is ignored, place it after "enum struct" to apply attribute to type declaration}}
 
   // Test that we get the same warnings for type declarations nested in a record.
   struct X {
@@ -20,7 +24,11 @@
 // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
 __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
-
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum struct ES {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum struct" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum struct" to apply attribute to type declaration}}
+  
 // Also test [[]] attribute syntax. (On a non-nested declaration, these
 // generate a hard "misplaced attributes" error, which we test for
 // elsewhere.)
@@ -32,6 +40,10 @@
 // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] enum H {H}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+[[gnu::visibility("hidden")]]  [[gnu::aligned]] enum class I {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
+[[gnu::visibility("hidden")]]  [[gnu::aligned]] enum struct J {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum struct" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum struct" to apply attribute to type declaration}}
   };
 }
 
@@ -40,16 +52,22 @@
   __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B {} b;
   __attribute__((visibility("hidden")))  __attribute__((aligned)) union C {} c;
   __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D} d;
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {} ec;
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum struct ES {} es;
 
   struct X {
 __attribute__((visibility("hidden")))  __attribute__((aligned)) class A {} a;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B {} b;
 

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-22 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 updated this revision to Diff 516036.
ipriyanshi1708 added a comment.

Added case for enum struct


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/attr-declspec-ignored.c
  clang/test/SemaCXX/attr-declspec-ignored.cpp

Index: clang/test/SemaCXX/attr-declspec-ignored.cpp
===
--- clang/test/SemaCXX/attr-declspec-ignored.cpp
+++ clang/test/SemaCXX/attr-declspec-ignored.cpp
@@ -9,6 +9,10 @@
   // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
   __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
   // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+  // expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum struct ES {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum struct" to apply attribute to type declaration}} \
+  // expected-warning{{attribute 'aligned' is ignored, place it after "enum struct" to apply attribute to type declaration}}
 
   // Test that we get the same warnings for type declarations nested in a record.
   struct X {
@@ -20,7 +24,11 @@
 // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
 __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
-
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum struct ES {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum struct" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum struct" to apply attribute to type declaration}}
+  
 // Also test [[]] attribute syntax. (On a non-nested declaration, these
 // generate a hard "misplaced attributes" error, which we test for
 // elsewhere.)
@@ -32,6 +40,10 @@
 // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] enum H {H}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+[[gnu::visibility("hidden")]]  [[gnu::aligned]] enum class I {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
+[[gnu::visibility("hidden")]]  [[gnu::aligned]] enum struct J {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum struct" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum struct" to apply attribute to type declaration}}
   };
 }
 
@@ -40,16 +52,22 @@
   __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B {} b;
   __attribute__((visibility("hidden")))  __attribute__((aligned)) union C {} c;
   __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D} d;
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {} ec;
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum struct ES {} es;
 
   struct X {
 __attribute__((visibility("hidden")))  __attribute__((aligned)) class A {} a;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B {} b;
 

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

Thank you for working on this! I spotted a little more that needs to be done, 
but this is pretty close to ready. I *think* the precommit CI failures are 
unrelated to this change, but you should double-check just to be sure.




Comment at: clang/lib/Sema/SemaDecl.cpp:5031
+static unsigned GetDiagnosticTypeSpecifierID(const DeclSpec ) {
+  DeclSpec::TST T=DS.getTypeSpecType();
   switch (T) {

Style nit; NFC



Comment at: clang/lib/Sema/SemaDecl.cpp:5042-5046
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+return 5;
+}
 return 4;

There's a subtle bug hiding in here, consider code like:
```
 __attribute__((visibility("hidden")))  __attribute__((aligned)) enum struct E 
{};
```
The diagnostic will emit `enum` because the `EnumDecl` is scoped using the 
`struct` tag rather than the `class` tag. I think you should add another entry 
to the `%select` for `enum struct` and return that value here if 
`ED->isScoped()` is true, and only return `4` for a plain `enum`.



Comment at: clang/test/Sema/attr-declspec-ignored.c:23
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum F {F} f;
\ No newline at end of file


I'm not seeing what changed with this line, I think  you can revert the changes 
to this file.



Comment at: clang/test/SemaCXX/attr-declspec-ignored.cpp:12
   // expected-warning{{attribute 'aligned' is ignored, place it after "enum" 
to apply attribute to type declaration}}
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class 
EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after 
"enum class" to apply attribute to type declaration}} \
+  // expected-warning{{attribute 'aligned' is ignored, place it after "enum 
class" to apply attribute to type declaration}}

Once you fix the `enum struct` diagnostic above, I'd recommend adding some 
`enum struct` test cases.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-20 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 marked 3 inline comments as done.
ipriyanshi1708 added a comment.

In D147989#4283666 , @samtebbs wrote:

> This looks good to me now, nice work. Let's wait a few days for others' input 
> to be safe.

okay! Thank You Sir.




Comment at: clang/lib/Sema/SemaDecl.cpp:5051
+return 5;
+  else
+return 4;

samtebbs wrote:
> Instead of returning 4 here, I think it's best to just delegate to the other 
> `GetDiagnosticTypeSpecifierID` function. That way, if the IDs change for 
> whatever reason they only have to updated in one place. This could be done 
> cleanly by just making the call below be at the top level of the function 
> (i.e. not inside an `else` block).
Ya that can be done. I will do it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-20 Thread Sam Tebbs via Phabricator via cfe-commits
samtebbs accepted this revision.
samtebbs added a comment.
This revision is now accepted and ready to land.

This looks good to me now, nice work. Let's wait a few days for others' input 
to be safe.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-19 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 updated this revision to Diff 515196.
ipriyanshi1708 marked an inline comment as done.
ipriyanshi1708 added a comment.

Updated the logic in a better way


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/attr-declspec-ignored.c
  clang/test/SemaCXX/attr-declspec-ignored.cpp

Index: clang/test/SemaCXX/attr-declspec-ignored.cpp
===
--- clang/test/SemaCXX/attr-declspec-ignored.cpp
+++ clang/test/SemaCXX/attr-declspec-ignored.cpp
@@ -9,6 +9,8 @@
   // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
   __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
   // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+  // expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
 
   // Test that we get the same warnings for type declarations nested in a record.
   struct X {
@@ -20,7 +22,9 @@
 // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
 __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
-
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
+  
 // Also test [[]] attribute syntax. (On a non-nested declaration, these
 // generate a hard "misplaced attributes" error, which we test for
 // elsewhere.)
@@ -32,6 +36,8 @@
 // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] enum H {H}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+[[gnu::visibility("hidden")]]  [[gnu::aligned]] enum class I {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
   };
 }
 
@@ -40,16 +46,19 @@
   __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B {} b;
   __attribute__((visibility("hidden")))  __attribute__((aligned)) union C {} c;
   __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D} d;
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {} ec;
 
   struct X {
 __attribute__((visibility("hidden")))  __attribute__((aligned)) class A {} a;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B {} b;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) union C {} c;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D} d;
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {} ec;
 
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] class E {} e;
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] struct F {} f;
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] union G {} g;
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] enum H {H} h;
+[[gnu::visibility("hidden")]]  [[gnu::aligned]] enum class I {} i;
   };
 }
Index: clang/test/Sema/attr-declspec-ignored.c
===
--- clang/test/Sema/attr-declspec-ignored.c
+++ clang/test/Sema/attr-declspec-ignored.c
@@ -19,4 +19,4 @@
 
 __attribute__((visibility("hidden")))  __attribute__((aligned)) struct D {} d;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) union E {} e;
-__attribute__((visibility("hidden")))  __attribute__((aligned)) enum F {F} f;

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-19 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 updated this revision to Diff 514931.
ipriyanshi1708 marked an inline comment as done.
ipriyanshi1708 added a comment.

Updated the logic


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/attr-declspec-ignored.c
  clang/test/SemaCXX/attr-declspec-ignored.cpp

Index: clang/test/SemaCXX/attr-declspec-ignored.cpp
===
--- clang/test/SemaCXX/attr-declspec-ignored.cpp
+++ clang/test/SemaCXX/attr-declspec-ignored.cpp
@@ -9,6 +9,8 @@
   // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
   __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
   // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+  // expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
 
   // Test that we get the same warnings for type declarations nested in a record.
   struct X {
@@ -20,7 +22,9 @@
 // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
 __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
-
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
+  
 // Also test [[]] attribute syntax. (On a non-nested declaration, these
 // generate a hard "misplaced attributes" error, which we test for
 // elsewhere.)
@@ -32,6 +36,8 @@
 // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] enum H {H}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+[[gnu::visibility("hidden")]]  [[gnu::aligned]] enum class I {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
   };
 }
 
@@ -40,16 +46,19 @@
   __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B {} b;
   __attribute__((visibility("hidden")))  __attribute__((aligned)) union C {} c;
   __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D} d;
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {} ec;
 
   struct X {
 __attribute__((visibility("hidden")))  __attribute__((aligned)) class A {} a;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B {} b;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) union C {} c;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D} d;
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {} ec;
 
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] class E {} e;
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] struct F {} f;
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] union G {} g;
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] enum H {H} h;
+[[gnu::visibility("hidden")]]  [[gnu::aligned]] enum class I {} i;
   };
 }
Index: clang/test/Sema/attr-declspec-ignored.c
===
--- clang/test/Sema/attr-declspec-ignored.c
+++ clang/test/Sema/attr-declspec-ignored.c
@@ -19,4 +19,4 @@
 
 __attribute__((visibility("hidden")))  __attribute__((aligned)) struct D {} d;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) union E {} e;
-__attribute__((visibility("hidden")))  __attribute__((aligned)) enum F {F} f;

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-19 Thread Sam Tebbs via Phabricator via cfe-commits
samtebbs added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:5041
   case DeclSpec::TST_enum:
 return 4;
   default:

ipriyanshi1708 wrote:
> jrtc27 wrote:
> > Why not just always pass the full DeclSpec and handle the class case here, 
> > maybe with a bool to allow other users to not need to treat enum class as 
> > different?
> Ya, we can do that too. But like GetDiagnosticTypeSpecifierID() is also 
> called in many other places in the file so if I pass the full DeclSpec in 
> this function will not disturb those calls?
It's probably worth doing as the other callsites just pass the `DeclSpec`'s 
type specifier.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-19 Thread Sam Tebbs via Phabricator via cfe-commits
samtebbs added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:5051
+return 5;
+  else
+return 4;

Instead of returning 4 here, I think it's best to just delegate to the other 
`GetDiagnosticTypeSpecifierID` function. That way, if the IDs change for 
whatever reason they only have to updated in one place. This could be done 
cleanly by just making the call below be at the top level of the function (i.e. 
not inside an `else` block).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-19 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 updated this revision to Diff 514911.
ipriyanshi1708 added a comment.

Removed spurious whitespace changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/attr-declspec-ignored.c
  clang/test/SemaCXX/attr-declspec-ignored.cpp

Index: clang/test/SemaCXX/attr-declspec-ignored.cpp
===
--- clang/test/SemaCXX/attr-declspec-ignored.cpp
+++ clang/test/SemaCXX/attr-declspec-ignored.cpp
@@ -9,6 +9,8 @@
   // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
   __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
   // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+  // expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
 
   // Test that we get the same warnings for type declarations nested in a record.
   struct X {
@@ -20,7 +22,9 @@
 // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
 __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
-
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
+  
 // Also test [[]] attribute syntax. (On a non-nested declaration, these
 // generate a hard "misplaced attributes" error, which we test for
 // elsewhere.)
@@ -32,6 +36,8 @@
 // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] enum H {H}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+[[gnu::visibility("hidden")]]  [[gnu::aligned]] enum class I {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
   };
 }
 
@@ -40,16 +46,19 @@
   __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B {} b;
   __attribute__((visibility("hidden")))  __attribute__((aligned)) union C {} c;
   __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D} d;
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {} ec;
 
   struct X {
 __attribute__((visibility("hidden")))  __attribute__((aligned)) class A {} a;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B {} b;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) union C {} c;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D} d;
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {} ec;
 
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] class E {} e;
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] struct F {} f;
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] union G {} g;
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] enum H {H} h;
+[[gnu::visibility("hidden")]]  [[gnu::aligned]] enum class I {} i;
   };
 }
Index: clang/test/Sema/attr-declspec-ignored.c
===
--- clang/test/Sema/attr-declspec-ignored.c
+++ clang/test/Sema/attr-declspec-ignored.c
@@ -19,4 +19,4 @@
 
 __attribute__((visibility("hidden")))  __attribute__((aligned)) struct D {} d;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) union E {} e;
-__attribute__((visibility("hidden")))  __attribute__((aligned)) enum F {F} f;
+__attribute__((visibility("hidden")))  

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-19 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 updated this revision to Diff 514909.
ipriyanshi1708 added a comment.

Updated the test file


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/attr-declspec-ignored.c
  clang/test/SemaCXX/attr-declspec-ignored.cpp

Index: clang/test/SemaCXX/attr-declspec-ignored.cpp
===
--- clang/test/SemaCXX/attr-declspec-ignored.cpp
+++ clang/test/SemaCXX/attr-declspec-ignored.cpp
@@ -9,6 +9,8 @@
   // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
   __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
   // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+  // expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
 
   // Test that we get the same warnings for type declarations nested in a record.
   struct X {
@@ -20,7 +22,9 @@
 // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
 __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
-
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
+  
 // Also test [[]] attribute syntax. (On a non-nested declaration, these
 // generate a hard "misplaced attributes" error, which we test for
 // elsewhere.)
@@ -32,6 +36,8 @@
 // expected-warning{{attribute 'aligned' is ignored, place it after "union" to apply attribute to type declaration}}
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] enum H {H}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum" to apply attribute to type declaration}}
+[[gnu::visibility("hidden")]]  [[gnu::aligned]] enum class I {}; // expected-warning{{attribute 'visibility' is ignored, place it after "enum class" to apply attribute to type declaration}} \
+// expected-warning{{attribute 'aligned' is ignored, place it after "enum class" to apply attribute to type declaration}}
   };
 }
 
@@ -40,16 +46,19 @@
   __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B {} b;
   __attribute__((visibility("hidden")))  __attribute__((aligned)) union C {} c;
   __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D} d;
+  __attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {} ec;
 
   struct X {
 __attribute__((visibility("hidden")))  __attribute__((aligned)) class A {} a;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) struct B {} b;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) union C {} c;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) enum D {D} d;
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum class EC {} ec;
 
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] class E {} e;
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] struct F {} f;
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] union G {} g;
 [[gnu::visibility("hidden")]]  [[gnu::aligned]] enum H {H} h;
+[[gnu::visibility("hidden")]]  [[gnu::aligned]] enum class I {} i;
   };
 }
Index: clang/test/Sema/attr-declspec-ignored.c
===
--- clang/test/Sema/attr-declspec-ignored.c
+++ clang/test/Sema/attr-declspec-ignored.c
@@ -19,4 +19,4 @@
 
 __attribute__((visibility("hidden")))  __attribute__((aligned)) struct D {} d;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) union E {} e;
-__attribute__((visibility("hidden")))  __attribute__((aligned)) enum F {F} f;
+__attribute__((visibility("hidden")))  __attribute__((aligned)) 

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-14 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 added a comment.

In D147989#4257721 , @aaron.ballman 
wrote:

> Thank you for working on this!
>
> The changes are missing test coverage; please be sure to add that, along with 
> a release note about the fix. I think there's likely more work to be done 
> here as well, considering this behavior: https://godbolt.org/z/sdK3Gef75 
> (notice the suggested location for the fix-it -- that also needs to be fixed 
> for this)

Can you please provide me guidance for writing tests for enum class. As I have 
tried but I am not getting any idea on how to write new tests for enum class.




Comment at: clang/lib/Sema/SemaDecl.cpp:5041
   case DeclSpec::TST_enum:
 return 4;
   default:

jrtc27 wrote:
> Why not just always pass the full DeclSpec and handle the class case here, 
> maybe with a bool to allow other users to not need to treat enum class as 
> different?
Ya, we can do that too. But like GetDiagnosticTypeSpecifierID() is also called 
in many other places in the file so if I pass the full DeclSpec in this 
function will not disturb those calls?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-14 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 updated this revision to Diff 513549.
ipriyanshi1708 marked 5 inline comments as done.
ipriyanshi1708 added a comment.

Improved the logic


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/attr-declspec-ignored.c


Index: clang/test/Sema/attr-declspec-ignored.c
===
--- clang/test/Sema/attr-declspec-ignored.c
+++ clang/test/Sema/attr-declspec-ignored.c
@@ -19,4 +19,4 @@
 
 __attribute__((visibility("hidden")))  __attribute__((aligned)) struct D {} d;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) union E {} e;
-__attribute__((visibility("hidden")))  __attribute__((aligned)) enum F {F} f;
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum F {F} f;
\ No newline at end of file
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5043,7 +5043,20 @@
 llvm_unreachable("unexpected type specifier");
   }
 }
-
+static unsigned GetDiagnosticTypeSpecifierID(const DeclSpec ){
+  if (DS.getTypeSpecType() == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+return 5;
+  else
+return 4;
+}
+  }
+  else{
+return GetDiagnosticTypeSpecifierID(DS.getTypeSpecType());
+  }
+  return 0;
+}
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
 /// no declarator (e.g. "struct foo;") is parsed. It also accepts template
 /// parameters to cope with template friend declarations.
@@ -5300,11 +5313,11 @@
 TypeSpecType == DeclSpec::TST_enum) {
   for (const ParsedAttr  : DS.getAttributes())
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
+<< AL << GetDiagnosticTypeSpecifierID(DS);
   for (const ParsedAttr  : DeclAttrs)
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
-}
+<< AL << GetDiagnosticTypeSpecifierID(DS);
+}
   }
 
   return TagD;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3421,7 +3421,7 @@
   InGroup;
 def warn_declspec_attribute_ignored : Warning<
   "attribute %0 is ignored, place it after "
-  "\"%select{class|struct|interface|union|enum}1\" to apply attribute to "
+  "\"%select{class|struct|interface|union|enum|enum class}1\" to apply 
attribute to "
   "type declaration">, InGroup;
 def warn_attribute_precede_definition : Warning<
   "attribute declaration must precede definition">,
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -193,6 +193,8 @@
 
 Bug Fixes to Attribute Support
 ^^
+- Fixed a bug where attribute annotations on type specifiers (enums, classes, 
structs, unions, and scoped enums) were not properly ignored, resulting in 
misleading warning messages. Now, such attribute annotations are correctly 
ignored.
+(`#61660 `_)
 
 Bug Fixes to C++ Support
 


Index: clang/test/Sema/attr-declspec-ignored.c
===
--- clang/test/Sema/attr-declspec-ignored.c
+++ clang/test/Sema/attr-declspec-ignored.c
@@ -19,4 +19,4 @@
 
 __attribute__((visibility("hidden")))  __attribute__((aligned)) struct D {} d;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) union E {} e;
-__attribute__((visibility("hidden")))  __attribute__((aligned)) enum F {F} f;
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum F {F} f;
\ No newline at end of file
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5043,7 +5043,20 @@
 llvm_unreachable("unexpected type specifier");
   }
 }
-
+static unsigned GetDiagnosticTypeSpecifierID(const DeclSpec ){
+  if (DS.getTypeSpecType() == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+return 5;
+  else
+return 4;
+}
+  }
+  else{
+return GetDiagnosticTypeSpecifierID(DS.getTypeSpecType());
+  }
+  return 0;
+}
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
 /// 

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-13 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:5041
   case DeclSpec::TST_enum:
 return 4;
   default:

Why not just always pass the full DeclSpec and handle the class case here, 
maybe with a bool to allow other users to not need to treat enum class as 
different?



Comment at: clang/lib/Sema/SemaDecl.cpp:5052-5053
+}
+  }
+  else{
+return GetDiagnosticTypeSpecifierID(DS.getTypeSpecType());

Read the style guide



Comment at: clang/lib/Sema/SemaDecl.cpp:5318
+<< AL << GetDiagnosticTypeSpecifierID(DS);
+}
   }

?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Precommit CI has several failures introduced by this patch -- some test cases 
need to be fixed up (in addition to the new test coverage).




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3424
   "attribute %0 is ignored, place it after "
-  "\"%select{class|struct|interface|union|enum}1\" to apply attribute to "
+  "\"%select{class|struct|interface|union|enum|enum class}1\" to apply 
attribute to "
   "type declaration">, InGroup;

tbaeder wrote:
> "enum struct" is also possible in C++, so I think this needs to be covered as 
> well.
If that turns out to be frustrating for some reason, we could perhaps reuse 
`class` or `struct` instead of adding `enum ` as another option. e.g.,
```
__attribute__((whatever)) // warning: attribute 'whatever' is ignored, place it 
after "class" to apply attribute to type declaration
enum class foo {
};
```
coupled with the insert caret and fix-it hint, it's pretty clear where to move 
the attribute to despite the warning not saying `enum class` specifically.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3424
   "attribute %0 is ignored, place it after "
-  "\"%select{class|struct|interface|union|enum}1\" to apply attribute to "
+  "\"%select{class|struct|interface|union|enum|enum class}1\" to apply 
attribute to "
   "type declaration">, InGroup;

"enum struct" is also possible in C++, so I think this needs to be covered as 
well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-11 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 updated this revision to Diff 512445.
ipriyanshi1708 added a comment.

Applied C++ Overloading


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp


Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5043,7 +5043,18 @@
 llvm_unreachable("unexpected type specifier");
   }
 }
-
+static unsigned GetDiagnosticTypeSpecifierID(const DeclSpec ){
+  if (DS.getTypeSpecType() == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+  return 5;
+}
+  }
+  else{
+return GetDiagnosticTypeSpecifierID(DS.getTypeSpecType());
+  }
+  return 0;
+}
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
 /// no declarator (e.g. "struct foo;") is parsed. It also accepts template
 /// parameters to cope with template friend declarations.
@@ -5300,11 +5311,11 @@
 TypeSpecType == DeclSpec::TST_enum) {
   for (const ParsedAttr  : DS.getAttributes())
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
+<< AL << GetDiagnosticTypeSpecifierID(DS);
   for (const ParsedAttr  : DeclAttrs)
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
-}
+<< AL << GetDiagnosticTypeSpecifierID(DS);
+}
   }
 
   return TagD;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3421,7 +3421,7 @@
   InGroup;
 def warn_declspec_attribute_ignored : Warning<
   "attribute %0 is ignored, place it after "
-  "\"%select{class|struct|interface|union|enum}1\" to apply attribute to "
+  "\"%select{class|struct|interface|union|enum|enum class}1\" to apply 
attribute to "
   "type declaration">, InGroup;
 def warn_attribute_precede_definition : Warning<
   "attribute declaration must precede definition">,
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -193,6 +193,8 @@
 
 Bug Fixes to Attribute Support
 ^^
+- Fixed a bug where attribute annotations on type specifiers (enums, classes, 
structs, unions, and scoped enums) were not properly ignored, resulting in 
misleading warning messages. Now, such attribute annotations are correctly 
ignored.
+(`#61660 `_)
 
 Bug Fixes to C++ Support
 


Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5043,7 +5043,18 @@
 llvm_unreachable("unexpected type specifier");
   }
 }
-
+static unsigned GetDiagnosticTypeSpecifierID(const DeclSpec ){
+  if (DS.getTypeSpecType() == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+  return 5;
+}
+  }
+  else{
+return GetDiagnosticTypeSpecifierID(DS.getTypeSpecType());
+  }
+  return 0;
+}
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
 /// no declarator (e.g. "struct foo;") is parsed. It also accepts template
 /// parameters to cope with template friend declarations.
@@ -5300,11 +5311,11 @@
 TypeSpecType == DeclSpec::TST_enum) {
   for (const ParsedAttr  : DS.getAttributes())
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
+<< AL << GetDiagnosticTypeSpecifierID(DS);
   for (const ParsedAttr  : DeclAttrs)
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
-}
+<< AL << GetDiagnosticTypeSpecifierID(DS);
+}
   }
 
   return TagD;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3421,7 +3421,7 @@
   InGroup;
 def warn_declspec_attribute_ignored : Warning<
   "attribute %0 is ignored, place it after "
-  "\"%select{class|struct|interface|union|enum}1\" to apply attribute to "
+  "\"%select{class|struct|interface|union|enum|enum class}1\" to apply attribute to "
   "type declaration">, InGroup;
 def 

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-11 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 added a comment.

In D147989#4257947 , @samtebbs wrote:

> Thanks for the input Aaron and Martin. This is looking good. With the 
> suggested changes and some formatting 
>  I think it 
> will be ready.

Okay! I will update it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-11 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 updated this revision to Diff 512437.
ipriyanshi1708 added a comment.

Added the Release note for the fix


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp


Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5043,7 +5043,18 @@
 llvm_unreachable("unexpected type specifier");
   }
 }
-
+static unsigned GetDiagnosticTypeSpecifierIDWithAttrs(DeclSpec::TST T, const 
DeclSpec ){
+  if (T == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+  return 5;
+}
+  }
+  else{
+return GetDiagnosticTypeSpecifierID(T);
+  }
+  return 0;
+}
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
 /// no declarator (e.g. "struct foo;") is parsed. It also accepts template
 /// parameters to cope with template friend declarations.
@@ -5300,11 +5311,11 @@
 TypeSpecType == DeclSpec::TST_enum) {
   for (const ParsedAttr  : DS.getAttributes())
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
+<< AL << GetDiagnosticTypeSpecifierIDWithAttrs(TypeSpecType,DS);
   for (const ParsedAttr  : DeclAttrs)
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
-}
+<< AL << GetDiagnosticTypeSpecifierIDWithAttrs(TypeSpecType,DS);
+}
   }
 
   return TagD;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3421,7 +3421,7 @@
   InGroup;
 def warn_declspec_attribute_ignored : Warning<
   "attribute %0 is ignored, place it after "
-  "\"%select{class|struct|interface|union|enum}1\" to apply attribute to "
+  "\"%select{class|struct|interface|union|enum|enum class}1\" to apply 
attribute to "
   "type declaration">, InGroup;
 def warn_attribute_precede_definition : Warning<
   "attribute declaration must precede definition">,
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -193,6 +193,8 @@
 
 Bug Fixes to Attribute Support
 ^^
+- Fixed a bug where attribute annotations on type specifiers (enums, classes, 
structs, unions, and scoped enums) were not properly ignored, resulting in 
misleading warning messages. Now, such attribute annotations are correctly 
ignored.
+(`#61660 `_)
 
 Bug Fixes to C++ Support
 


Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5043,7 +5043,18 @@
 llvm_unreachable("unexpected type specifier");
   }
 }
-
+static unsigned GetDiagnosticTypeSpecifierIDWithAttrs(DeclSpec::TST T, const DeclSpec ){
+  if (T == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+  return 5;
+}
+  }
+  else{
+return GetDiagnosticTypeSpecifierID(T);
+  }
+  return 0;
+}
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
 /// no declarator (e.g. "struct foo;") is parsed. It also accepts template
 /// parameters to cope with template friend declarations.
@@ -5300,11 +5311,11 @@
 TypeSpecType == DeclSpec::TST_enum) {
   for (const ParsedAttr  : DS.getAttributes())
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
+<< AL << GetDiagnosticTypeSpecifierIDWithAttrs(TypeSpecType,DS);
   for (const ParsedAttr  : DeclAttrs)
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
-}
+<< AL << GetDiagnosticTypeSpecifierIDWithAttrs(TypeSpecType,DS);
+}
   }
 
   return TagD;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3421,7 +3421,7 @@
   InGroup;
 def warn_declspec_attribute_ignored : Warning<
   "attribute %0 is ignored, place it after "
-  "\"%select{class|struct|interface|union|enum}1\" to apply attribute to "
+  "\"%select{class|struct|interface|union|enum|enum 

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-11 Thread Sam Tebbs via Phabricator via cfe-commits
samtebbs added a comment.

Thanks for the input Aaron and Martin. This is looking good. With the suggested 
changes (don't forget the test, you could try adding one to 
clang/test/Sema/attr-declspec-ignored.c and 
clang/test/SemaCXX/attr-declspec-ignored.cpp) and some formatting 
 I think it will 
be ready.




Comment at: clang/include/clang/Sema/DeclSpec.h:274
   };
-
+  
   // Import type specifier type enumeration and constants.

There is still a whitespace change here.



Comment at: clang/lib/Sema/SemaDecl.cpp:5045
 }
-
+static unsigned GetDiagnosticTypeSpecifierIDWithAttrs(DeclSpec::TST T, const 
DeclSpec ){
+  if (T == DeclSpec::TST_enum) {

Thanks to C++ overloading, this can be called `GetDiagnosticTypeSpecifierID`, 
and I don't think it will need the `T` parameter since that can be fetched with 
`DS.getTypeSpecType()`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-11 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 added a comment.

In D147989#4257721 , @aaron.ballman 
wrote:

> Thank you for working on this!
>
> The changes are missing test coverage; please be sure to add that, along with 
> a release note about the fix. I think there's likely more work to be done 
> here as well, considering this behavior: https://godbolt.org/z/sdK3Gef75 
> (notice the suggested location for the fix-it -- that also needs to be fixed 
> for this)

Thanks for reviewing. I am working on tests now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-11 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 updated this revision to Diff 512421.
ipriyanshi1708 added a comment.

Removed the spurious whitespace changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Sema/SemaDecl.cpp


Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5043,7 +5043,18 @@
 llvm_unreachable("unexpected type specifier");
   }
 }
-
+static unsigned GetDiagnosticTypeSpecifierIDWithAttrs(DeclSpec::TST T, const 
DeclSpec ){
+  if (T == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+  return 5;
+}
+  }
+  else{
+return GetDiagnosticTypeSpecifierID(T);
+  }
+  return 0;
+}
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
 /// no declarator (e.g. "struct foo;") is parsed. It also accepts template
 /// parameters to cope with template friend declarations.
@@ -5300,11 +5311,11 @@
 TypeSpecType == DeclSpec::TST_enum) {
   for (const ParsedAttr  : DS.getAttributes())
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
+<< AL << GetDiagnosticTypeSpecifierIDWithAttrs(TypeSpecType,DS);
   for (const ParsedAttr  : DeclAttrs)
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
-}
+<< AL << GetDiagnosticTypeSpecifierIDWithAttrs(TypeSpecType,DS);
+}
   }
 
   return TagD;
Index: clang/include/clang/Sema/DeclSpec.h
===
--- clang/include/clang/Sema/DeclSpec.h
+++ clang/include/clang/Sema/DeclSpec.h
@@ -271,7 +271,7 @@
 TSC_imaginary,
 TSC_complex
   };
-
+  
   // Import type specifier type enumeration and constants.
   typedef TypeSpecifierType TST;
   static const TST TST_unspecified = clang::TST_unspecified;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3421,7 +3421,7 @@
   InGroup;
 def warn_declspec_attribute_ignored : Warning<
   "attribute %0 is ignored, place it after "
-  "\"%select{class|struct|interface|union|enum}1\" to apply attribute to "
+  "\"%select{class|struct|interface|union|enum|enum class}1\" to apply 
attribute to "
   "type declaration">, InGroup;
 def warn_attribute_precede_definition : Warning<
   "attribute declaration must precede definition">,


Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5043,7 +5043,18 @@
 llvm_unreachable("unexpected type specifier");
   }
 }
-
+static unsigned GetDiagnosticTypeSpecifierIDWithAttrs(DeclSpec::TST T, const DeclSpec ){
+  if (T == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+  return 5;
+}
+  }
+  else{
+return GetDiagnosticTypeSpecifierID(T);
+  }
+  return 0;
+}
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
 /// no declarator (e.g. "struct foo;") is parsed. It also accepts template
 /// parameters to cope with template friend declarations.
@@ -5300,11 +5311,11 @@
 TypeSpecType == DeclSpec::TST_enum) {
   for (const ParsedAttr  : DS.getAttributes())
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
+<< AL << GetDiagnosticTypeSpecifierIDWithAttrs(TypeSpecType,DS);
   for (const ParsedAttr  : DeclAttrs)
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
-}
+<< AL << GetDiagnosticTypeSpecifierIDWithAttrs(TypeSpecType,DS);
+}
   }
 
   return TagD;
Index: clang/include/clang/Sema/DeclSpec.h
===
--- clang/include/clang/Sema/DeclSpec.h
+++ clang/include/clang/Sema/DeclSpec.h
@@ -271,7 +271,7 @@
 TSC_imaginary,
 TSC_complex
   };
-
+  
   // Import type specifier type enumeration and constants.
   typedef TypeSpecifierType TST;
   static const TST TST_unspecified = clang::TST_unspecified;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3421,7 +3421,7 @@
   

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-11 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 updated this revision to Diff 512419.
ipriyanshi1708 added a comment.

Implemented the required changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Sema/SemaDecl.cpp


Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -55,7 +55,6 @@
 
 using namespace clang;
 using namespace sema;
-
 Sema::DeclGroupPtrTy Sema::ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType) {
   if (OwnedType) {
 Decl *Group[2] = { OwnedType, Ptr };
@@ -5043,7 +5042,18 @@
 llvm_unreachable("unexpected type specifier");
   }
 }
-
+static unsigned GetDiagnosticTypeSpecifierIDWithAttrs(DeclSpec::TST T, const 
DeclSpec ){
+  if (T == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+  return 5;
+}
+  }
+  else{
+return GetDiagnosticTypeSpecifierID(T);
+  }
+  return 0;
+}
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
 /// no declarator (e.g. "struct foo;") is parsed. It also accepts template
 /// parameters to cope with template friend declarations.
@@ -5300,11 +5310,11 @@
 TypeSpecType == DeclSpec::TST_enum) {
   for (const ParsedAttr  : DS.getAttributes())
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
+<< AL << GetDiagnosticTypeSpecifierIDWithAttrs(TypeSpecType,DS);
   for (const ParsedAttr  : DeclAttrs)
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
-}
+<< AL << GetDiagnosticTypeSpecifierIDWithAttrs(TypeSpecType,DS);
+}
   }
 
   return TagD;
Index: clang/include/clang/Sema/DeclSpec.h
===
--- clang/include/clang/Sema/DeclSpec.h
+++ clang/include/clang/Sema/DeclSpec.h
@@ -271,7 +271,6 @@
 TSC_imaginary,
 TSC_complex
   };
-
   // Import type specifier type enumeration and constants.
   typedef TypeSpecifierType TST;
   static const TST TST_unspecified = clang::TST_unspecified;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3421,7 +3421,7 @@
   InGroup;
 def warn_declspec_attribute_ignored : Warning<
   "attribute %0 is ignored, place it after "
-  "\"%select{class|struct|interface|union|enum}1\" to apply attribute to "
+  "\"%select{class|struct|interface|union|enum|enum class}1\" to apply 
attribute to "
   "type declaration">, InGroup;
 def warn_attribute_precede_definition : Warning<
   "attribute declaration must precede definition">,


Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -55,7 +55,6 @@
 
 using namespace clang;
 using namespace sema;
-
 Sema::DeclGroupPtrTy Sema::ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType) {
   if (OwnedType) {
 Decl *Group[2] = { OwnedType, Ptr };
@@ -5043,7 +5042,18 @@
 llvm_unreachable("unexpected type specifier");
   }
 }
-
+static unsigned GetDiagnosticTypeSpecifierIDWithAttrs(DeclSpec::TST T, const DeclSpec ){
+  if (T == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+  return 5;
+}
+  }
+  else{
+return GetDiagnosticTypeSpecifierID(T);
+  }
+  return 0;
+}
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
 /// no declarator (e.g. "struct foo;") is parsed. It also accepts template
 /// parameters to cope with template friend declarations.
@@ -5300,11 +5310,11 @@
 TypeSpecType == DeclSpec::TST_enum) {
   for (const ParsedAttr  : DS.getAttributes())
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
+<< AL << GetDiagnosticTypeSpecifierIDWithAttrs(TypeSpecType,DS);
   for (const ParsedAttr  : DeclAttrs)
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
-}
+<< AL << GetDiagnosticTypeSpecifierIDWithAttrs(TypeSpecType,DS);
+}
   }
 
   return TagD;
Index: clang/include/clang/Sema/DeclSpec.h
===
--- clang/include/clang/Sema/DeclSpec.h
+++ clang/include/clang/Sema/DeclSpec.h
@@ -271,7 +271,6 @@
 TSC_imaginary,
 TSC_complex
   };
-
   // 

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-11 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added a comment.

In D147989#4257539 , @samtebbs wrote:

> Looping in some people who have worked on and reviewed patches in this area 
> for some experienced eyes.

Nothing else to add beyond what @aaron.ballman has noted.

Thanks for working on this!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for working on this!

The changes are missing test coverage; please be sure to add that, along with a 
release note about the fix. I think there's likely more work to be done here as 
well, considering this behavior: https://godbolt.org/z/sdK3Gef75 (notice the 
suggested location for the fix-it -- that also needs to be fixed for this)




Comment at: clang/include/clang/Sema/DeclSpec.h:274
   };
-
   // Import type specifier type enumeration and constants.

Spurious whitespace change can be removed.



Comment at: clang/lib/Sema/SemaDecl.cpp:58
 using namespace sema;
-
+bool isEnumClass = false;
 Sema::DeclGroupPtrTy Sema::ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType) {

samtebbs wrote:
> This being global could lead to issues where one overwrites the other. I 
> think a better approach would be to create another version of 
> `GetDiagnosticTypeSpecifierID` that takes the DeclSpec, then this won't be 
> needed.
+1


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-11 Thread Sam Tebbs via Phabricator via cfe-commits
samtebbs added reviewers: mboehme, aaron.ballman.
samtebbs added a comment.

Looping in some people who have worked on and reviewed patches in this area for 
some experienced eyes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-11 Thread Sam Tebbs via Phabricator via cfe-commits
samtebbs added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:58
 using namespace sema;
-
+bool isEnumClass = false;
 Sema::DeclGroupPtrTy Sema::ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType) {

This being global could lead to issues where one overwrites the other. I think 
a better approach would be to create another version of 
`GetDiagnosticTypeSpecifierID` that takes the DeclSpec, then this won't be 
needed.



Comment at: clang/lib/Sema/SemaDecl.cpp:5305-5310
+   if (TypeSpecType == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+isEnumClass = true;
+}
+  }

if you make a new `GetDiagnosticTypeSpecifierID` then you can check these 
conditions in that function instead of there and return 5 if they are all true, 
otherwise return `GetDiagnosticTypeSpecifierID(TypeSpecType)`.



Comment at: clang/lib/Sema/SemaDecl.cpp:5313-5316
 << AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
   for (const ParsedAttr  : DeclAttrs)
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
 << AL << GetDiagnosticTypeSpecifierID(TypeSpecType);

Then use the new `GetDiagnosticTypeSpecifierID` here, passing `DS` instead of 
`TypeSpecType`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-11 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 updated this revision to Diff 512349.
ipriyanshi1708 edited the summary of this revision.
ipriyanshi1708 added a comment.

Updated the summary


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Sema/SemaDecl.cpp


Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -55,7 +55,7 @@
 
 using namespace clang;
 using namespace sema;
-
+bool isEnumClass = false;
 Sema::DeclGroupPtrTy Sema::ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType) {
   if (OwnedType) {
 Decl *Group[2] = { OwnedType, Ptr };
@@ -5028,6 +5028,9 @@
 }
 
 static unsigned GetDiagnosticTypeSpecifierID(DeclSpec::TST T) {
+  if (isEnumClass) {
+return 5;
+  }else{
   switch (T) {
   case DeclSpec::TST_class:
 return 0;
@@ -5042,6 +5045,7 @@
   default:
 llvm_unreachable("unexpected type specifier");
   }
+  }
 }
 
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
@@ -5298,13 +5302,19 @@
 TypeSpecType == DeclSpec::TST_interface ||
 TypeSpecType == DeclSpec::TST_union ||
 TypeSpecType == DeclSpec::TST_enum) {
+   if (TypeSpecType == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+isEnumClass = true;
+}
+  }
   for (const ParsedAttr  : DS.getAttributes())
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
 << AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
   for (const ParsedAttr  : DeclAttrs)
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
 << AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
-}
+}
   }
 
   return TagD;
Index: clang/include/clang/Sema/DeclSpec.h
===
--- clang/include/clang/Sema/DeclSpec.h
+++ clang/include/clang/Sema/DeclSpec.h
@@ -271,7 +271,6 @@
 TSC_imaginary,
 TSC_complex
   };
-
   // Import type specifier type enumeration and constants.
   typedef TypeSpecifierType TST;
   static const TST TST_unspecified = clang::TST_unspecified;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3421,7 +3421,7 @@
   InGroup;
 def warn_declspec_attribute_ignored : Warning<
   "attribute %0 is ignored, place it after "
-  "\"%select{class|struct|interface|union|enum}1\" to apply attribute to "
+  "\"%select{class|struct|interface|union|enum|enum class}1\" to apply 
attribute to "
   "type declaration">, InGroup;
 def warn_attribute_precede_definition : Warning<
   "attribute declaration must precede definition">,


Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -55,7 +55,7 @@
 
 using namespace clang;
 using namespace sema;
-
+bool isEnumClass = false;
 Sema::DeclGroupPtrTy Sema::ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType) {
   if (OwnedType) {
 Decl *Group[2] = { OwnedType, Ptr };
@@ -5028,6 +5028,9 @@
 }
 
 static unsigned GetDiagnosticTypeSpecifierID(DeclSpec::TST T) {
+  if (isEnumClass) {
+return 5;
+  }else{
   switch (T) {
   case DeclSpec::TST_class:
 return 0;
@@ -5042,6 +5045,7 @@
   default:
 llvm_unreachable("unexpected type specifier");
   }
+  }
 }
 
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
@@ -5298,13 +5302,19 @@
 TypeSpecType == DeclSpec::TST_interface ||
 TypeSpecType == DeclSpec::TST_union ||
 TypeSpecType == DeclSpec::TST_enum) {
+   if (TypeSpecType == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+isEnumClass = true;
+}
+  }
   for (const ParsedAttr  : DS.getAttributes())
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
 << AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
   for (const ParsedAttr  : DeclAttrs)
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
 << AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
-}
+}
   }
 
   return TagD;
Index: clang/include/clang/Sema/DeclSpec.h
===
--- clang/include/clang/Sema/DeclSpec.h
+++ clang/include/clang/Sema/DeclSpec.h
@@ -271,7 +271,6 @@
 TSC_imaginary,
 TSC_complex
   };
-
   // Import type specifier type enumeration and constants.
   typedef TypeSpecifierType TST;
   

[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-11 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 updated this revision to Diff 512344.
ipriyanshi1708 retitled this revision from "Fix Attribute Placememt" to 
"[clang] Fix Attribute Placement".
ipriyanshi1708 added a comment.

Updated the title


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Sema/SemaDecl.cpp


Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -55,7 +55,7 @@
 
 using namespace clang;
 using namespace sema;
-
+bool isEnumClass = false;
 Sema::DeclGroupPtrTy Sema::ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType) {
   if (OwnedType) {
 Decl *Group[2] = { OwnedType, Ptr };
@@ -5028,6 +5028,9 @@
 }
 
 static unsigned GetDiagnosticTypeSpecifierID(DeclSpec::TST T) {
+  if (isEnumClass) {
+return 5;
+  }else{
   switch (T) {
   case DeclSpec::TST_class:
 return 0;
@@ -5042,6 +5045,7 @@
   default:
 llvm_unreachable("unexpected type specifier");
   }
+  }
 }
 
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
@@ -5298,13 +5302,19 @@
 TypeSpecType == DeclSpec::TST_interface ||
 TypeSpecType == DeclSpec::TST_union ||
 TypeSpecType == DeclSpec::TST_enum) {
+   if (TypeSpecType == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+isEnumClass = true;
+}
+  }
   for (const ParsedAttr  : DS.getAttributes())
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
 << AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
   for (const ParsedAttr  : DeclAttrs)
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
 << AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
-}
+}
   }
 
   return TagD;
Index: clang/include/clang/Sema/DeclSpec.h
===
--- clang/include/clang/Sema/DeclSpec.h
+++ clang/include/clang/Sema/DeclSpec.h
@@ -271,7 +271,6 @@
 TSC_imaginary,
 TSC_complex
   };
-
   // Import type specifier type enumeration and constants.
   typedef TypeSpecifierType TST;
   static const TST TST_unspecified = clang::TST_unspecified;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3421,7 +3421,7 @@
   InGroup;
 def warn_declspec_attribute_ignored : Warning<
   "attribute %0 is ignored, place it after "
-  "\"%select{class|struct|interface|union|enum}1\" to apply attribute to "
+  "\"%select{class|struct|interface|union|enum|enum class}1\" to apply 
attribute to "
   "type declaration">, InGroup;
 def warn_attribute_precede_definition : Warning<
   "attribute declaration must precede definition">,


Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -55,7 +55,7 @@
 
 using namespace clang;
 using namespace sema;
-
+bool isEnumClass = false;
 Sema::DeclGroupPtrTy Sema::ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType) {
   if (OwnedType) {
 Decl *Group[2] = { OwnedType, Ptr };
@@ -5028,6 +5028,9 @@
 }
 
 static unsigned GetDiagnosticTypeSpecifierID(DeclSpec::TST T) {
+  if (isEnumClass) {
+return 5;
+  }else{
   switch (T) {
   case DeclSpec::TST_class:
 return 0;
@@ -5042,6 +5045,7 @@
   default:
 llvm_unreachable("unexpected type specifier");
   }
+  }
 }
 
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
@@ -5298,13 +5302,19 @@
 TypeSpecType == DeclSpec::TST_interface ||
 TypeSpecType == DeclSpec::TST_union ||
 TypeSpecType == DeclSpec::TST_enum) {
+   if (TypeSpecType == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+isEnumClass = true;
+}
+  }
   for (const ParsedAttr  : DS.getAttributes())
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
 << AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
   for (const ParsedAttr  : DeclAttrs)
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
 << AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
-}
+}
   }
 
   return TagD;
Index: clang/include/clang/Sema/DeclSpec.h
===
--- clang/include/clang/Sema/DeclSpec.h
+++ clang/include/clang/Sema/DeclSpec.h
@@ -271,7 +271,6 @@
 TSC_imaginary,
 TSC_complex
   };
-
   // Import type specifier type enumeration