Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 2848f56

Browse files
committed
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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@319386 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 1da00dd commit 2848f56

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/Sema/SemaTemplate.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -9239,10 +9239,18 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
92399239
return (Decl*) nullptr;
92409240
}
92419241

9242-
Specialization->setTemplateSpecializationKind(TSK, D.getIdentifierLoc());
92439242
if (Attr)
92449243
ProcessDeclAttributeList(S, Specialization, Attr);
92459244

9245+
// In MSVC mode, dllimported explicit instantiation definitions are treated as
9246+
// instantiation declarations.
9247+
if (TSK == TSK_ExplicitInstantiationDefinition &&
9248+
Specialization->hasAttr<DLLImportAttr>() &&
9249+
Context.getTargetInfo().getCXXABI().isMicrosoft())
9250+
TSK = TSK_ExplicitInstantiationDeclaration;
9251+
9252+
Specialization->setTemplateSpecializationKind(TSK, D.getIdentifierLoc());
9253+
92469254
if (Specialization->isDefined()) {
92479255
// Let the ASTConsumer know that this function has been explicitly
92489256
// instantiated now, and its linkage might have changed.

test/CodeGenCXX/dllimport.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ USE(inlineFuncTmpl<ExplicitDecl_Imported>)
579579
// MSC-DAG: declare dllimport void @"\01??$inlineFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"()
580580
// GNU-DAG: declare dllimport void @_Z8funcTmplI21ExplicitInst_ImportedEvv()
581581
// GNU-DAG: define weak_odr void @_Z14inlineFuncTmplI21ExplicitInst_ImportedEvv()
582-
// MO1-DAG: define available_externally dllimport void @"\01??$funcTmpl@UExplicitInst_Imported@@@@YAXXZ"()
582+
// MO1-DAG: declare dllimport void @"\01??$funcTmpl@UExplicitInst_Imported@@@@YAXXZ"()
583583
// MO1-DAG: define available_externally dllimport void @"\01??$inlineFuncTmpl@UExplicitInst_Imported@@@@YAXXZ"()
584584
// GO1-DAG: define available_externally dllimport void @_Z8funcTmplI21ExplicitInst_ImportedEvv()
585585
// GO1-DAG: define weak_odr void @_Z14inlineFuncTmplI21ExplicitInst_ImportedEvv()
@@ -609,6 +609,15 @@ USE(funcTmpl<ExplicitSpec_Imported>)
609609
template<> __declspec(dllimport) inline void funcTmpl<ExplicitSpec_InlineDef_Imported>() {}
610610
USE(funcTmpl<ExplicitSpec_InlineDef_Imported>)
611611

612+
#ifdef MSABI
613+
namespace pr35435 {
614+
struct X;
615+
template <typename T> struct __declspec(dllimport) S {
616+
void foo(T *t) { t->problem(); }
617+
};
618+
template void S<X>::foo(X*); // Cannot be instantiated because X is incomplete; dllimport means it's treated as an instantiation decl.
619+
}
620+
#endif
612621

613622

614623
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)