aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-02-13 22:48:56 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-02-13 22:48:56 +0000
commit186204bfcf9c53d48143ec300d4c3d036fed4140 (patch)
tree8efa74015b1da090a4319470802995db0679eca0
parent1dd467a111794453e4d97af9907cb29ea72c44e5 (diff)
Warn about attribute used ignored on "extern int a
__attribute__((used))". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64499 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDeclAttr.cpp2
-rw-r--r--test/Sema/attr-used.c3
2 files changed, 4 insertions, 1 deletions
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 29f6cb18a0..3ea2b5064c 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -439,7 +439,7 @@ static void HandleUsedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
}
if (const VarDecl *VD = dyn_cast<VarDecl>(d)) {
- if (VD->hasLocalStorage()) {
+ if (VD->hasLocalStorage() || VD->hasExternalStorage()) {
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "used";
return;
}
diff --git a/test/Sema/attr-used.c b/test/Sema/attr-used.c
index 7d0265ef32..10674814ce 100644
--- a/test/Sema/attr-used.c
+++ b/test/Sema/attr-used.c
@@ -1,5 +1,8 @@
// RUN: clang -verify -fsyntax-only %s
+extern int l0 __attribute__((used)); // expected-warning {{used attribute ignored}}
+__private_extern__ int l1 __attribute__((used)); // expected-warning {{used attribute ignored}}
+
struct __attribute__((used)) s { // expected-warning {{'used' attribute only applies to variable and function types}}
int x;
};