diff options
| author | Hans Wennborg <hans@hanshq.net> | 2016-05-25 20:16:43 +0000 |
|---|---|---|
| committer | Hans Wennborg <hans@hanshq.net> | 2016-05-25 20:16:43 +0000 |
| commit | 12e3bde64ba7686996701489f3b07b3b5ae04cbf (patch) | |
| tree | a138a2eafa51c619725b11a20e0a8bafd82df068 /clang/lib/Sema | |
| parent | 0a6b95a60adc64999027539bb9f70fab799b8933 (diff) | |
| download | bcm5719-llvm-12e3bde64ba7686996701489f3b07b3b5ae04cbf.tar.gz bcm5719-llvm-12e3bde64ba7686996701489f3b07b3b5ae04cbf.zip | |
clang-cl: Treat dllimport explicit template instantiation definitions as declarations (PR27810, PR27811)
This matches what MSVC does, and should make compiles faster by avoiding to
unnecessarily emit a lot of code.
Differential Revision: http://reviews.llvm.org/D20608
llvm-svn: 270748
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 59e984dd93e..73b5c44b599 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -7367,6 +7367,29 @@ Sema::ActOnExplicitInstantiation(Scope *S, } } + // In MSVC mode, dllimported explicit instantiation definitions are treated as + // instantiation declarations for most purposes. + bool DLLImportExplicitInstantiationDef = false; + if (TSK == TSK_ExplicitInstantiationDefinition && + Context.getTargetInfo().getCXXABI().isMicrosoft()) { + // Check for dllimport class template instantiation definitions. + bool DLLImport = + ClassTemplate->getTemplatedDecl()->getAttr<DLLImportAttr>(); + for (AttributeList *A = Attr; A; A = A->getNext()) { + if (A->getKind() == AttributeList::AT_DLLImport) + DLLImport = true; + if (A->getKind() == AttributeList::AT_DLLExport) { + // dllexport trumps dllimport here. + DLLImport = false; + break; + } + } + if (DLLImport) { + TSK = TSK_ExplicitInstantiationDeclaration; + DLLImportExplicitInstantiationDef = true; + } + } + // Translate the parser's template argument list in our AST format. TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc); translateTemplateArguments(TemplateArgsIn, TemplateArgs); @@ -7420,6 +7443,12 @@ Sema::ActOnExplicitInstantiation(Scope *S, Specialization->setLocation(TemplateNameLoc); PrevDecl = nullptr; } + + if (PrevDecl_TSK == TSK_ExplicitInstantiationDeclaration && + DLLImportExplicitInstantiationDef) { + // The new specialization might add a dllimport attribute. + HasNoEffect = false; + } } if (!Specialization) { @@ -7497,11 +7526,11 @@ Sema::ActOnExplicitInstantiation(Scope *S, Specialization->getDefinition()); if (Def) { TemplateSpecializationKind Old_TSK = Def->getTemplateSpecializationKind(); - // Fix a TSK_ExplicitInstantiationDeclaration followed by a // TSK_ExplicitInstantiationDefinition if (Old_TSK == TSK_ExplicitInstantiationDeclaration && - TSK == TSK_ExplicitInstantiationDefinition) { + (TSK == TSK_ExplicitInstantiationDefinition || + DLLImportExplicitInstantiationDef)) { // FIXME: Need to notify the ASTMutationListener that we did this. Def->setTemplateSpecializationKind(TSK); |

