Skip upfront emission of vtables for generic classes (#5349)

These will need to be emitted lazily, as we do for functions - this
addresses the crash/removes the impossible (because we don't have a
specific) non-lazy path.
This commit is contained in:
David Blaikie
2025-04-23 22:55:07 +00:00
committed by GitHub
parent b00a037c52
commit 77c5f63be7
2 changed files with 23 additions and 0 deletions
+6
View File
@@ -732,6 +732,12 @@ auto FileContext::BuildVtable(const SemIR::Class& class_info)
return nullptr;
}
// Vtables can't be generated for generics, only for their specifics - and
// must be done lazily based on the use of those specifics.
if (class_info.generic_id != SemIR::GenericId::None) {
return nullptr;
}
Mangler m(*this);
std::string mangled_name = m.MangleVTable(class_info);
+17
View File
@@ -87,6 +87,13 @@ fn Use(b: Base) {
b.F();
}
// --- generic.carbon
library "[[@TEST_NAME]]";
base class Base(T:! type) {
virtual fn F[self: Self]();
}
// CHECK:STDOUT: ; ModuleID = 'classes.carbon'
// CHECK:STDOUT: source_filename = "classes.carbon"
@@ -316,3 +323,13 @@ fn Use(b: Base) {
// CHECK:STDOUT: !6 = !{}
// CHECK:STDOUT: !7 = !DILocation(line: 9, column: 3, scope: !4)
// CHECK:STDOUT: !8 = !DILocation(line: 8, column: 1, scope: !4)
// CHECK:STDOUT: ; ModuleID = 'generic.carbon'
// CHECK:STDOUT: source_filename = "generic.carbon"
// CHECK:STDOUT:
// CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
// CHECK:STDOUT: !llvm.dbg.cu = !{!2}
// CHECK:STDOUT:
// CHECK:STDOUT: !0 = !{i32 7, !"Dwarf Version", i32 5}
// CHECK:STDOUT: !1 = !{i32 2, !"Debug Info Version", i32 3}
// CHECK:STDOUT: !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "carbon", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
// CHECK:STDOUT: !3 = !DIFile(filename: "generic.carbon", directory: "")