[PATCH] Don't dynamically initialize dllimport vars (PR19933)
Hans Wennborg
hans at chromium.org
Wed Jun 4 14:17:43 PDT 2014
Closed by commit rL210217 (authored by @hans).
http://reviews.llvm.org/D4020
Files:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/CodeGenCXX/dllimport.cpp
Index: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3671,6 +3671,12 @@
// We already have an initializer in the class.
return;
+ if (Var->hasAttr<DLLImportAttr>() &&
+ !(OldVar->getInit() && OldVar->checkInitIsICE())) {
+ // Do not dynamically initialize dllimport variables.
+ return;
+ }
+
if (OldVar->getInit()) {
if (Var->isStaticDataMember() && !OldVar->isOutOfLine())
PushExpressionEvaluationContext(Sema::ConstantEvaluated, OldVar);
Index: cfe/trunk/test/CodeGenCXX/dllimport.cpp
===================================================================
--- cfe/trunk/test/CodeGenCXX/dllimport.cpp
+++ cfe/trunk/test/CodeGenCXX/dllimport.cpp
@@ -5,6 +5,10 @@
// RUN: %clang_cc1 -triple i686-windows-msvc -fno-rtti -emit-llvm -std=c++1y -O1 -o - %s -DMSABI | FileCheck --check-prefix=MO1 %s
// RUN: %clang_cc1 -triple i686-windows-gnu -fno-rtti -emit-llvm -std=c++1y -O1 -o - %s | FileCheck --check-prefix=GO1 %s
+// CHECK-NOT doesn't play nice with CHECK-DAG, so use separate run lines.
+// RUN: %clang_cc1 -triple i686-windows-msvc -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s -DMSABI | FileCheck --check-prefix=MSC2 %s
+// RUN: %clang_cc1 -triple i686-windows-gnu -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s | FileCheck --check-prefix=GNU2 %s
+
// Helper structs to make templates more expressive.
struct ImplicitInst_Imported {};
struct ImplicitInst_NotImported {};
@@ -219,6 +223,11 @@
__declspec(dllimport) __attribute__((noinline)) inline void noinline() {}
USE(noinline)
+// MSC2-NOT: @"\01?alwaysInline@@YAXXZ"()
+// GNU2-NOT: @_Z12alwaysInlinev()
+__declspec(dllimport) __attribute__((always_inline)) inline void alwaysInline() {}
+USE(alwaysInline)
+
// Redeclarations
// MSC-DAG: declare dllimport void @"\01?redecl1@@YAXXZ"()
// GNU-DAG: declare dllimport void @_Z7redecl1v()
@@ -580,13 +589,26 @@
int f() { return S<int>::x; }
}
-//===----------------------------------------------------------------------===//
-// Negative checks
-//===----------------------------------------------------------------------===//
-
-// These checks are at the end to avoid interference with the DAG checks.
-
-// MSC-NOT: @"\01?alwaysInline@@YAXXZ"()
-// GNU-NOT: @_Z12alwaysInlinev()
-__declspec(dllimport) __attribute__((always_inline)) inline void alwaysInline() {}
-USE(alwaysInline)
+namespace PR19933 {
+// Don't dynamically initialize dllimport vars.
+// MSC2-NOT: @llvm.global_ctors
+// GNU2-NOT: @llvm.global_ctors
+
+ struct NonPOD { NonPOD(); };
+ template <typename T> struct A { static NonPOD x; };
+ template <typename T> NonPOD A<T>::x;
+ template struct __declspec(dllimport) A<int>;
+ // MSC-DAG: @"\01?x@?$A at H@PR19933@@2UNonPOD at 2@A" = available_externally dllimport global %"struct.PR19933::NonPOD" zeroinitializer
+
+ int f();
+ template <typename T> struct B { static int x; };
+ template <typename T> int B<T>::x = f();
+ template struct __declspec(dllimport) B<int>;
+ // MSC-DAG: @"\01?x@?$B at H@PR19933@@2HA" = available_externally dllimport global i32 0
+
+ constexpr int g() { return 42; }
+ template <typename T> struct C { static int x; };
+ template <typename T> int C<T>::x = g();
+ template struct __declspec(dllimport) C<int>;
+ // MSC-DAG: @"\01?x@?$C at H@PR19933@@2HA" = available_externally dllimport global i32 42
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4020.10106.patch
Type: text/x-patch
Size: 3534 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140604/0c6dba62/attachment.bin>
More information about the cfe-commits
mailing list