Author: hans
Date: Wed Oct 31 03:34:46 2018
New Revision: 345709

URL: http://llvm.org/viewvc/llvm-project?rev=345709&view=rev
Log:
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.

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=345709&r1=345708&r2=345709&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Oct 31 03:34:46 2018
@@ -728,9 +728,6 @@ Decl *TemplateDeclInstantiator::VisitVar
                           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::VisitVar
 
   Var->setImplicit(D->isImplicit());
 
+  if (Var->isStaticLocal())
+    SemaRef.CheckStaticLocalForDllExport(Var);
+
   return Var;
 }
 

Modified: cfe/trunk/test/CodeGenCXX/dllimport.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport.cpp?rev=345709&r1=345708&r2=345709&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/dllimport.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllimport.cpp Wed Oct 31 03:34:46 2018
@@ -1008,4 +1008,14 @@ template <typename> struct T { int foo()
 extern template struct __declspec(dllimport) T<int>;
 int bar() { T<int> 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 <typename T> 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<int> u; u.foo(); } // No diagnostic.
+
 }


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to