mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 10:01:06 +01:00
Support C++ calling Carbon functions with ref parameters (#7107)
When creating the C++ thunk, make the parameters references if the corresponding callee parameters are `ref`s. When creating the Carbon thunk, tag the call arguments as `ref` if the corresponding callee parameters are `ref`s.
This commit is contained in:
@@ -399,12 +399,33 @@ auto BuildThunkDefinitionForExport(Context& context,
|
||||
param_pattern_ids =
|
||||
context.inst_blocks().Get(thunk_function.param_patterns_id);
|
||||
}
|
||||
auto call_param_ids =
|
||||
context.inst_blocks().Get(thunk_function.call_params_id);
|
||||
llvm::SmallVector<SemIR::InstId> call_param_ids(
|
||||
context.inst_blocks().Get(thunk_function.call_params_id));
|
||||
|
||||
if (thunk_has_return_param) {
|
||||
param_pattern_ids = param_pattern_ids.drop_back();
|
||||
call_param_ids = call_param_ids.drop_back();
|
||||
call_param_ids.pop_back();
|
||||
}
|
||||
|
||||
auto callee_param_ids =
|
||||
context.inst_blocks().Get(callee_function.call_param_patterns_id);
|
||||
|
||||
// If any explicit parameters of the callee are `ref` parameters,
|
||||
// modify the corresponding call arguments to be `ref` tagged.
|
||||
for (auto index = thunk_function.call_param_ranges.explicit_begin().index;
|
||||
index < thunk_function.call_param_ranges.explicit_end().index; index++) {
|
||||
if (context.insts().Is<SemIR::RefParamPattern>(callee_param_ids[index])) {
|
||||
auto& call_param_id = call_param_ids[index];
|
||||
auto type = context.insts().Get(call_param_id).type_id();
|
||||
SemIR::LocId loc_id(thunk_id);
|
||||
call_param_id =
|
||||
AddInst(context, SemIR::LocIdAndInst::RuntimeVerified(
|
||||
context.sem_ir(), SemIR::LocId(call_param_id),
|
||||
SemIR::RefTagExpr{
|
||||
.type_id = type,
|
||||
.expr_id = call_param_id,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
auto call_id = BuildThunkCall(context, thunk_function_id, callee_id,
|
||||
|
||||
Reference in New Issue
Block a user