Instantiate C++ templates at end of file. (#6084)

Mark C++ functions as used when overload resolution selects them, and
trigger Clang's end-of-TU processing at the end of the Carbon
compilation to perform instantiation and other pending cleanup steps.
This commit is contained in:
Richard Smith
2025-09-17 01:06:47 +00:00
committed by GitHub
parent 6086d6eef2
commit 65a7e50037
9 changed files with 144 additions and 18 deletions
@@ -16,9 +16,6 @@ template<typename T> struct X {
static void f(T t) {}
};
// TODO: We should be able to instantiate the class and function when needed.
template struct X<int>;
using Y = X<int>;
// --- use_class_template.carbon
@@ -47,7 +44,7 @@ fn F() {
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: ; Function Attrs: mustprogress noinline nounwind optnone
// CHECK:STDOUT: define weak_odr dso_local void @_ZN1XIiE1fEi(i32 %t) #0 comdat align 2 {
// CHECK:STDOUT: define linkonce_odr dso_local void @_ZN1XIiE1fEi(i32 %t) #0 comdat align 2 {
// CHECK:STDOUT: entry:
// CHECK:STDOUT: %t.addr = alloca i32, align 4
// CHECK:STDOUT: store i32 %t, ptr %t.addr, align 4