summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaTemplate.cpp
diff options
context:
space:
mode:
authorMartin Storsjo <martin@martin.st>2019-04-26 08:09:51 +0000
committerMartin Storsjo <martin@martin.st>2019-04-26 08:09:51 +0000
commit5be69bc68a6581897d7fa5068059aa8e723c6ce7 (patch)
treebc7a1b7ace9d742554d2656c863e35e5c5627e8d /clang/lib/Sema/SemaTemplate.cpp
parentc316b22496017c48aba08de1fb69554404bc311b (diff)
downloadbcm5719-llvm-5be69bc68a6581897d7fa5068059aa8e723c6ce7.tar.gz
bcm5719-llvm-5be69bc68a6581897d7fa5068059aa8e723c6ce7.zip
[MinGW] Fix dllexport of explicit template instantiation
Contrary to MSVC, GCC/MinGW needs to have the dllexport attribute on the template instantiation declaration, not on the definition. Previously clang never marked explicit template instantiations as dllexport in MinGW mode, if the instantiation had a previous declaration, regardless of where the attribute was placed. This makes Clang behave like GCC in this regard, and allows using the same attribute form for both MinGW compilers. This fixes PR40256. Differential Revision: https://reviews.llvm.org/D61118 llvm-svn: 359285
Diffstat (limited to 'clang/lib/Sema/SemaTemplate.cpp')
-rw-r--r--clang/lib/Sema/SemaTemplate.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 973911eb840..939941a4c2d 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -8732,8 +8732,10 @@ DeclResult Sema::ActOnExplicitInstantiation(
? TSK_ExplicitInstantiationDefinition
: TSK_ExplicitInstantiationDeclaration;
- if (TSK == TSK_ExplicitInstantiationDeclaration) {
- // Check for dllexport class template instantiation declarations.
+ if (TSK == TSK_ExplicitInstantiationDeclaration &&
+ !Context.getTargetInfo().getTriple().isWindowsGNUEnvironment()) {
+ // Check for dllexport class template instantiation declarations,
+ // except for MinGW mode.
for (const ParsedAttr &AL : Attr) {
if (AL.getKind() == ParsedAttr::AT_DLLExport) {
Diag(ExternLoc,
@@ -8793,6 +8795,19 @@ DeclResult Sema::ActOnExplicitInstantiation(
TemplateSpecializationKind PrevDecl_TSK
= PrevDecl ? PrevDecl->getTemplateSpecializationKind() : TSK_Undeclared;
+ if (TSK == TSK_ExplicitInstantiationDefinition && PrevDecl != nullptr &&
+ Context.getTargetInfo().getTriple().isWindowsGNUEnvironment()) {
+ // Check for dllexport class template instantiation definitions in MinGW
+ // mode, if a previous declaration of the instantiation was seen.
+ for (const ParsedAttr &AL : Attr) {
+ if (AL.getKind() == ParsedAttr::AT_DLLExport) {
+ Diag(AL.getLoc(),
+ diag::warn_attribute_dllexport_explicit_instantiation_def);
+ break;
+ }
+ }
+ }
+
if (CheckExplicitInstantiation(*this, ClassTemplate, TemplateNameLoc,
SS.isSet(), TSK))
return true;
@@ -8949,6 +8964,14 @@ DeclResult Sema::ActOnExplicitInstantiation(
dllExportImportClassTemplateSpecialization(*this, Def);
}
+ // In MinGW mode, export the template instantiation if the declaration
+ // was marked dllexport.
+ if (PrevDecl_TSK == TSK_ExplicitInstantiationDeclaration &&
+ Context.getTargetInfo().getTriple().isWindowsGNUEnvironment() &&
+ PrevDecl->hasAttr<DLLExportAttr>()) {
+ dllExportImportClassTemplateSpecialization(*this, Def);
+ }
+
// Set the template specialization kind. Make sure it is set before
// instantiating the members which will trigger ASTConsumer callbacks.
Specialization->setTemplateSpecializationKind(TSK);
OpenPOWER on IntegriCloud