[PATCH] D147989: [clang] Fix Attribute Placement

Priyanshi Agarwal via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 14 05:09:57 PDT 2023


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 &DS){
+  if (DS.getTypeSpecType() == DeclSpec::TST_enum) {
+    if (const EnumDecl *ED = dyn_cast<EnumDecl>(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 &AL : DS.getAttributes())
         Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-            << AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
+            << AL << GetDiagnosticTypeSpecifierID(DS);
       for (const ParsedAttr &AL : 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<DeprecatedAttributes>;
 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<IgnoredAttributes>;
 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 <https://github.com/llvm/llvm-project/issues/61660>`_)
 
 Bug Fixes to C++ Support
 ^^^^^^^^^^^^^^^^^^^^^^^^


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147989.513549.patch
Type: text/x-patch
Size: 3317 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230414/4d24c811/attachment.bin>


More information about the cfe-commits mailing list