Warn on and drop dllimport attrs from variable definitions

AsmPrinter::EmitLinkage() does not handle dllimport linkage.  The LLVM
verifier should also be fixed to reject this.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182320 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/TargetAttributesSema.cpp b/lib/Sema/TargetAttributesSema.cpp
index 2f77012..526399a 100644
--- a/lib/Sema/TargetAttributesSema.cpp
+++ b/lib/Sema/TargetAttributesSema.cpp
@@ -161,6 +161,15 @@
   if (D->hasAttr<DLLImportAttr>())
     return NULL;
 
+  if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
+    if (VD->hasDefinition()) {
+      // dllimport cannot be applied to definitions.
+      Diag(D->getLocation(), diag::warn_attribute_invalid_on_definition)
+        << "dllimport";
+      return NULL;
+    }
+  }
+
   return ::new (Context) DLLImportAttr(Range, Context,
                                        AttrSpellingListIndex);
 }