Skip to content

Commit 05861b3

Browse files
authored
[C++20] [Modules] Make sure vtable are generated for explicit template instantiation definition (llvm#123871)
Close llvm#123719 The reason is, we thought the external explicit template instantiation declaration as the external definition incorrectly.
1 parent 582fe3e commit 05861b3

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

clang/lib/Serialization/ASTWriter.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -7198,6 +7198,8 @@ void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) {
71987198

71997199
bool ModulesCodegen =
72007200
!D->isDependentType() &&
7201+
D->getTemplateSpecializationKind() !=
7202+
TSK_ExplicitInstantiationDeclaration &&
72017203
(Writer->getLangOpts().ModulesDebugInfo || D->isInNamedModule());
72027204
Record->push_back(ModulesCodegen);
72037205
if (ModulesCodegen)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir %t
3+
// RUN: split-file %s %t
4+
5+
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -triple %itanium_abi_triple -emit-module-interface -o %t/a.pcm
6+
// RUN: %clang_cc1 -std=c++20 %t/a.cc -triple %itanium_abi_triple -fmodule-file=a=%t/a.pcm -emit-llvm -o - | FileCheck %t/a.cc
7+
//
8+
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -triple %itanium_abi_triple -emit-reduced-module-interface -o %t/a.pcm
9+
// RUN: %clang_cc1 -std=c++20 %t/a.cc -triple %itanium_abi_triple -fmodule-file=a=%t/a.pcm -emit-llvm -o - | FileCheck %t/a.cc
10+
11+
//--- a.cppm
12+
export module a;
13+
class base {
14+
public:
15+
~base() = default;
16+
virtual void foo();
17+
};
18+
19+
template <class T>
20+
class a : public base {
21+
public:
22+
virtual void foo() override;
23+
};
24+
25+
extern template class a<int>;
26+
27+
//--- a.cc
28+
module a;
29+
30+
template <class T>
31+
void a<T>::foo() {}
32+
33+
template class a<int>;
34+
// CHECK: _ZTVW1a1aIiE

0 commit comments

Comments
 (0)