r211137 - Fix bug in code for avoiding dynamic initialization of dllimport globals
Hans Wennborg
hans at hanshq.net
Tue Jun 17 18:21:33 PDT 2014
Author: hans
Date: Tue Jun 17 20:21:33 2014
New Revision: 211137
URL: http://llvm.org/viewvc/llvm-project?rev=211137&view=rev
Log:
Fix bug in code for avoiding dynamic initialization of dllimport globals
When instantiating dllimport variables with dynamic initializers, don't
bail out of Sema::InstantiateVariableInitializer without calling
PopExpressionEvaluationContext().
This was causing a stale object to stay on the ExprEvalContexts stack,
causing subsequent calls to getCurrentMangleNumberContext() to fail,
resulting in incorrect numbering of static locals (and probably other
broken things).
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=211137&r1=211136&r2=211137&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Tue Jun 17 20:21:33 2014
@@ -3688,7 +3688,6 @@ void Sema::InstantiateVariableInitialize
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, InitExpr, DirectInit, TypeMayContainAuto);
Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp?rev=211137&r1=211136&r2=211137&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-static-initializers.cpp Tue Jun 17 20:21:33 2014
@@ -189,6 +189,23 @@ inline void switch_test2() {
switch (1) default: static int x = f();
}
+namespace DynamicDLLImportInitVSMangling {
+ // Failing to pop the ExprEvalContexts when instantiating a dllimport var with
+ // dynamic initializer would cause subsequent static local numberings to be
+ // incorrect.
+ struct NonPOD { NonPOD(); };
+ template <typename T> struct A { static NonPOD x; };
+ template <typename T> NonPOD A<T>::x;
+ template struct __declspec(dllimport) A<int>;
+
+ inline int switch_test3() {
+ // CHECK-LABEL: define linkonce_odr i32 @"\01?switch_test3 at DynamicDLLImportInitVSMangling@@YAHXZ"
+ static int local;
+ // CHECK: @"\01?local@?1??switch_test3 at DynamicDLLImportInitVSMangling@@YAHXZ at 4HA"
+ return local++;
+ }
+}
+
void force_usage() {
UnreachableStatic();
getS();
@@ -197,6 +214,7 @@ void force_usage() {
(void)&T::enum_in_struct;
switch_test(1);
switch_test2();
+ DynamicDLLImportInitVSMangling::switch_test3();
}
// CHECK: define linkonce_odr void @"\01??__Efoo@?$B at H@@2VA@@A at YAXXZ"()
More information about the cfe-commits
mailing list