The export side is responsible for running any initializers, they are
run when the module is first loaded. Attempting to run an initializer
for the import side is not possible.
This fixes PR28216.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@273237
91177308-0d34-0410-b5e6-
96231b3b80d8
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)
--- /dev/null
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -fms-extensions -emit-llvm -o - | FileCheck %s
+
+template <typename>
+struct __declspec(dllimport) S {
+ S();
+};
+
+template <typename T>
+struct __declspec(dllimport) U {
+ static S<T> u;
+};
+
+template <typename T>
+S<T> U<T>::u;
+
+template S<int> U<int>::u;
+// CHECK-NOT: define internal void @"\01??__Eu@?$U@H@@2U?$S@H@@A@YAXXZ"(
+
+S<int> &i = U<int>::u;