mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Fix crash when lowering Carbon derived class with C++ virtual base class (#7745)
If a Carbon class overrides virtual functions from a C++ base class but is never referenced from C++, it is never exported to Clang. During lowering, `BuildVtable` then fails to find a `CXXRecordDecl` and crashes when attempting to get the vtable from Clang's code generator. Ensure dynamic classes with foreign vtables are exported to Clang when completing the class definition in `CheckCompleteClassType`, and look up `first_decl_id()` in `BuildVtable`. Fixes #7721 --------- Co-authored-by: Dana Jansens <danakj@orodu.net>
This commit is contained in:
@@ -293,6 +293,16 @@ auto ExportClassToCpp(Context& context, SemIR::ClassType class_type)
|
||||
return record_decl;
|
||||
}
|
||||
|
||||
auto ExportAndCompleteClassToCpp(Context& context, SemIR::ClassType class_type)
|
||||
-> clang::TagDecl* {
|
||||
auto* tag_decl = ExportClassToCpp(context, class_type);
|
||||
if (tag_decl && context.cpp_context() &&
|
||||
context.ast_context().getExternalSource()) {
|
||||
context.ast_context().getExternalSource()->CompleteType(tag_decl);
|
||||
}
|
||||
return tag_decl;
|
||||
}
|
||||
|
||||
// Export the bindings in a generic as a `clang::TemplateParameterList`.
|
||||
static auto ExportGenericBindings(Context& context, SemIR::LocId loc_id,
|
||||
SemIR::GenericId generic_id,
|
||||
|
||||
Reference in New Issue
Block a user