Author: Chuanqi Xu Date: 2025-06-25T17:51:50+08:00 New Revision: 4efb61850b590941a8da51057d3a63782864f44c
URL: https://github.com/llvm/llvm-project/commit/4efb61850b590941a8da51057d3a63782864f44c DIFF: https://github.com/llvm/llvm-project/commit/4efb61850b590941a8da51057d3a63782864f44c.diff LOG: [C++20] [Modules] Handling template declare with debug info It looks an overlook that debug info can't play well with explicit template instantiation. Tested in donwstream for years. I just forgot to upstream it. Added: clang/test/Modules/template-declare.cppm Modified: clang/lib/CodeGen/CGVTables.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp index 2897ccdf88660..0b6e830e0d557 100644 --- a/clang/lib/CodeGen/CGVTables.cpp +++ b/clang/lib/CodeGen/CGVTables.cpp @@ -1138,7 +1138,9 @@ CodeGenModule::getVTableLinkage(const CXXRecordDecl *RD) { llvm::Function::InternalLinkage; case TSK_ExplicitInstantiationDeclaration: - llvm_unreachable("Should not have been asked to emit this"); + return IsExternalDefinition + ? llvm::GlobalVariable::AvailableExternallyLinkage + : llvm::GlobalVariable::ExternalLinkage; } } diff --git a/clang/test/Modules/template-declare.cppm b/clang/test/Modules/template-declare.cppm new file mode 100644 index 0000000000000..01a7cca10e4ee --- /dev/null +++ b/clang/test/Modules/template-declare.cppm @@ -0,0 +1,39 @@ +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 %t/a.cppm -dwarf-version=4 -debug-info-kind=constructor \ +// RUN: -emit-module-interface -o %t/a.pcm +// RUN: %clang_cc1 -std=c++20 %t/b.cppm -dwarf-version=4 -debug-info-kind=constructor \ +// RUN: -emit-module-interface -o %t/b.pcm -fmodule-file=a=%t/a.pcm +// RUN: %clang_cc1 -std=c++20 %t/b.cpp -dwarf-version=4 -debug-info-kind=constructor \ +// RUN: -emit-llvm -o - -fmodule-file=a=%t/a.pcm -fmodule-file=b=%t/b.pcm | FileCheck %t/b.cpp + +//--- a.cppm +export module a; +export template <class T> +class a { +private: + T *data; + +public: + virtual T* getData(); +}; + +extern template class a<char>; + +//--- b.cppm +export module b; +import a; +export struct b { + a<char> v; +}; + +//--- b.cpp +module b; +extern "C" void func() { + b(); +} + +// It is fine enough to check that we won't crash. +// CHECK: define {{.*}}void @func() _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits