From: Hans Wennborg Date: Wed, 31 Oct 2018 10:34:46 +0000 (+0000) Subject: Follow-up to r345699: Call CheckStaticLocalForDllExport later for templates X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5bd4b03535c115d46ecd089fdf391efd794e67e1;p=clang Follow-up to r345699: Call CheckStaticLocalForDllExport later for templates Calling it too early might cause dllimport to get inherited onto the VarDecl before the initializer got attached. See the test case for an example where this broke things. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@345709 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 1256a6bf5c..4f7ecdfcdf 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -728,9 +728,6 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D, D->getLocation(), D->getIdentifier(), DI->getType(), DI, D->getStorageClass()); - if (Var->isStaticLocal()) - SemaRef.CheckStaticLocalForDllExport(Var); - // In ARC, infer 'retaining' for variables of retainable type. if (SemaRef.getLangOpts().ObjCAutoRefCount && SemaRef.inferObjCARCLifetime(Var)) @@ -751,6 +748,9 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D, Var->setImplicit(D->isImplicit()); + if (Var->isStaticLocal()) + SemaRef.CheckStaticLocalForDllExport(Var); + return Var; } diff --git a/test/CodeGenCXX/dllimport.cpp b/test/CodeGenCXX/dllimport.cpp index 874f119a43..e9f0e4795f 100644 --- a/test/CodeGenCXX/dllimport.cpp +++ b/test/CodeGenCXX/dllimport.cpp @@ -1008,4 +1008,14 @@ template struct T { int foo() { static int x; return x++; } }; extern template struct __declspec(dllimport) T; int bar() { T t; return t.foo(); } // MO1-DAG: @"?x@?{{1|2}}??foo@?$T@H@pr39496@@Q{{[A-Z]*}}HXZ@4HA" = available_externally dllimport global i32 0, align 4 + +template struct __declspec(dllimport) U { + void foo() { + // Don't inherit dllimport to src before attaching the initializer. + static constexpr char src[] = {"hello"}; + T arr[sizeof(src)]; + } +}; +void baz() { U u; u.foo(); } // No diagnostic. + }