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:
Richard Smith
2026-04-29 00:28:00 +00:00
committed by GitHub
parent ab0aff91b8
commit 0124aae041
23 changed files with 412 additions and 411 deletions
+2 -1
View File
@@ -9,6 +9,7 @@
#include "toolchain/check/cpp/location.h"
#include "toolchain/check/cpp/type_mapping.h"
#include "toolchain/check/function.h"
#include "toolchain/check/pattern.h"
#include "toolchain/check/thunk.h"
#include "toolchain/check/type.h"
#include "toolchain/sem_ir/mangler.h"
@@ -543,7 +544,7 @@ static auto BuildCarbonToCarbonThunk(Context& context, SemIR::LocId loc_id,
.name_id = thunk_name_id,
.self_type_id = target.self_type_id,
.param_type_ids = thunk_param_type_ids,
.params_are_refs = true})
.param_kind = ParamPatternKind::Ref})
.second;
BuildThunkDefinitionForExport(