r210505 - Improve checking for dynamic initializers of dllimport fields in template instantiation
Hans Wennborg
hans at hanshq.net
Mon Jun 9 17:55:52 PDT 2014
Author: hans
Date: Mon Jun 9 19:55:51 2014
New Revision: 210505
URL: http://llvm.org/viewvc/llvm-project?rev=210505&view=rev
Log:
Improve checking for dynamic initializers of dllimport fields in template instantiation
We would previously assert if the initializer was dependent. I also think that
checking isConstantInitializer is more correct here than checkInitIsICE.
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/CodeGenCXX/dllimport.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=210505&r1=210504&r2=210505&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon Jun 9 19:55:51 2014
@@ -3671,12 +3671,6 @@ void Sema::InstantiateVariableInitialize
// 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);
@@ -3689,9 +3683,15 @@ void Sema::InstantiateVariableInitialize
OldVar->getInitStyle() == VarDecl::CallInit);
if (!Init.isInvalid()) {
bool TypeMayContainAuto = true;
- if (Init.get()) {
+ Expr *InitExpr = Init.get();
+
+ if (Var->hasAttr<DLLImportAttr>() && InitExpr &&
+ !InitExpr->isConstantInitializer(getASTContext(), false)) {
+ // Do not dynamically initialize dllimport variables.
+ return;
+ } else if (InitExpr) {
bool DirectInit = OldVar->isDirectInit();
- AddInitializerToDecl(Var, Init.get(), DirectInit, TypeMayContainAuto);
+ AddInitializerToDecl(Var, InitExpr, DirectInit, TypeMayContainAuto);
} else
ActOnUninitializedDecl(Var, TypeMayContainAuto);
} else {
Modified: cfe/trunk/test/CodeGenCXX/dllimport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport.cpp?rev=210505&r1=210504&r2=210505&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/dllimport.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllimport.cpp Mon Jun 9 19:55:51 2014
@@ -621,4 +621,11 @@ namespace PR19933 {
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
+
+ template <int I> struct D { static int x, y; };
+ template <int I> int D<I>::x = I + 1;
+ template <int I> int D<I>::y = I + f();
+ template struct __declspec(dllimport) D<42>;
+ // MSC-DAG: @"\01?x@?$D@$0CK@@PR19933@@2HA" = available_externally dllimport global i32 43
+ // MSC-DAG: @"\01?y@?$D@$0CK@@PR19933@@2HA" = available_externally dllimport global i32 0
}
More information about the cfe-commits
mailing list