[PATCH] D97161: Improve diagnostic for ignored GNU 'used' attribute
Fangrui Song via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 22 09:18:36 PST 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbccdf6b232f6: Improve diagnostic for ignored GNU 'used' attribute (authored by MaskRay).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D97161/new/
https://reviews.llvm.org/D97161
Files:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/attr-used.c
clang/test/SemaCXX/attr-used.cpp
Index: clang/test/SemaCXX/attr-used.cpp
===================================================================
--- clang/test/SemaCXX/attr-used.cpp
+++ clang/test/SemaCXX/attr-used.cpp
@@ -1,5 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-extern char test1[] __attribute__((used)); // expected-warning {{'used' attribute ignored}}
-extern const char test2[] __attribute__((used)); // expected-warning {{'used' attribute ignored}}
+extern char test1[] __attribute__((used)); // expected-warning {{'used' attribute ignored on a non-definition declaration}}
+extern const char test2[] __attribute__((used)); // expected-warning {{'used' attribute ignored on a non-definition declaration}}
extern const char test3[] __attribute__((used)) = "";
Index: clang/test/Sema/attr-used.c
===================================================================
--- clang/test/Sema/attr-used.c
+++ clang/test/Sema/attr-used.c
@@ -1,7 +1,7 @@
// RUN: %clang_cc1 -verify -fsyntax-only -Wno-private-extern %s
-extern int l0 __attribute__((used)); // expected-warning {{'used' attribute ignored}}
-__private_extern__ int l1 __attribute__((used)); // expected-warning {{'used' attribute ignored}}
+extern int l0 __attribute__((used)); // expected-warning {{'used' attribute ignored on a non-definition declaration}}
+__private_extern__ int l1 __attribute__((used)); // expected-warning {{'used' attribute ignored on a non-definition declaration}}
struct __attribute__((used)) s { // expected-warning {{'used' attribute only applies to variables with non-local storage, functions, and Objective-C methods}}
int x;
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13295,7 +13295,8 @@
if (UsedAttr *Attr = VD->getAttr<UsedAttr>()) {
if (!Attr->isInherited() && !VD->isThisDeclarationADefinition()) {
- Diag(Attr->getLocation(), diag::warn_attribute_ignored) << Attr;
+ Diag(Attr->getLocation(), diag::warn_attribute_ignored_on_non_definition)
+ << Attr;
VD->dropAttr<UsedAttr>();
}
}
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3159,6 +3159,9 @@
def warn_nothrow_attribute_ignored : Warning<"'nothrow' attribute conflicts with"
" exception specification; attribute ignored">,
InGroup<IgnoredAttributes>;
+def warn_attribute_ignored_on_non_definition :
+ Warning<"%0 attribute ignored on a non-definition declaration">,
+ InGroup<IgnoredAttributes>;
def warn_attribute_ignored_on_inline :
Warning<"%0 attribute ignored on inline function">,
InGroup<IgnoredAttributes>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97161.325469.patch
Type: text/x-patch
Size: 2830 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210222/59d1d3b6/attachment.bin>
More information about the cfe-commits
mailing list