mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Import non-const rvalue references as var parameters. (#7125)
When importing a C++ function with an rvalue reference parameter, we previously produced a Carbon value parameter. This would lead to the toolchain believing it could pass the address of a non-expiring object to the function, which would lead to a use-after-move. Instead, we now map non-const rvalue reference parameters to Carbon `var` parameters. This forces the object passed into C++ to be unique and owned by the call. While that's not an exact match for C++ rvalue reference parameters, given that it provides "always move" not "conditionally move", it's the closest match we have at the moment.
This commit is contained in:
@@ -140,9 +140,9 @@ static auto MakeFunctionSignature(Context& context, SemIR::LocId loc_id,
|
||||
context, context.types().GetTypeInstId(args.self_type_id));
|
||||
EndEmptySubpattern(context);
|
||||
|
||||
insts.self_param_id = AddParamPattern(
|
||||
context, loc_id, SemIR::NameId::SelfValue, self_type_region_id,
|
||||
args.self_type_id, args.self_is_ref);
|
||||
insts.self_param_id =
|
||||
AddParamPattern(context, loc_id, SemIR::NameId::SelfValue,
|
||||
self_type_region_id, args.self_type_id, args.self_kind);
|
||||
insts.implicit_param_patterns_id =
|
||||
context.inst_blocks().Add({insts.self_param_id});
|
||||
|
||||
@@ -164,7 +164,7 @@ static auto MakeFunctionSignature(Context& context, SemIR::LocId loc_id,
|
||||
|
||||
context.inst_block_stack().AddInstId(AddParamPattern(
|
||||
context, loc_id, SemIR::NameId::Underscore, param_type_region_id,
|
||||
param_type_id, /*is_ref=*/args.params_are_refs));
|
||||
param_type_id, args.param_kind));
|
||||
}
|
||||
insts.param_patterns_id = context.inst_block_stack().Pop();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user