Skip to content

Conversation

ChuanqiXu9
Copy link
Member

Close #123719

The reason is, we thought the external explicit template instantiation declaration as the external definition incorrectly.

instantiation definition

Close llvm#123719

The reason is, we thought the external explicit template
instantiation declaration as the external definition incorrectly.
@ChuanqiXu9 ChuanqiXu9 added clang:modules C++20 modules and Clang Header Modules skip-precommit-approval PR for CI feedback, not intended for review labels Jan 22, 2025
@ChuanqiXu9 ChuanqiXu9 self-assigned this Jan 22, 2025
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jan 22, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 22, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-modules

Author: Chuanqi Xu (ChuanqiXu9)

Changes

Close #123719

The reason is, we thought the external explicit template instantiation declaration as the external definition incorrectly.


Full diff: https://github.com/llvm/llvm-project/pull/123871.diff

2 Files Affected:

  • (modified) clang/lib/Serialization/ASTWriter.cpp (+2)
  • (added) clang/test/Modules/vtable-in-explicit-instantiation.cppm (+34)
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

@ChuanqiXu9 ChuanqiXu9 merged commit 05861b3 into llvm:main Jan 22, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category skip-precommit-approval PR for CI feedback, not intended for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[C++20] [Modules] Missing vtable for explicit template instantiation in other units
2 participants