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"))) __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,10 +5313,10 @@
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);
}
}
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
^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits