From: David Majnemer Date: Mon, 11 Jul 2016 04:28:21 +0000 (+0000) Subject: [CodeGen] Treat imported static local variables as declarations X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8e069d324927a8276de3268d55a55e494462b6eb;p=clang [CodeGen] Treat imported static local variables as declarations Imported variables cannot really be definitions for the purposes of IR generation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275040 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDeclCXX.cpp b/lib/CodeGen/CGDeclCXX.cpp index 8f8ffe66b6..89d142e44b 100644 --- a/lib/CodeGen/CGDeclCXX.cpp +++ b/lib/CodeGen/CGDeclCXX.cpp @@ -323,10 +323,6 @@ CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D, D->hasAttr())) return; - // DLL imported variables will be initialized by the export side. - if (D->hasAttr()) - return; - // Check if we've already initialized this decl. auto I = DelayedCXXInitPosition.find(D); if (I != DelayedCXXInitPosition.end() && I->second == ~0U) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 55b13b4b21..0161cfb611 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -2851,6 +2851,10 @@ static void ReplaceUsesOfNonProtoTypeWithRealFunction(llvm::GlobalValue *Old, } void CodeGenModule::HandleCXXStaticMemberVarInstantiation(VarDecl *VD) { + auto DK = VD->isThisDeclarationADefinition(); + if (DK == VarDecl::Definition && VD->hasAttr()) + return; + TemplateSpecializationKind TSK = VD->getTemplateSpecializationKind(); // If we have a definition, this might be a deferred decl. If the // instantiation is explicit, make sure we emit it at the end. diff --git a/test/CodeGenCXX/dllimport.cpp b/test/CodeGenCXX/dllimport.cpp index 629c2b6c8b..aff240f287 100644 --- a/test/CodeGenCXX/dllimport.cpp +++ b/test/CodeGenCXX/dllimport.cpp @@ -676,7 +676,7 @@ namespace ClassTemplateStaticDef { static int x; }; template int S::x; - // MSC-DAG: @"\01?x@?$S@H@ClassTemplateStaticDef@@2HA" = available_externally dllimport global i32 0 + // MSC-DAG: @"\01?x@?$S@H@ClassTemplateStaticDef@@2HA" = external dllimport global i32 int f() { return S::x; } // Partial class template specialization static field: @@ -685,7 +685,7 @@ namespace ClassTemplateStaticDef { static int x; }; template int T::x; - // GNU-DAG: @_ZN22ClassTemplateStaticDef1TIPvE1xE = available_externally dllimport global i32 0 + // GNU-DAG: @_ZN22ClassTemplateStaticDef1TIPvE1xE = external dllimport global i32 int g() { return T::x; } }