r275040 - [CodeGen] Treat imported static local variables as declarations
David Majnemer via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 10 21:28:22 PDT 2016
Author: majnemer
Date: Sun Jul 10 23:28:21 2016
New Revision: 275040
URL: http://llvm.org/viewvc/llvm-project?rev=275040&view=rev
Log:
[CodeGen] Treat imported static local variables as declarations
Imported variables cannot really be definitions for the purposes of
IR generation.
Modified:
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGenCXX/dllimport.cpp
Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=275040&r1=275039&r2=275040&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Sun Jul 10 23:28:21 2016
@@ -323,10 +323,6 @@ CodeGenModule::EmitCXXGlobalVarDeclInitF
D->hasAttr<CUDASharedAttr>()))
return;
- // DLL imported variables will be initialized by the export side.
- if (D->hasAttr<DLLImportAttr>())
- return;
-
// Check if we've already initialized this decl.
auto I = DelayedCXXInitPosition.find(D);
if (I != DelayedCXXInitPosition.end() && I->second == ~0U)
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=275040&r1=275039&r2=275040&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sun Jul 10 23:28:21 2016
@@ -2851,6 +2851,10 @@ static void ReplaceUsesOfNonProtoTypeWit
}
void CodeGenModule::HandleCXXStaticMemberVarInstantiation(VarDecl *VD) {
+ auto DK = VD->isThisDeclarationADefinition();
+ if (DK == VarDecl::Definition && VD->hasAttr<DLLImportAttr>())
+ 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.
Modified: cfe/trunk/test/CodeGenCXX/dllimport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport.cpp?rev=275040&r1=275039&r2=275040&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/dllimport.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllimport.cpp Sun Jul 10 23:28:21 2016
@@ -676,7 +676,7 @@ namespace ClassTemplateStaticDef {
static int x;
};
template <typename T> int S<T>::x;
- // MSC-DAG: @"\01?x@?$S at H@ClassTemplateStaticDef@@2HA" = available_externally dllimport global i32 0
+ // MSC-DAG: @"\01?x@?$S at H@ClassTemplateStaticDef@@2HA" = external dllimport global i32
int f() { return S<int>::x; }
// Partial class template specialization static field:
@@ -685,7 +685,7 @@ namespace ClassTemplateStaticDef {
static int x;
};
template <typename A> int T<A*>::x;
- // GNU-DAG: @_ZN22ClassTemplateStaticDef1TIPvE1xE = available_externally dllimport global i32 0
+ // GNU-DAG: @_ZN22ClassTemplateStaticDef1TIPvE1xE = external dllimport global i32
int g() { return T<void*>::x; }
}
More information about the cfe-commits
mailing list