r214425 - Local extern redeclarations of dllimport variables stay dllimport even if they don't specify the attribute

Hans Wennborg hans at hanshq.net
Thu Jul 31 12:29:40 PDT 2014


Author: hans
Date: Thu Jul 31 14:29:39 2014
New Revision: 214425

URL: http://llvm.org/viewvc/llvm-project?rev=214425&view=rev
Log:
Local extern redeclarations of dllimport variables stay dllimport even if they don't specify the attribute

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CodeGen/dllimport.c
    cfe/trunk/test/Sema/dllimport.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=214425&r1=214424&r2=214425&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jul 31 14:29:39 2014
@@ -5047,7 +5047,7 @@ static void checkDLLAttributeRedeclarati
   }
 
   // A redeclaration is not allowed to drop a dllimport attribute, the only
-  // exception being inline function definitions.
+  // exceptions being inline function definitions and local extern declarations.
   // NB: MSVC converts such a declaration to dllexport.
   bool IsInline = false, IsStaticDataMember = false;
   if (const auto *VD = dyn_cast<VarDecl>(NewDecl))
@@ -5057,7 +5057,8 @@ static void checkDLLAttributeRedeclarati
   else if (const auto *FD = dyn_cast<FunctionDecl>(NewDecl))
     IsInline = FD->isInlined();
 
-  if (OldImportAttr && !HasNewAttr && !IsInline && !IsStaticDataMember) {
+  if (OldImportAttr && !HasNewAttr && !IsInline && !IsStaticDataMember &&
+      !NewDecl->isLocalExternDecl()) {
     S.Diag(NewDecl->getLocation(),
            diag::warn_redeclaration_without_attribute_prev_attribute_ignored)
       << NewDecl << OldImportAttr;

Modified: cfe/trunk/test/CodeGen/dllimport.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/dllimport.c?rev=214425&r1=214424&r2=214425&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/dllimport.c (original)
+++ cfe/trunk/test/CodeGen/dllimport.c Thu Jul 31 14:29:39 2014
@@ -44,6 +44,14 @@ __declspec(dllimport) extern int GlobalR
                       extern int GlobalRedecl3; // dllimport ignored
 USEVAR(GlobalRedecl3)
 
+// Redeclaration in local context.
+// CHECK: @GlobalRedecl4 = external dllimport global i32
+__declspec(dllimport) int GlobalRedecl4;
+int functionScope() {
+  extern int GlobalRedecl4; // still dllimport
+  return GlobalRedecl4;
+}
+
 
 
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/test/Sema/dllimport.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/dllimport.c?rev=214425&r1=214424&r2=214425&view=diff
==============================================================================
--- cfe/trunk/test/Sema/dllimport.c (original)
+++ cfe/trunk/test/Sema/dllimport.c Thu Jul 31 14:29:39 2014
@@ -74,6 +74,7 @@ __declspec(dllimport) static int StaticG
 __declspec(dllimport) float LocalRedecl1; // expected-note{{previous definition is here}}
 __declspec(dllimport) float LocalRedecl2; // expected-note{{previous definition is here}}
 __declspec(dllimport) float LocalRedecl3; // expected-note{{previous definition is here}}
+__declspec(dllimport) float LocalRedecl4;
 void functionScope() {
   __declspec(dllimport) int LocalRedecl1; // expected-error{{redefinition of 'LocalRedecl1' with a different type: 'int' vs 'float'}}
   int *__attribute__((dllimport)) LocalRedecl2; // expected-error{{redefinition of 'LocalRedecl2' with a different type: 'int *' vs 'float'}}
@@ -84,6 +85,9 @@ void functionScope() {
   __declspec(dllimport) extern int ExternLocalVarDecl;
   __declspec(dllimport) extern int ExternLocalVarDef = 1; // expected-error{{definition of dllimport data}}
   __declspec(dllimport) static int StaticLocalVar; // expected-error{{'StaticLocalVar' must have external linkage when declared 'dllimport'}}
+
+  // Local extern redeclaration does not drop the attribute.
+  extern float LocalRedecl4;
 }
 
 





More information about the cfe-commits mailing list