mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 17:21:04 +01:00
C++ Interop: Set location when creating a return pattern (#6185)
This requires changing `ReturnSlotPattern` and `OutParamPattern` definitions to use untyped node id, so they can have any associated node. Follow up of #5197. Part of #5064.
This commit is contained in:
@@ -1492,17 +1492,29 @@ static auto GetReturnPattern(Context& context, SemIR::LocId loc_id,
|
||||
return SemIR::InstId::None;
|
||||
}
|
||||
auto pattern_type_id = GetPatternType(context, type_id);
|
||||
clang::SourceLocation return_type_loc =
|
||||
clang_decl->getReturnTypeSourceRange().getBegin();
|
||||
if (return_type_loc.isInvalid()) {
|
||||
// TODO: While `getReturnTypeSourceRange()` should work, it seems broken for
|
||||
// trailing return type. See
|
||||
// https://github.com/llvm/llvm-project/issues/162649. Until this is fixed,
|
||||
// we fallback to `getTypeSpecStartLoc()`.
|
||||
return_type_loc = clang_decl->getTypeSpecStartLoc();
|
||||
}
|
||||
SemIR::ImportIRInstId return_type_import_ir_inst_id =
|
||||
AddImportIRInst(context.sem_ir(), return_type_loc);
|
||||
SemIR::InstId return_slot_pattern_id = AddPatternInst(
|
||||
// TODO: Fill in a location for the return type once available.
|
||||
context,
|
||||
SemIR::LocIdAndInst::NoLoc(SemIR::ReturnSlotPattern(
|
||||
{.type_id = pattern_type_id, .type_inst_id = type_inst_id})));
|
||||
context, MakeImportedLocIdAndInst(
|
||||
context, return_type_import_ir_inst_id,
|
||||
SemIR::ReturnSlotPattern({.type_id = pattern_type_id,
|
||||
.type_inst_id = type_inst_id})));
|
||||
SemIR::InstId param_pattern_id = AddPatternInst(
|
||||
// TODO: Fill in a location for the return type once available.
|
||||
context, SemIR::LocIdAndInst::NoLoc(SemIR::OutParamPattern(
|
||||
{.type_id = pattern_type_id,
|
||||
.subpattern_id = return_slot_pattern_id,
|
||||
.index = SemIR::CallParamIndex::None})));
|
||||
context,
|
||||
MakeImportedLocIdAndInst(
|
||||
context, return_type_import_ir_inst_id,
|
||||
SemIR::OutParamPattern({.type_id = pattern_type_id,
|
||||
.subpattern_id = return_slot_pattern_id,
|
||||
.index = SemIR::CallParamIndex::None})));
|
||||
return param_pattern_id;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user