Author: hans
Date: Fri Jan 13 13:11:01 2017
New Revision: 291943

URL: http://llvm.org/viewvc/llvm-project?rev=291943&view=rev
Log:
Merging r291877:
------------------------------------------------------------------------
r291877 | smeenai | 2017-01-12 17:28:34 -0800 (Thu, 12 Jan 2017) | 13 lines

[Sema] Restrict explicit instantation definition dllexport

In the case where the template class itself is already `dllexport`, the
implicit instantiation will have already emitted all members. When we
check the explicit instantiation definition, the `Specialization` will
have inherited the `dllexport` attribute, so we'll attempt to emit all
members for a second time, which causes an assertion failure. Restrict
the exporting to when the `dllexport` attribute is newly introduced by
the explicit instantiation definition.

Fixes PR31608.

Differential Revision: https://reviews.llvm.org/D28590
------------------------------------------------------------------------

Modified:
    cfe/branches/release_40/   (props changed)
    cfe/branches/release_40/lib/Sema/SemaTemplate.cpp
    cfe/branches/release_40/test/CodeGenCXX/dllexport.cpp

Propchange: cfe/branches/release_40/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jan 13 13:11:01 2017
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:291850,291853,291865,291871
+/cfe/trunk:291850,291853,291865,291871,291877
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_40/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/lib/Sema/SemaTemplate.cpp?rev=291943&r1=291942&r2=291943&view=diff
==============================================================================
--- cfe/branches/release_40/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/branches/release_40/lib/Sema/SemaTemplate.cpp Fri Jan 13 13:11:01 2017
@@ -7789,6 +7789,7 @@ Sema::ActOnExplicitInstantiation(Scope *
   Specialization->setTemplateKeywordLoc(TemplateLoc);
   Specialization->setBraceRange(SourceRange());
 
+  bool PreviouslyDLLExported = Specialization->hasAttr<DLLExportAttr>();
   if (Attr)
     ProcessDeclAttributeList(S, Specialization, Attr);
 
@@ -7851,8 +7852,9 @@ Sema::ActOnExplicitInstantiation(Scope *
 
     // Fix a TSK_ImplicitInstantiation followed by a
     // TSK_ExplicitInstantiationDefinition
-    if (Old_TSK == TSK_ImplicitInstantiation &&
-        Specialization->hasAttr<DLLExportAttr>() &&
+    bool NewlyDLLExported =
+        !PreviouslyDLLExported && Specialization->hasAttr<DLLExportAttr>();
+    if (Old_TSK == TSK_ImplicitInstantiation && NewlyDLLExported &&
         (Context.getTargetInfo().getCXXABI().isMicrosoft() ||
          Context.getTargetInfo().getTriple().isWindowsItaniumEnvironment())) {
       // In the MS ABI, an explicit instantiation definition can add a dll

Modified: cfe/branches/release_40/test/CodeGenCXX/dllexport.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/branches/release_40/test/CodeGenCXX/dllexport.cpp?rev=291943&r1=291942&r2=291943&view=diff
==============================================================================
--- cfe/branches/release_40/test/CodeGenCXX/dllexport.cpp (original)
+++ cfe/branches/release_40/test/CodeGenCXX/dllexport.cpp Fri Jan 13 13:11:01 
2017
@@ -732,13 +732,27 @@ USEMEMFUNC(ExplicitInstantiationDeclExpo
 // M32-DAG: define weak_odr dllexport x86_thiscallcc 
%struct.ExplicitInstantiationDeclExportedDefTemplate* 
@"\01??0?$ExplicitInstantiationDeclExportedDefTemplate@H@@QAE@XZ"
 // G32-DAG: define weak_odr x86_thiscallcc void 
@_ZN44ExplicitInstantiationDeclExportedDefTemplateIiE1fEv
 
-template <typename T> struct 
ImplicitInstantiationExplicitInstantiationDefExportedTemplate { void f() {} };
+template <typename T> struct 
ImplicitInstantiationExportedExplicitInstantiationDefTemplate { virtual void 
f() {} };
+ImplicitInstantiationExportedExplicitInstantiationDefTemplate<int> 
ImplicitInstantiationExportedExplicitInstantiationDefTemplateInstance;
+template struct __declspec(dllexport) 
ImplicitInstantiationExportedExplicitInstantiationDefTemplate<int>;
+USEMEMFUNC(ImplicitInstantiationExportedExplicitInstantiationDefTemplate<int>, 
f);
+// M32-DAG: define weak_odr dllexport x86_thiscallcc void 
@"\01?f@?$ImplicitInstantiationExportedExplicitInstantiationDefTemplate@H@@UAEXXZ"
+// G32-DAG: define weak_odr x86_thiscallcc void 
@_ZN61ImplicitInstantiationExportedExplicitInstantiationDefTemplateIiE1fEv
+
+template <typename T> struct __declspec(dllexport) 
ImplicitInstantiationExplicitInstantiationDefExportedTemplate { virtual void 
f() {} };
 ImplicitInstantiationExplicitInstantiationDefExportedTemplate<int> 
ImplicitInstantiationExplicitInstantiationDefExportedTemplateInstance;
-template class __declspec(dllexport) 
ImplicitInstantiationExplicitInstantiationDefExportedTemplate<int>;
+template struct 
ImplicitInstantiationExplicitInstantiationDefExportedTemplate<int>;
 USEMEMFUNC(ImplicitInstantiationExplicitInstantiationDefExportedTemplate<int>, 
f);
-// M32-DAG: define weak_odr dllexport x86_thiscallcc void 
@"\01?f@?$ImplicitInstantiationExplicitInstantiationDefExportedTemplate@H@@QAEXXZ"
+// M32-DAG: define weak_odr dllexport x86_thiscallcc void 
@"\01?f@?$ImplicitInstantiationExplicitInstantiationDefExportedTemplate@H@@UAEXXZ"
 // G32-DAG: define weak_odr x86_thiscallcc void 
@_ZN61ImplicitInstantiationExplicitInstantiationDefExportedTemplateIiE1fEv
 
+template <typename T> struct __declspec(dllexport) 
ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplate { virtual 
void f() {} };
+ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplate<int> 
ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplateInstance;
+template struct __declspec(dllexport) 
ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplate<int>;
+USEMEMFUNC(ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplate<int>,
 f);
+// M32-DAG: define weak_odr dllexport x86_thiscallcc void 
@"\01?f@?$ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplate@H@@UAEXXZ"
+// G32-DAG: define weak_odr x86_thiscallcc void 
@_ZN69ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplateIiE1fEv
+
 namespace { struct InternalLinkageType {}; }
 struct __declspec(dllexport) PR23308 {
   void f(InternalLinkageType*);


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

Reply via email to