[clang] [C++20] [Modules] Make sure vtable are generated for explicit template instantiation definition (PR #123871)
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 21 19:06:02 PST 2025
https://github.com/ChuanqiXu9 created https://github.com/llvm/llvm-project/pull/123871
Close https://github.com/llvm/llvm-project/issues/123719
The reason is, we thought the external explicit template instantiation declaration as the external definition incorrectly.
>From 77cc683b9e0330baf0890e97c6fa416b11c182ad Mon Sep 17 00:00:00 2001
From: Chuanqi Xu <yedeng.yd at linux.alibaba.com>
Date: Wed, 22 Jan 2025 10:59:32 +0800
Subject: [PATCH] [C++20] [Modules] Make sure vtable are generated for explicit
template instantiation definition
Close https://github.com/llvm/llvm-project/issues/123719
The reason is, we thought the external explicit template
instantiation declaration as the external definition incorrectly.
---
clang/lib/Serialization/ASTWriter.cpp | 2 ++
.../vtable-in-explicit-instantiation.cppm | 34 +++++++++++++++++++
2 files changed, 36 insertions(+)
create mode 100644 clang/test/Modules/vtable-in-explicit-instantiation.cppm
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index c7c17e09a30e0a..066c4b1533552a 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -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)
diff --git a/clang/test/Modules/vtable-in-explicit-instantiation.cppm b/clang/test/Modules/vtable-in-explicit-instantiation.cppm
new file mode 100644
index 00000000000000..b090607751744c
--- /dev/null
+++ b/clang/test/Modules/vtable-in-explicit-instantiation.cppm
@@ -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
More information about the cfe-commits
mailing list