Skip to content

Commit

Permalink
[C++20] [Modules] Make sure vtable are generated for explicit templat…
Browse files Browse the repository at this point in the history
…e instantiation definition (#123871)

Close llvm/llvm-project#123719

The reason is, we thought the external explicit template instantiation
declaration as the external definition incorrectly.
  • Loading branch information
ChuanqiXu9 authored Jan 22, 2025
1 parent 582fe3e commit 05861b3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/lib/Serialization/ASTWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7198,6 +7198,8 @@ void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) {

bool ModulesCodegen =
!D->isDependentType() &&
D->getTemplateSpecializationKind() !=
TSK_ExplicitInstantiationDeclaration &&
(Writer->getLangOpts().ModulesDebugInfo || D->isInNamedModule());
Record->push_back(ModulesCodegen);
if (ModulesCodegen)
Expand Down
34 changes: 34 additions & 0 deletions clang/test/Modules/vtable-in-explicit-instantiation.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// RUN: rm -rf %t
// RUN: mkdir %t
// RUN: split-file %s %t

// RUN: %clang_cc1 -std=c++20 %t/a.cppm -triple %itanium_abi_triple -emit-module-interface -o %t/a.pcm
// 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
//
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -triple %itanium_abi_triple -emit-reduced-module-interface -o %t/a.pcm
// 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

//--- a.cppm
export module a;
class base {
public:
~base() = default;
virtual void foo();
};

template <class T>
class a : public base {
public:
virtual void foo() override;
};

extern template class a<int>;

//--- a.cc
module a;

template <class T>
void a<T>::foo() {}

template class a<int>;
// CHECK: _ZTVW1a1aIiE

0 comments on commit 05861b3

Please sign in to comment.