]> granicus.if.org Git - clang/commitdiff
Downgrade error about adding 'dllimport' to used free function to warning (PR24215)
authorHans Wennborg <hans@hanshq.net>
Wed, 22 Jul 2015 23:54:51 +0000 (23:54 +0000)
committerHans Wennborg <hans@hanshq.net>
Wed, 22 Jul 2015 23:54:51 +0000 (23:54 +0000)
The code will still work as it can reference the function via its thunk.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242973 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/dllimport.c

index d25b4dda88525706e43d41bb72e0c7291e17fe39..0eea0e689dc1d1618239154acc59c2772725a56b 100644 (file)
@@ -5368,10 +5368,9 @@ static void checkDLLAttributeRedeclaration(Sema &S, NamedDecl *OldDecl,
   bool AddsAttr = !(OldImportAttr || OldExportAttr) && HasNewAttr;
 
   if (AddsAttr && !IsSpecialization && !OldDecl->isImplicit()) {
-    // If the declaration hasn't been used yet, allow with a warning for
-    // free functions and global variables.
+    // Allow with a warning for free functions and global variables.
     bool JustWarn = false;
-    if (!OldDecl->isUsed() && !OldDecl->isCXXClassMember()) {
+    if (!OldDecl->isCXXClassMember()) {
       auto *VD = dyn_cast<VarDecl>(OldDecl);
       if (VD && !VD->getDescribedVarTemplate())
         JustWarn = true;
@@ -5380,6 +5379,13 @@ static void checkDLLAttributeRedeclaration(Sema &S, NamedDecl *OldDecl,
         JustWarn = true;
     }
 
+    // We cannot change a declaration that's been used because IR has already
+    // been emitted. Dllimported functions will still work though (modulo
+    // address equality) as they can use the thunk.
+    if (OldDecl->isUsed())
+      if (!isa<FunctionDecl>(OldDecl) || !NewImportAttr)
+        JustWarn = false;
+
     unsigned DiagID = JustWarn ? diag::warn_attribute_dll_redeclaration
                                : diag::err_attribute_dll_redeclaration;
     S.Diag(NewDecl->getLocation(), DiagID)
index 3ca1baa299c10b1df8f45290e2ddf80a01b521c8..d81aecd604c7f6a22f0242ffb678e875285a524d 100644 (file)
@@ -143,7 +143,7 @@ __declspec(dllimport) void redecl3(); // expected-note{{previous declaration is
 
                       void redecl4(); // expected-note{{previous declaration is here}}
 void useRedecl4() { redecl4(); }
-__declspec(dllimport) void redecl4(); // expected-error{{redeclaration of 'redecl4' cannot add 'dllimport' attribute}}
+__declspec(dllimport) void redecl4(); // expected-warning{{redeclaration of 'redecl4' should not add 'dllimport' attribute}}
 
 // Allow with a warning if the decl hasn't been used yet.
                       void redecl5(); // expected-note{{previous declaration is here}}