diff options
author | Hans Wennborg <hans@hanshq.net> | 2017-11-29 23:44:11 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2017-11-29 23:44:11 +0000 |
commit | b8304a6aed5291b15ff9e22118bafb2d8c2de794 (patch) | |
tree | 28a2455450abbfdcff165e91746b144a48ded2f7 | |
parent | e10568364e880ecb54111aba41b653bdf6b59609 (diff) | |
download | bcm5719-llvm-b8304a6aed5291b15ff9e22118bafb2d8c2de794.tar.gz bcm5719-llvm-b8304a6aed5291b15ff9e22118bafb2d8c2de794.zip |
MS ABI: Treat explicit instantiation definitions of dllimport function templates as explicit instantiation decls (PR35435)
This matches MSVC's behaviour, and we already do it for class templates
since r270897.
Differential revision: https://reviews.llvm.org/D40621
llvm-svn: 319386
-rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 10 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/dllimport.cpp | 11 |
2 files changed, 19 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 26b80f11fb4..e110a8cc814 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -9239,10 +9239,18 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S, return (Decl*) nullptr; } - Specialization->setTemplateSpecializationKind(TSK, D.getIdentifierLoc()); if (Attr) ProcessDeclAttributeList(S, Specialization, Attr); + // In MSVC mode, dllimported explicit instantiation definitions are treated as + // instantiation declarations. + if (TSK == TSK_ExplicitInstantiationDefinition && + Specialization->hasAttr<DLLImportAttr>() && + Context.getTargetInfo().getCXXABI().isMicrosoft()) + TSK = TSK_ExplicitInstantiationDeclaration; + + Specialization->setTemplateSpecializationKind(TSK, D.getIdentifierLoc()); + if (Specialization->isDefined()) { // Let the ASTConsumer know that this function has been explicitly // instantiated now, and its linkage might have changed. diff --git a/clang/test/CodeGenCXX/dllimport.cpp b/clang/test/CodeGenCXX/dllimport.cpp index 372a96ba2ef..14558aec39a 100644 --- a/clang/test/CodeGenCXX/dllimport.cpp +++ b/clang/test/CodeGenCXX/dllimport.cpp @@ -579,7 +579,7 @@ USE(inlineFuncTmpl<ExplicitDecl_Imported>) // MSC-DAG: declare dllimport void @"\01??$inlineFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"() // GNU-DAG: declare dllimport void @_Z8funcTmplI21ExplicitInst_ImportedEvv() // GNU-DAG: define weak_odr void @_Z14inlineFuncTmplI21ExplicitInst_ImportedEvv() -// MO1-DAG: define available_externally dllimport void @"\01??$funcTmpl@UExplicitInst_Imported@@@@YAXXZ"() +// MO1-DAG: declare dllimport void @"\01??$funcTmpl@UExplicitInst_Imported@@@@YAXXZ"() // MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"() // GO1-DAG: define available_externally dllimport void @_Z8funcTmplI21ExplicitInst_ImportedEvv() // GO1-DAG: define weak_odr void @_Z14inlineFuncTmplI21ExplicitInst_ImportedEvv() @@ -609,6 +609,15 @@ USE(funcTmpl<ExplicitSpec_Imported>) template<> __declspec(dllimport) inline void funcTmpl<ExplicitSpec_InlineDef_Imported>() {} USE(funcTmpl<ExplicitSpec_InlineDef_Imported>) +#ifdef MSABI +namespace pr35435 { +struct X; +template <typename T> struct __declspec(dllimport) S { + void foo(T *t) { t->problem(); } +}; +template void S<X>::foo(X*); // Cannot be instantiated because X is incomplete; dllimport means it's treated as an instantiation decl. +} +#endif //===----------------------------------------------------------------------===// |