]> granicus.if.org Git - clang/commitdiff
Warn on and drop dllimport attrs from variable definitions
authorReid Kleckner <reid@kleckner.net>
Mon, 20 May 2013 21:53:29 +0000 (21:53 +0000)
committerReid Kleckner <reid@kleckner.net>
Mon, 20 May 2013 21:53:29 +0000 (21:53 +0000)
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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclAttr.cpp
lib/Sema/TargetAttributesSema.cpp
test/Sema/dllimport-dllexport.c

index f1a179c259c8a2bf7fb6a99793b576e183ab0ccd..f52d1f3162bc4d2d6018839d5c8283d9c9a6e6c9 100644 (file)
@@ -1957,8 +1957,8 @@ def err_attribute_weak_static : Error<
   "weak declaration cannot have internal linkage">;
 def err_attribute_selectany_non_extern_data : Error<
   "'selectany' can only be applied to data items with external linkage">;
-def warn_attribute_weak_import_invalid_on_definition : Warning<
-  "'weak_import' attribute cannot be specified on a definition">,
+def warn_attribute_invalid_on_definition : Warning<
+  "'%0' attribute cannot be specified on a definition">,
   InGroup<IgnoredAttributes>;
 def err_attribute_weakref_not_static : Error<
   "weakref declaration must have internal linkage">;
index 627bc3d364953a585635beac2f682b2387998b45..be4bd0e3b78c92ac125361f9f7140152b56c2eaf 100644 (file)
@@ -2725,9 +2725,8 @@ static void handleWeakImportAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   bool isDef = false;
   if (!D->canBeWeakImported(isDef)) {
     if (isDef)
-      S.Diag(Attr.getLoc(),
-             diag::warn_attribute_weak_import_invalid_on_definition)
-        << "weak_import" << 2 /*variable and function*/;
+      S.Diag(Attr.getLoc(), diag::warn_attribute_invalid_on_definition)
+        << "weak_import";
     else if (isa<ObjCPropertyDecl>(D) || isa<ObjCMethodDecl>(D) ||
              (S.Context.getTargetInfo().getTriple().isOSDarwin() &&
               (isa<ObjCInterfaceDecl>(D) || isa<EnumDecl>(D)))) {
index 2f7701227da649f552cf3c49f24de81f6a66e470..526399a27830128fea6fa6c0fa01479379ea0d06 100644 (file)
@@ -161,6 +161,15 @@ DLLImportAttr *Sema::mergeDLLImportAttr(Decl *D, SourceRange Range,
   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);
 }
index 00c9df594b6f0429e6ceaa5e8087a62d8fc8e54b..80810d696e8c9f53ec6918822e79a5d710b20f6a 100644 (file)
@@ -41,3 +41,8 @@ void __attribute__((dllexport)) foo13();
 
 extern int foo14 __attribute__((dllexport));
 extern int foo14 __attribute__((dllimport));  // expected-warning{{dllimport attribute ignored}}
+
+__declspec(dllimport) int foo15 = 54; // expected-warning{{'dllimport' attribute cannot be specified on a definition}}
+
+extern __declspec(dllimport) int foo17;
+int foo17 = 54; // expected-warning{{'dllimport' attribute cannot be specified on a definition}}