mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +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:
@@ -143,7 +143,6 @@ fn UseZ() -> Cpp.A.Z {
|
||||
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
|
||||
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
|
||||
// CHECK:STDOUT: %X: type = class_type @X [concrete]
|
||||
// CHECK:STDOUT: %pattern_type.f80: type = pattern_type %X [concrete]
|
||||
// CHECK:STDOUT: %X.elem: type = unbound_element_type %X, %i32 [concrete]
|
||||
// CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
|
||||
// CHECK:STDOUT: %Int.as.Copy.impl.Op.type.824: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%N) [symbolic]
|
||||
@@ -169,14 +168,9 @@ fn UseZ() -> Cpp.A.Z {
|
||||
// CHECK:STDOUT: %Copy.impl_witness_table.e76 = impl_witness_table (%Core.import_ref.18d), @Int.as.Copy.impl [concrete]
|
||||
// CHECK:STDOUT: %X.g.cpp_overload_set.value: %X.g.cpp_overload_set.type = cpp_overload_set_value @X.g.cpp_overload_set [concrete = constants.%X.g.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %X.g.decl: %X.g.type = fn_decl @X.g [concrete = constants.%X.g] {
|
||||
// CHECK:STDOUT: %self.param_patt: %pattern_type.f80 = ref_param_pattern [concrete]
|
||||
// CHECK:STDOUT: %self.patt: %pattern_type.f80 = at_binding_pattern self, %self.param_patt [concrete]
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: } {
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: %self.param: ref %X = ref_param call_param0
|
||||
// CHECK:STDOUT: %self: ref %X = ref_binding self, %self.param
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
@@ -271,14 +265,9 @@ fn UseZ() -> Cpp.A.Z {
|
||||
// CHECK:STDOUT: %ImplicitAs.impl_witness_table.74f = impl_witness_table (%Core.import_ref.42d), @Core.IntLiteral.as.ImplicitAs.impl [concrete]
|
||||
// CHECK:STDOUT: %X.g.cpp_overload_set.value: %X.g.cpp_overload_set.type = cpp_overload_set_value @X.g.cpp_overload_set [concrete = constants.%X.g.cpp_overload_set.value]
|
||||
// CHECK:STDOUT: %X.g.decl: %X.g.type = fn_decl @X.g [concrete = constants.%X.g] {
|
||||
// CHECK:STDOUT: %self.param_patt: %pattern_type.f80 = ref_param_pattern [concrete]
|
||||
// CHECK:STDOUT: %self.patt: %pattern_type.f80 = at_binding_pattern self, %self.param_patt [concrete]
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: } {
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: %self.param: ref %X = ref_param call_param0
|
||||
// CHECK:STDOUT: %self: ref %X = ref_binding self, %self.param
|
||||
// CHECK:STDOUT: <elided>
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT: %Core.import_ref.18d: @Int.as.Copy.impl.%Int.as.Copy.impl.Op.type (%Int.as.Copy.impl.Op.type.824) = import_ref Core//prelude/parts/int, loc{{\d+_\d+}}, loaded [symbolic = @Int.as.Copy.impl.%Int.as.Copy.impl.Op (constants.%Int.as.Copy.impl.Op.9b9)]
|
||||
// CHECK:STDOUT: %Copy.impl_witness_table.e76 = impl_witness_table (%Core.import_ref.18d), @Int.as.Copy.impl [concrete]
|
||||
|
||||
Reference in New Issue
Block a user