Initialize vptrs to point to vtables (#5244)

Adds a mapping to keep track of vtable LLVM IR decls/defs for use.
Adds the vtable_id to the vtable_ptr initialize instruction for lookup.
Adds emission of vtable declarations for use outside the file that
defines the vtable. (this isn't done lazily, it's done for any imported
class - it could be done lazily & maybe eventually has to be lazy to
handle generics)
This commit is contained in:
David Blaikie
2025-04-05 06:11:34 +00:00
committed by GitHub
parent 8c113c1241
commit 8e7bb2f953
8 changed files with 218 additions and 63 deletions
+2 -6
View File
@@ -324,12 +324,8 @@ auto HandleInst(FunctionContext& context, SemIR::InstId inst_id,
}
auto HandleInst(FunctionContext& context, SemIR::InstId inst_id,
SemIR::VtablePtr /*inst*/) -> void {
// TODO: Initialize the virtual pointer to actually point to a virtual
// function table.
context.SetLocal(inst_id,
llvm::ConstantPointerNull::get(
llvm::PointerType::get(context.llvm_context(), 0)));
SemIR::VtablePtr inst) -> void {
context.SetLocal(inst_id, context.GetValue(inst.vtable_id));
}
} // namespace Carbon::Lower