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:
Boaz Brickner
2025-10-10 15:32:14 +00:00
committed by GitHub
parent 9441c278df
commit 46c5209f2f
4 changed files with 39 additions and 18 deletions
+21 -9
View File
@@ -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;
}