Before this patch we would warn and drop the attribute in
extern const char test3[] __attribute__((used)) = "";
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188588
91177308-0d34-0410-b5e6-
96231b3b80d8
if (!VD)
return;
+ if (UsedAttr *Attr = VD->getAttr<UsedAttr>()) {
+ if (!Attr->isInherited() && !VD->isThisDeclarationADefinition()) {
+ Diag(Attr->getLocation(), diag::warn_attribute_ignored) << "used";
+ VD->dropAttr<UsedAttr>();
+ }
+ }
+
const DeclContext *DC = VD->getDeclContext();
// If there's a #pragma GCC visibility in scope, and this isn't a class
// member, set the visibility of this variable.
}
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
- if (VD->hasLocalStorage() || VD->hasExternalStorage()) {
+ if (VD->hasLocalStorage()) {
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "used";
return;
}
--- /dev/null
+// 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 const char test3[] __attribute__((used)) = "";