Skip to content

Commit 4efb618

Browse files
committed
[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.
1 parent 22ee837 commit 4efb618

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

clang/lib/CodeGen/CGVTables.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,9 @@ CodeGenModule::getVTableLinkage(const CXXRecordDecl *RD) {
11381138
llvm::Function::InternalLinkage;
11391139

11401140
case TSK_ExplicitInstantiationDeclaration:
1141-
llvm_unreachable("Should not have been asked to emit this");
1141+
return IsExternalDefinition
1142+
? llvm::GlobalVariable::AvailableExternallyLinkage
1143+
: llvm::GlobalVariable::ExternalLinkage;
11421144
}
11431145
}
11441146

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -dwarf-version=4 -debug-info-kind=constructor \
6+
// RUN: -emit-module-interface -o %t/a.pcm
7+
// RUN: %clang_cc1 -std=c++20 %t/b.cppm -dwarf-version=4 -debug-info-kind=constructor \
8+
// RUN: -emit-module-interface -o %t/b.pcm -fmodule-file=a=%t/a.pcm
9+
// RUN: %clang_cc1 -std=c++20 %t/b.cpp -dwarf-version=4 -debug-info-kind=constructor \
10+
// RUN: -emit-llvm -o - -fmodule-file=a=%t/a.pcm -fmodule-file=b=%t/b.pcm | FileCheck %t/b.cpp
11+
12+
//--- a.cppm
13+
export module a;
14+
export template <class T>
15+
class a {
16+
private:
17+
T *data;
18+
19+
public:
20+
virtual T* getData();
21+
};
22+
23+
extern template class a<char>;
24+
25+
//--- b.cppm
26+
export module b;
27+
import a;
28+
export struct b {
29+
a<char> v;
30+
};
31+
32+
//--- b.cpp
33+
module b;
34+
extern "C" void func() {
35+
b();
36+
}
37+
38+
// It is fine enough to check that we won't crash.
39+
// CHECK: define {{.*}}void @func()

0 commit comments

Comments
 (0)