Issue warning if weak_import attribute is added to an already
declared variable and ignore it. // rdar://9538608

llvm-svn: 133654
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fe3b3b4..daf9f03 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2039,12 +2039,17 @@
   }
   
   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);