mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 19:01:07 +01:00
Fix SemIR not showing insts used to compute FieldDecl type (#7706)
Add an `ExprRegionId` to `FieldDecl`. This required moving the `NameId` into `Field`.
This commit is contained in:
@@ -79,10 +79,10 @@ static auto MapLValueToConstant(Context& context, SemIR::LocId loc_id,
|
||||
|
||||
const SemIR::FieldDecl& field_decl_inst =
|
||||
context.insts().GetAs<SemIR::FieldDecl>(field_inst_id);
|
||||
const auto& field = context.fields().Get(field_decl_inst.field_id);
|
||||
|
||||
qual_type = field_decl->getType();
|
||||
inst_id = PerformMemberAccess(context, loc_id, inst_id,
|
||||
field_decl_inst.name_id);
|
||||
inst_id = PerformMemberAccess(context, loc_id, inst_id, field.name_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -502,9 +502,10 @@ static auto CreateCppFieldDecl(Context& context,
|
||||
}
|
||||
|
||||
// Get the field's C++ identifier.
|
||||
auto* identifier_info = GetClangIdentifierInfo(context, field_decl.name_id);
|
||||
const auto& field = context.fields().Get(field_decl.field_id);
|
||||
auto* identifier_info = GetClangIdentifierInfo(context, field.name_id);
|
||||
CARBON_CHECK(identifier_info, "field with non-identifier name {0}",
|
||||
field_decl.name_id);
|
||||
field.name_id);
|
||||
|
||||
// Create the `clang::FieldDecl`.
|
||||
auto* cpp_field_decl = clang::FieldDecl::Create(
|
||||
@@ -514,7 +515,7 @@ static auto CreateCppFieldDecl(Context& context,
|
||||
/*Mutable=*/true, clang::ICIS_NoInit);
|
||||
cpp_field_decl->setInvalidDecl(invalid);
|
||||
|
||||
SetCppClassMemberAccess(class_scope, field_decl.name_id, cpp_field_decl);
|
||||
SetCppClassMemberAccess(class_scope, field.name_id, cpp_field_decl);
|
||||
|
||||
record_decl->addHiddenDecl(cpp_field_decl);
|
||||
|
||||
|
||||
@@ -811,8 +811,16 @@ static auto ImportClassObjectRepr(Context& context, SemIR::ClassId class_id,
|
||||
}
|
||||
|
||||
auto field_name_id = AddIdentifierName(context, field->getName());
|
||||
|
||||
BeginExprRegionForPattern(context);
|
||||
|
||||
auto [field_type_inst_id, field_type_id] =
|
||||
ImportCppType(context, import_ir_inst_id, field->getType());
|
||||
|
||||
SemIR::ExprRegionId type_region_id =
|
||||
ConsumeExprRegionForPattern(context, field_type_inst_id);
|
||||
EndEmptyExprRegionForPattern(context);
|
||||
|
||||
if (!field_type_inst_id.has_value()) {
|
||||
// TODO: For now, just skip over fields whose types we can't map.
|
||||
continue;
|
||||
@@ -822,6 +830,7 @@ static auto ImportClassObjectRepr(Context& context, SemIR::ClassId class_id,
|
||||
// TODO: Consider doing this lazily instead.
|
||||
auto field_id =
|
||||
context.fields().Add({.index = SemIR::ElementIndex(fields.size()),
|
||||
.name_id = field_name_id,
|
||||
// TODO: import initializers.
|
||||
.initializer_id = SemIR::InstId::None});
|
||||
auto field_decl_id = AddInst(
|
||||
@@ -830,8 +839,9 @@ static auto ImportClassObjectRepr(Context& context, SemIR::ClassId class_id,
|
||||
SemIR::FieldDecl{
|
||||
.type_id = GetUnboundElementType(
|
||||
context, class_type_inst_id, field_type_inst_id),
|
||||
.name_id = field_name_id,
|
||||
.field_id = field_id,
|
||||
.type_region_id = type_region_id
|
||||
|
||||
}));
|
||||
// The imported SemIR::FieldDecl represents the original declaration `decl`,
|
||||
// which is either the field or the indirect field declaration.
|
||||
|
||||
Reference in New Issue
Block a user