summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp2
-rw-r--r--clang/test/Sema/attr-used.c3
2 files changed, 4 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 29f6cb18a07..3ea2b5064c4 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/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/clang/test/Sema/attr-used.c b/clang/test/Sema/attr-used.c
index 7d0265ef323..10674814ce2 100644
--- a/clang/test/Sema/attr-used.c
+++ b/clang/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;
};
OpenPOWER on IntegriCloud