"inline declaration of %0 not allowed in block scope">;
def err_static_non_static : Error<
"static declaration of %0 follows non-static declaration">;
+def warn_weak_import : Warning <
+ "an already-declared variable is made a weak_import declaration %0">;
def warn_static_non_static : ExtWarn<
"static declaration of %0 follows non-static declaration">;
def err_non_static_static : Error<
}
mergeDeclAttributes(New, Old, Context);
- // weak_import on current declaration is applied to previous
- // tentative definiton.
+ // Warn if an already-declared variable is made a weak_import in a subsequent declaration
if (New->getAttr<WeakImportAttr>() &&
Old->getStorageClass() == SC_None &&
- !Old->getAttr<WeakImportAttr>())
- Old->addAttr(::new (Context) WeakImportAttr(SourceLocation(), Context));
+ !Old->getAttr<WeakImportAttr>()) {
+ Diag(New->getLocation(), diag::warn_weak_import) << New->getDeclName();
+ Diag(Old->getLocation(), diag::note_previous_definition);
+ // Remove weak_import attribute on new declaration.
+ // I am just dropping all attributes in curernt decl. We have
+ // already issued a warning, so we are OK.
+ New->dropAttrs();
+ }
// Merge the types.
MergeVarDeclTypes(New, Old);
// CHECK: @A = global i32
// CHECK-NOT: @B =
-// CHECK: @C = global i32
+// CHECK: @C = common global i32
// CHECK: @D = global i32
// CHECK: @E = global i32
struct __attribute__((weak_import)) s1 {}; // expected-warning {{'weak_import' attribute only applies to variables and functions}}
static int x __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
+
+// rdar://9538608
+int C; // expected-note {{previous definition is here}}
+extern int C __attribute__((weak_import)); // expected-warning {{an already-declared variable is made a weak_import declaration}}