From 02294014b63e5c5134d645b00dbb15c577259c53 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Wed, 25 Nov 2026 19:01:36 +0000 Subject: [PATCH 01/25] Evaluate assignment targets once in both models Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 82 +- cpp2rust/converter/converter.h | 12 +- .../converter/models/converter_refcount.cpp | 75 +- .../converter/models/converter_refcount.h | 11 +- .../out/refcount/p14-class-in-two-files.rs | 41 +- .../out/unsafe/p14-class-in-two-files.rs | 37 +- .../p15-class-template-static-member.rs | 41 +- .../p15-class-template-static-member.rs | 37 +- .../out/refcount/p15-function-template.rs | 41 +- .../out/unsafe/p15-function-template.rs | 37 +- .../out/refcount/p15-inline-function.rs | 41 +- .../out/unsafe/p15-inline-function.rs | 37 +- .../out/refcount/p15-inline-variable.rs | 41 +- .../out/unsafe/p15-inline-variable.rs | 37 +- .../p16-default-argument-lambda-in-class.rs | 41 +- .../p16-default-argument-lambda-in-class.rs | 37 +- .../refcount/p16-lambda-in-inline-function.rs | 41 +- .../unsafe/p16-lambda-in-inline-function.rs | 37 +- .../out/refcount/basic.scope.block.rs | 41 +- .../out/unsafe/basic.scope.block.rs | 37 +- tests/std/basic/out/refcount/basic.def.odr.rs | 41 +- tests/std/basic/out/unsafe/basic.def.odr.rs | 37 +- .../stmt.select/out/refcount/stmt.if.rs | 41 +- .../stmt.select/out/refcount/stmt.switch.rs | 41 +- .../stmt.select/out/unsafe/stmt.if.rs | 37 +- .../stmt.select/out/unsafe/stmt.switch.rs | 37 +- tests/unit/assign_as_value.c | 3 + tests/unit/assignment_single_eval.cpp | 76 ++ tests/unit/out/refcount/anonymous-struct.rs | 16 +- tests/unit/out/refcount/anonymous-struct_c.rs | 16 +- tests/unit/out/refcount/assign_as_value.rs | 26 +- tests/unit/out/refcount/assign_rhs_first.rs | 8 +- .../out/refcount/assignment_single_eval.rs | 552 ++++++++++++ .../out/refcount/compound_assign_paren.rs | 58 +- .../unit/out/refcount/copy_move_defaulted.rs | 12 +- tests/unit/out/refcount/destructor.rs | 28 +- tests/unit/out/refcount/expr_as_bool_c.rs | 40 +- tests/unit/out/refcount/expr_as_bool_cpp.rs | 40 +- .../field_pointers_malloced_struct.rs | 16 +- tests/unit/out/refcount/fn_ptr.rs | 12 +- .../out/refcount/global_call_temporaries.rs | 192 +++-- .../refcount/immutable_unsigned_arithmetic.rs | 8 +- tests/unit/out/refcount/inet_pton_ntop.rs | 87 +- .../out/refcount/inline_container_fields.rs | 8 +- tests/unit/out/refcount/lambda_generic.rs | 8 +- .../refcount/lambda_generic_explicit_args.rs | 42 +- tests/unit/out/refcount/map_key_copy_ctor.rs | 382 ++++++--- tests/unit/out/refcount/map_key_identity.rs | 795 ++++++++++++------ tests/unit/out/refcount/map_try_emplace.rs | 569 ++++++++----- .../out/refcount/map_try_emplace_lvalues.rs | 530 ++++++------ .../operator_compound_assignment_free.rs | 40 +- .../operator_compound_assignment_member.rs | 40 +- tests/unit/out/refcount/size_t_ssize_t.rs | 99 ++- .../out/refcount/size_t_template_param.rs | 8 +- tests/unit/out/refcount/swap_map_no_copy.rs | 99 ++- .../unit/out/refcount/switch_on_assignment.rs | 8 +- tests/unit/out/refcount/va_arg_concat.rs | 8 +- tests/unit/out/refcount/va_arg_two_passes.rs | 16 +- .../out/refcount/vector_subscript_borrow.rs | 7 +- tests/unit/out/unsafe/anonymous-struct.rs | 16 +- tests/unit/out/unsafe/anonymous-struct_c.rs | 16 +- tests/unit/out/unsafe/assign_as_value.rs | 24 +- tests/unit/out/unsafe/assign_rhs_first.rs | 6 +- .../unit/out/unsafe/assignment_single_eval.rs | 577 +++++++++++++ .../unit/out/unsafe/compound_assign_paren.rs | 44 +- tests/unit/out/unsafe/copy_move_defaulted.rs | 12 +- tests/unit/out/unsafe/destructor.rs | 22 +- tests/unit/out/unsafe/expr_as_bool_c.rs | 40 +- tests/unit/out/unsafe/expr_as_bool_cpp.rs | 40 +- .../unsafe/field_pointers_malloced_struct.rs | 16 +- tests/unit/out/unsafe/fn_ptr.rs | 10 +- .../out/unsafe/global_call_temporaries.rs | 171 ++-- .../unsafe/immutable_unsigned_arithmetic.rs | 6 +- tests/unit/out/unsafe/inet_pton_ntop.rs | 18 +- .../out/unsafe/inline_container_fields.rs | 6 +- tests/unit/out/unsafe/lambda_generic.rs | 6 +- .../unsafe/lambda_generic_explicit_args.rs | 32 +- tests/unit/out/unsafe/map_key_copy_ctor.rs | 234 ++++-- tests/unit/out/unsafe/map_key_identity.rs | 462 +++++++--- tests/unit/out/unsafe/map_try_emplace.rs | 449 +++++++--- .../out/unsafe/map_try_emplace_lvalues.rs | 420 ++++----- .../operator_compound_assignment_free.rs | 30 +- .../operator_compound_assignment_member.rs | 30 +- tests/unit/out/unsafe/size_t_ssize_t.rs | 77 +- .../unit/out/unsafe/size_t_template_param.rs | 6 +- tests/unit/out/unsafe/swap_map_no_copy.rs | 24 +- tests/unit/out/unsafe/switch_on_assignment.rs | 8 +- tests/unit/out/unsafe/va_arg_concat.rs | 8 +- tests/unit/out/unsafe/va_arg_two_passes.rs | 16 +- .../out/unsafe/vector_subscript_borrow.rs | 6 +- 90 files changed, 5556 insertions(+), 2163 deletions(-) create mode 100644 tests/unit/assignment_single_eval.cpp create mode 100644 tests/unit/out/refcount/assignment_single_eval.rs create mode 100644 tests/unit/out/unsafe/assignment_single_eval.rs diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index eb0231c9f0..d6cb5f0c6d 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -3007,7 +3007,8 @@ bool Converter::VisitBinaryOperator(clang::BinaryOperator *expr) { ConvertAssignmentRef(expr); return false; } - if (expr->isAssignmentOp() && isLValue()) { + if (isLValue() && + (expr->isAssignmentOp() || (expr->isCommaOp() && expr->isLValue()))) { EmitPointee(std::format("({})", ConvertFreshPointer(expr)), expr->getType(), /*fresh=*/true); return false; @@ -3048,11 +3049,6 @@ void Converter::ConvertAssignmentRef(clang::BinaryOperator *expr) { if (auto *compound = clang::dyn_cast(expr)) { assignment = AssignPtrExpr(left, lhs->getType(), [&](std::string_view read) { - if (lhs->getType()->isPointerType()) { - return std::format( - "({}).offset({}({} as isize))", read, - expr->getOpcode() == clang::BO_SubAssign ? "-" : "", right); - } return ConvertCompoundAssignValue(compound, read, right); }); } @@ -3072,13 +3068,14 @@ void Converter::ConvertBinaryOperator(clang::BinaryOperator *expr) { auto rhs_type = rhs->getType(); std::string_view opcode_as_string = expr->getOpcodeStr(); - if (auto *cmpd_assign_op = - llvm::dyn_cast(expr); - expr->isCompoundAssignmentOp() && - GetUnsafeTypeAsString(lhs_type) != - GetUnsafeTypeAsString(cmpd_assign_op->getComputationResultType())) { - StrCat(ConvertLValue(lhs), token::kAssign, - ConvertCompoundAssignValue(cmpd_assign_op)); + auto *compound = clang::dyn_cast(expr); + if (expr->isAssignmentOp() && + (isRValue() || + (compound && + (IsUnsignedArithOp(expr) || + GetUnsafeTypeAsString(lhs_type) != + GetUnsafeTypeAsString(compound->getComputationResultType()))))) { + ConvertAssignment(lhs, rhs, opcode_as_string, compound); } else if (expr->isCommaOp()) { PushBrace brace(*this); { @@ -3089,22 +3086,18 @@ void Converter::ConvertBinaryOperator(clang::BinaryOperator *expr) { StrCat(token::kSemiColon); if (isRValue()) { StrCat(ConvertFreshRValue(rhs)); + } else if (isAddrOf()) { + StrCat(MakeFresh(ToString(rhs))); } else { Convert(rhs); } } else if (IsUnsignedArithOp(expr)) { - if (expr->isCompoundAssignmentOp()) { - Convert(lhs); - StrCat(token::kAssign); - } { PushParen paren(*this); ConvertUnsignedArithOperand(lhs, type); } ConvertUnsignedArithBinaryOperator(expr, rhs); - if (!expr->isCompoundAssignmentOp()) { - MarkFresh(); - } + MarkFresh(); } else if (expr->isAssignmentOp()) { if (expr->isCompoundAssignmentOp() && lhs_type->isPointerType() && rhs_type->isIntegralOrEnumerationType()) { @@ -3185,12 +3178,17 @@ Converter::ConvertCompoundAssignValue(clang::CompoundAssignOperator *expr, std::string_view rhs_value) { auto *lhs = expr->getLHS(); auto computation_result_type = expr->getComputationResultType(); + if (lhs->getType()->isPointerType()) { + return std::format("({}).offset({}({} as isize))", lhs_value, + expr->getOpcode() == clang::BO_SubAssign ? "-" : "", + rhs_value); + } Buffer buf(*this); { PushParen outer(*this); { PushParen inner(*this); - StrCat(lhs_value.empty() ? ConvertRValue(lhs) : lhs_value); + StrCat(lhs_value); ConvertCast(computation_result_type); } if (IsUnsignedArithOp(expr)) { @@ -3199,12 +3197,8 @@ Converter::ConvertCompoundAssignValue(clang::CompoundAssignOperator *expr, std::string_view op = expr->getOpcodeStr(); op.remove_suffix(1); // remove '=' from operator StrCat(op); - if (rhs_value.empty()) { - Convert(expr->getRHS(), computation_result_type); - } else { - StrCat( - ConvertScalarCast(std::string(rhs_value), computation_result_type)); - } + StrCat( + ConvertScalarCast(std::string(rhs_value), computation_result_type)); } } if (lhs->getType()->isBooleanType()) { @@ -3237,6 +3231,11 @@ void Converter::ConvertGenericBinaryOperator(clang::BinaryOperator *expr) { bool Converter::IsReferenceType(const clang::Expr *expr) const { const auto *e = IgnoreTransparentStdCall(ctx_, expr->IgnoreCasts())->IgnoreCasts(); + if (const auto *comma = + clang::dyn_cast(e->IgnoreParens()); + comma && comma->isCommaOp()) { + return IsReferenceType(comma->getRHS()); + } if (const auto *call = clang::dyn_cast(e)) { return !clang::isa(call) && GetReturnTypeOfFunction(call)->isReferenceType(); @@ -4945,7 +4944,34 @@ void Converter::ConvertArraySubscript(clang::Expr *base, clang::Expr *idx, } void Converter::ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, - std::string_view assign_operator) { + std::string_view assign_operator, + clang::CompoundAssignOperator *compound) { + if (compound || isRValue()) { + auto right = NewTempName(); + auto left = NewTempName(); + auto rhs_value = ConvertFreshRValue( + rhs, compound ? std::nullopt : std::optional(lhs->getType())); + auto lhs_value = ConvertLValue(lhs); + auto read = std::format("(*{})", left); + auto value = + compound ? ConvertCompoundAssignValue(compound, read, right) : right; + // Rust evaluates tuple operands left to right. Resolve the target only + // after the right operand, keeping its temporaries alive through the write. + StrCat("match ({ ", rhs_value, " }, &mut "); + { + PushParen paren(*this); + StrCat(lhs_value); + } + StrCat(") { (", right, ", ", left, ") => {", read, token::kAssign, value, + token::kSemiColon); + if (isRValue()) { + StrCat(read, ".clone()"); + } + StrCat("} }"); + MarkFresh(); + return; + } + std::string lhs_as_string; { ScopedPush init_type(curr_init_type_, lhs->getType()); diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index df548824c5..526130a8fc 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -538,10 +538,10 @@ class Converter : public clang::RecursiveASTVisitor { virtual void ConvertBinaryOperator(clang::BinaryOperator *expr); // The value that the compound assignment expr assigns to its left operand. - // Optional operand strings refer to values that have already been evaluated. + // Operand strings refer to values that have already been evaluated. std::string ConvertCompoundAssignValue(clang::CompoundAssignOperator *expr, - std::string_view lhs_value = {}, - std::string_view rhs_value = {}); + std::string_view lhs_value, + std::string_view rhs_value); virtual bool ConvertIncAndDec(clang::UnaryOperator *expr); @@ -794,8 +794,10 @@ class Converter : public clang::RecursiveASTVisitor { void EmitFlexibleArrayElementPtr(clang::Expr *array, clang::Expr *idx, bool is_mut); - virtual void ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, - std::string_view assign_operator); + virtual void + ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, + std::string_view assign_operator, + clang::CompoundAssignOperator *compound = nullptr); virtual void ConvertFunctionParameters(clang::FunctionDecl *decl); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index bcb26c3f41..1d5bdadb39 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -1591,34 +1591,24 @@ void ConverterRefCount::ConvertBinaryOperator(clang::BinaryOperator *expr) { auto rhs_type = rhs->getType(); std::string_view opcode_as_string = expr->getOpcodeStr(); - if (auto *assign = llvm::dyn_cast(expr); - assign && GetSafeTypeAsString(lhs_type) != - GetSafeTypeAsString(assign->getComputationResultType())) { - EmitCompoundSetOrAssign(lhs, rhs, ConvertCompoundAssignValue(assign)); + auto *compound = clang::dyn_cast(expr); + if (expr->isAssignmentOp() && + (isRValue() || + (compound && + (IsUnsignedArithOp(expr) || + GetSafeTypeAsString(lhs_type) != + GetSafeTypeAsString(compound->getComputationResultType()))))) { + ConvertAssignment(lhs, rhs, opcode_as_string, compound); return; } if (IsUnsignedArithOp(expr)) { - std::optional buf; - if (expr->isCompoundAssignmentOp()) { - buf.emplace(*this); - } { PushParen paren(*this); - if (expr->isCompoundAssignmentOp() && lhs->isLValue()) { - StrCat(ConvertRValue(lhs)); - } else { - ConvertUnsignedArithOperand(lhs, expr->getType()); - } + ConvertUnsignedArithOperand(lhs, expr->getType()); } ConvertUnsignedArithBinaryOperator(expr, rhs); - if (expr->isCompoundAssignmentOp()) { - auto value = std::move(*buf).str(); - buf.reset(); - EmitCompoundSetOrAssign(lhs, rhs, value); - } else { - MarkFresh(); - } + MarkFresh(); return; } @@ -2432,21 +2422,42 @@ bool ConverterRefCount::CanBraceAssignedValue( !lhs->HasSideEffects(ctx_) && !rhs->HasSideEffects(ctx_); } -void ConverterRefCount::EmitCompoundSetOrAssign(clang::Expr *lhs, - clang::Expr *rhs, - std::string_view value) { - if (CanBraceAssignedValue(lhs, rhs, "=")) { - PushBrace brace(*this, isRValue()); - EmitSetOrAssign(lhs, std::format("{{ {} }}", value)); +void ConverterRefCount::ConvertAssignment( + clang::Expr *lhs, clang::Expr *rhs, std::string_view assign_operator, + clang::CompoundAssignOperator *compound) { + if (compound || isRValue()) { + // End target borrows before an enclosing expression consumes the result. + PushBrace brace(*this); + auto right = NewTempName(); + auto left = NewTempName(); + auto rhs_value = ConvertFreshRValue( + rhs, compound ? std::nullopt : std::optional(lhs->getType())); + auto lhs_value = ConvertLValue(lhs); + auto read = std::format("(*{})", left); + auto value = + compound ? ConvertCompoundAssignValue(compound, read, right) : right; + // Rust evaluates tuple operands left to right. Resolve the target only + // after the right operand, keeping its temporaries alive through the write. + StrCat("match ({ ", rhs_value, " }, "); + bool through_pointer = !pending_deref_.empty(); + StrCat(through_pointer ? "&" : "&mut "); + { + PushParen paren(*this); + StrCat(through_pointer ? pending_deref_.take() : lhs_value); + } + StrCat(") { (", right, ", ", left, ") => "); + if (through_pointer) { + StrCat(left, ".with_mut(|", left, "| "); + } + StrCat('{', read, token::kAssign, value, token::kSemiColon); + if (isRValue()) { + StrCat(read, ".clone()"); + } + StrCat(through_pointer ? "}) }" : "} }"); + MarkFresh(); return; } - PushBrace brace(*this); - StrCat(keyword::kLet, "rhs_0", token::kAssign, value, token::kSemiColon); - EmitSetOrAssign(lhs, "rhs_0"); -} -void ConverterRefCount::ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, - std::string_view assign_operator) { auto rhs_as_string = ConvertFreshRValue(rhs, lhs->getType()); PushBrace brace(*this, isRValue()); diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index ac55da89b7..d0ddc470df 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -299,8 +299,10 @@ class ConverterRefCount final : public Converter { std::string ConvertVarInitValue(clang::QualType qual_type, clang::Expr *expr); - void ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, - std::string_view assign_operator) override; + void + ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, + std::string_view assign_operator, + clang::CompoundAssignOperator *compound = nullptr) override; bool ConvertCXXOperatorCallExpr(clang::CXXOperatorCallExpr *expr) override; @@ -456,11 +458,6 @@ class ConverterRefCount final : public Converter { bool CanBraceAssignedValue(clang::Expr *lhs, clang::Expr *rhs, std::string_view assign_operator); - // Emits `lhs = value`, where value is the result of the compound assignment - // `lhs op= rhs` and thus reads lhs. - void EmitCompoundSetOrAssign(clang::Expr *lhs, clang::Expr *rhs, - std::string_view value); - // If lhs is a direct reference to a global/static value (not a reference // type), emits `var.with(|rc| *rc.borrow_mut() )` and returns // true. This avoids cloning the Rc just to assign through it. Returns diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs index 34f713292b..581ecad0e2 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs @@ -28,18 +28,39 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - copyCount_1.with(|rc| { - *rc.borrow_mut() = { - dtorCount_2.with(|rc| { - *rc.borrow_mut() = { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) + match ( + { + { + match ( + { + { + match ( + { 0 }, + &mut (*useCount_3.with(Value::clone).borrow_mut()), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + } + }, + &mut (*dtorCount_2.with(Value::clone).borrow_mut()), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } } - }); - dtorCount_2.with(|rc| *rc.borrow()) + } + }, + &mut (*copyCount_1.with(Value::clone).borrow_mut()), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() } - }); - copyCount_1.with(|rc| *rc.borrow()) + } } }); } diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs index 5309797a65..afbe301d39 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs @@ -17,15 +17,34 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( + { + match ( + { + match ( + { 0 }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } }; } pub unsafe fn new() -> Self { diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs index d2ffb7060e..922fef0561 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs @@ -28,18 +28,39 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - copyCount_1.with(|rc| { - *rc.borrow_mut() = { - dtorCount_2.with(|rc| { - *rc.borrow_mut() = { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) + match ( + { + { + match ( + { + { + match ( + { 0 }, + &mut (*useCount_3.with(Value::clone).borrow_mut()), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + } + }, + &mut (*dtorCount_2.with(Value::clone).borrow_mut()), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } } - }); - dtorCount_2.with(|rc| *rc.borrow()) + } + }, + &mut (*copyCount_1.with(Value::clone).borrow_mut()), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() } - }); - copyCount_1.with(|rc| *rc.borrow()) + } } }); } diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs index f366dd2b83..202058b1eb 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs @@ -17,15 +17,34 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( + { + match ( + { + match ( + { 0 }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } }; } pub unsafe fn new() -> Self { diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs index dd6c90c7ef..69bef28033 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs @@ -28,18 +28,39 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - copyCount_1.with(|rc| { - *rc.borrow_mut() = { - dtorCount_2.with(|rc| { - *rc.borrow_mut() = { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) + match ( + { + { + match ( + { + { + match ( + { 0 }, + &mut (*useCount_3.with(Value::clone).borrow_mut()), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + } + }, + &mut (*dtorCount_2.with(Value::clone).borrow_mut()), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } } - }); - dtorCount_2.with(|rc| *rc.borrow()) + } + }, + &mut (*copyCount_1.with(Value::clone).borrow_mut()), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() } - }); - copyCount_1.with(|rc| *rc.borrow()) + } } }); } diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs index e822da1ad5..3282fd145e 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs @@ -17,15 +17,34 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( + { + match ( + { + match ( + { 0 }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } }; } pub unsafe fn new() -> Self { diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs index 01e84bfcb3..36b3168d3d 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs @@ -28,18 +28,39 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - copyCount_1.with(|rc| { - *rc.borrow_mut() = { - dtorCount_2.with(|rc| { - *rc.borrow_mut() = { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) + match ( + { + { + match ( + { + { + match ( + { 0 }, + &mut (*useCount_3.with(Value::clone).borrow_mut()), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + } + }, + &mut (*dtorCount_2.with(Value::clone).borrow_mut()), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } } - }); - dtorCount_2.with(|rc| *rc.borrow()) + } + }, + &mut (*copyCount_1.with(Value::clone).borrow_mut()), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() } - }); - copyCount_1.with(|rc| *rc.borrow()) + } } }); } diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs index d71518db48..f02502bd6a 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs @@ -17,15 +17,34 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( + { + match ( + { + match ( + { 0 }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } }; } pub unsafe fn new() -> Self { diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs index 21b612eed3..0d2dc5255d 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs @@ -28,18 +28,39 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - copyCount_1.with(|rc| { - *rc.borrow_mut() = { - dtorCount_2.with(|rc| { - *rc.borrow_mut() = { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) + match ( + { + { + match ( + { + { + match ( + { 0 }, + &mut (*useCount_3.with(Value::clone).borrow_mut()), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + } + }, + &mut (*dtorCount_2.with(Value::clone).borrow_mut()), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } } - }); - dtorCount_2.with(|rc| *rc.borrow()) + } + }, + &mut (*copyCount_1.with(Value::clone).borrow_mut()), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() } - }); - copyCount_1.with(|rc| *rc.borrow()) + } } }); } diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs index c7006c1478..85b4ee567d 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs @@ -17,15 +17,34 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( + { + match ( + { + match ( + { 0 }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } }; } pub unsafe fn new() -> Self { diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs index da9dce2d90..baaab94999 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs @@ -28,18 +28,39 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - copyCount_1.with(|rc| { - *rc.borrow_mut() = { - dtorCount_2.with(|rc| { - *rc.borrow_mut() = { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) + match ( + { + { + match ( + { + { + match ( + { 0 }, + &mut (*useCount_3.with(Value::clone).borrow_mut()), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + } + }, + &mut (*dtorCount_2.with(Value::clone).borrow_mut()), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } } - }); - dtorCount_2.with(|rc| *rc.borrow()) + } + }, + &mut (*copyCount_1.with(Value::clone).borrow_mut()), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() } - }); - copyCount_1.with(|rc| *rc.borrow()) + } } }); } diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs index ad5d698cef..dd7d405c0b 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs @@ -17,15 +17,34 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( + { + match ( + { + match ( + { 0 }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } }; } pub unsafe fn new() -> Self { diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs index 98847588b6..ae10fc7e27 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs @@ -28,18 +28,39 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - copyCount_1.with(|rc| { - *rc.borrow_mut() = { - dtorCount_2.with(|rc| { - *rc.borrow_mut() = { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) + match ( + { + { + match ( + { + { + match ( + { 0 }, + &mut (*useCount_3.with(Value::clone).borrow_mut()), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + } + }, + &mut (*dtorCount_2.with(Value::clone).borrow_mut()), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } } - }); - dtorCount_2.with(|rc| *rc.borrow()) + } + }, + &mut (*copyCount_1.with(Value::clone).borrow_mut()), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() } - }); - copyCount_1.with(|rc| *rc.borrow()) + } } }); } diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs index fe1766c880..fb3187d45a 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs @@ -17,15 +17,34 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( + { + match ( + { + match ( + { 0 }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } }; } pub unsafe fn new() -> Self { diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs index fbd6e1813e..9dc9012e58 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs @@ -28,18 +28,39 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - copyCount_1.with(|rc| { - *rc.borrow_mut() = { - dtorCount_2.with(|rc| { - *rc.borrow_mut() = { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) + match ( + { + { + match ( + { + { + match ( + { 0 }, + &mut (*useCount_3.with(Value::clone).borrow_mut()), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + } + }, + &mut (*dtorCount_2.with(Value::clone).borrow_mut()), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } } - }); - dtorCount_2.with(|rc| *rc.borrow()) + } + }, + &mut (*copyCount_1.with(Value::clone).borrow_mut()), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() } - }); - copyCount_1.with(|rc| *rc.borrow()) + } } }); } diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs index cfaf288d6e..21af739147 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs @@ -17,15 +17,34 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( + { + match ( + { + match ( + { 0 }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } }; } pub unsafe fn new() -> Self { diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index 66705328fd..bc9aeb1aab 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -60,18 +60,39 @@ impl LifetimeTracked { pub fn reset() { ctorCount_1.with(|rc| { *rc.borrow_mut() = { - copyCount_2.with(|rc| { - *rc.borrow_mut() = { - dtorCount_3.with(|rc| { - *rc.borrow_mut() = { - useCount_4.with(|rc| *rc.borrow_mut() = 0); - useCount_4.with(|rc| *rc.borrow()) + match ( + { + { + match ( + { + { + match ( + { 0 }, + &mut (*useCount_4.with(Value::clone).borrow_mut()), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + } + }, + &mut (*dtorCount_3.with(Value::clone).borrow_mut()), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } } - }); - dtorCount_3.with(|rc| *rc.borrow()) + } + }, + &mut (*copyCount_2.with(Value::clone).borrow_mut()), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() } - }); - copyCount_2.with(|rc| *rc.borrow()) + } } }); } diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index d482309b05..67d0712b88 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -47,15 +47,34 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)) = match ( + { + match ( + { + match ( + { 0 }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } }; } pub unsafe fn new() -> Self { diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs index 6f94c793f0..5cc4ae59e1 100644 --- a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs @@ -28,18 +28,39 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - copyCount_1.with(|rc| { - *rc.borrow_mut() = { - dtorCount_2.with(|rc| { - *rc.borrow_mut() = { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) + match ( + { + { + match ( + { + { + match ( + { 0 }, + &mut (*useCount_3.with(Value::clone).borrow_mut()), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + } + }, + &mut (*dtorCount_2.with(Value::clone).borrow_mut()), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } } - }); - dtorCount_2.with(|rc| *rc.borrow()) + } + }, + &mut (*copyCount_1.with(Value::clone).borrow_mut()), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() } - }); - copyCount_1.with(|rc| *rc.borrow()) + } } }); } diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs index 0935da1fb3..19a9d002b1 100644 --- a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs @@ -28,18 +28,39 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - copyCount_1.with(|rc| { - *rc.borrow_mut() = { - dtorCount_2.with(|rc| { - *rc.borrow_mut() = { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) + match ( + { + { + match ( + { + { + match ( + { 0 }, + &mut (*useCount_3.with(Value::clone).borrow_mut()), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + } + }, + &mut (*dtorCount_2.with(Value::clone).borrow_mut()), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } } - }); - dtorCount_2.with(|rc| *rc.borrow()) + } + }, + &mut (*copyCount_1.with(Value::clone).borrow_mut()), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() } - }); - copyCount_1.with(|rc| *rc.borrow()) + } } }); } diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs index fd22be5aba..770dc0dc1d 100644 --- a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs @@ -17,15 +17,34 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( + { + match ( + { + match ( + { 0 }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } }; } pub unsafe fn new() -> Self { diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs index 177fa848ed..8acdb4be39 100644 --- a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs @@ -17,15 +17,34 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( + { + match ( + { + match ( + { 0 }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } }; } pub unsafe fn new() -> Self { diff --git a/tests/unit/assign_as_value.c b/tests/unit/assign_as_value.c index 7ec44cbde6..e148ed64ff 100644 --- a/tests/unit/assign_as_value.c +++ b/tests/unit/assign_as_value.c @@ -5,6 +5,9 @@ int main(void) { char *p = buf, *q; q = p += 1; assert(q == buf + 1); + q = p -= 1; + assert(p == buf); + assert(q == buf); char out; switch (out = 'x') { diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp new file mode 100644 index 0000000000..470496600b --- /dev/null +++ b/tests/unit/assignment_single_eval.cpp @@ -0,0 +1,76 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++17 +#include +#include + +template void test() { + T a[3] = {10, 20, 30}; + int i = 0; + a[i++] += 5; + std::printf("void %d %d %d\n", i, int(a[0]), int(a[1])); + + i = 0; + T sum = (a[i++] += 2); + std::printf("compound %d %d %d %d\n", i, int(sum), int(a[0]), int(a[1])); + + i = 0; + T assigned = (a[i++] = 99); + std::printf("simple %d %d %d %d\n", i, int(assigned), int(a[0]), int(a[1])); +} + +template void test_comma() { + T x = 10; + int i = 0; + ((++i, x) += 5); + std::printf("direct void %d %d\n", i, int(x)); + T result = ((++i, x) += 2); + std::printf("direct compound %d %d %d\n", i, int(result), int(x)); + result = ((++i, x) = 99); + std::printf("direct simple %d %d %d\n", i, int(result), int(x)); + + T *p = &x; + ((++i, *p) += 5); + std::printf("indirect void %d %d\n", i, int(*p)); + result = ((++i, *p) += 2); + std::printf("indirect compound %d %d %d\n", i, int(result), int(*p)); + result = ((++i, *p) = 99); + std::printf("indirect simple %d %d %d\n", i, int(result), int(*p)); +} + +int global = 10; +int observe_global(int assigned) { return assigned + global; } +int observe(int assigned, const int *stored) { return assigned + *stored; } + +void test_borrows() { + std::printf("%d\n", observe_global(global = 99)); + std::printf("%d\n", observe_global(global += 5)); + + int local = 10; + std::printf("%d\n", observe(local = 99, &local)); + std::printf("%d\n", observe(local += 5, &local)); + + struct Record { + int value; + }; + Record record{10}; + std::printf("%d\n", observe(record.value = 99, &record.value)); + std::printf("%d\n", observe(record.value += 5, &record.value)); + + std::vector values(1, 10); + std::printf("%d\n", observe(values[0] = 99, &values[0])); + std::printf("%d\n", observe(values[0] += 5, &values[0])); +} + +int main() { + test(); + test(); + test(); + test_comma(); + test_comma(); + unsigned values[2] = {10, 20}; + unsigned (&ref)[2] = values; + int i = 0; + unsigned result = ((++i, ref)[0] += 5); + std::printf("array reference %d %u %u\n", i, result, values[0]); + test_borrows(); + return 0; +} diff --git a/tests/unit/out/refcount/anonymous-struct.rs b/tests/unit/out/refcount/anonymous-struct.rs index d8b0921f4d..bc685c12df 100644 --- a/tests/unit/out/refcount/anonymous-struct.rs +++ b/tests/unit/out/refcount/anonymous-struct.rs @@ -114,14 +114,22 @@ fn main_0() -> i32 { s.z = 2; assert!( ({ - s.x = 1; - s.x + match ({ 1 }, &mut (s.x)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } + } } != 0) ); assert!( ({ - s.z = 2; - s.z + match ({ 2 }, &mut (s.z)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } } != 0) ); return 0; diff --git a/tests/unit/out/refcount/anonymous-struct_c.rs b/tests/unit/out/refcount/anonymous-struct_c.rs index c903903369..b6ba504c05 100644 --- a/tests/unit/out/refcount/anonymous-struct_c.rs +++ b/tests/unit/out/refcount/anonymous-struct_c.rs @@ -120,14 +120,22 @@ fn main_0() -> i32 { s.z = 2; assert!( ({ - s.x = 1; - s.x + match ({ 1 }, &mut (s.x)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } + } } != 0) ); assert!( ({ - s.z = 2; - s.z + match ({ 2 }, &mut (s.z)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } } != 0) ); return 0; diff --git a/tests/unit/out/refcount/assign_as_value.rs b/tests/unit/out/refcount/assign_as_value.rs index ca00769b39..4d3ec07a03 100644 --- a/tests/unit/out/refcount/assign_as_value.rs +++ b/tests/unit/out/refcount/assign_as_value.rs @@ -15,16 +15,34 @@ fn main_0() -> i32 { let mut p: Ptr = buf.decay(); let mut q: Ptr = Ptr::::null(); q = { - p += 1; - (p).clone() + match ({ 1 }, &mut (p)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (*__tmp_1).offset((__tmp_0 as isize)); + (*__tmp_1).clone() + } + } }; assert!(({ (q).clone() } == { buf.decay().offset((1) as isize) })); + q = { + match ({ 1 }, &mut (p)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (*__tmp_3).offset(-(__tmp_2 as isize)); + (*__tmp_3).clone() + } + } + }; + assert!(({ (p).clone() } == { buf.decay() })); + assert!(({ (q).clone() } == { buf.decay() })); let mut out: i8 = 0_i8; 'switch: { match { (({ - out = (('x' as i32) as i8); - out + match ({ (('x' as i32) as i8) }, &mut (out)) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } }) as i32) } { __v if __v == ('x' as i32) => { diff --git a/tests/unit/out/refcount/assign_rhs_first.rs b/tests/unit/out/refcount/assign_rhs_first.rs index 44e750a1f5..5153a31aac 100644 --- a/tests/unit/out/refcount/assign_rhs_first.rs +++ b/tests/unit/out/refcount/assign_rhs_first.rs @@ -105,7 +105,13 @@ fn main_0() -> i32 { ); let mut b: Ptr = a.decay().reinterpret_cast::(); elem!(b, 0).write(7_u8); - elem!(b, 4).write({ (((elem!(b, 4).read()) as i32) + 1) as u8 }); + { + match ({ 1 }, &(elem!(b, 4))) { + (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { + (*__tmp_1) = (((*__tmp_1) as i32) + (__tmp_0 as i32)) as u8; + }), + } + }; assert!(({ ((*a.borrow())[(0) as usize] == 7) && ((*a.borrow())[(1) as usize] == 3) })); return 0; } diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs new file mode 100644 index 0000000000..1d133b8633 --- /dev/null +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -0,0 +1,552 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +pub fn test_0() { + let mut a: [u32; 3] = [10_u32, 20_u32, 30_u32]; + let mut i: i32 = 0; + { + match ({ 5_u32 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; + } + } + }; + printf!( + b"void %d %d %d\n", + i, + (a[(0) as usize] as i32), + (a[(1) as usize] as i32) + ); + i = 0; + let mut sum: u32 = ({ + match ({ 2_u32 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (((*__tmp_3) as u32).wrapping_add((__tmp_2 as u32))) as u32; + (*__tmp_3).clone() + } + } + }); + printf!( + b"compound %d %d %d %d\n", + i, + (sum as i32), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32) + ); + i = 0; + let mut assigned: u32 = ({ + match ({ 99_u32 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } + }); + printf!( + b"simple %d %d %d %d\n", + i, + (assigned as i32), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32) + ); +} +pub fn test_1() { + let mut a: [i16; 3] = [10_i16, 20_i16, 30_i16]; + let mut i: i32 = 0; + { + match ({ 5 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as i32) + (__tmp_6 as i32)) as i16; + } + } + }; + printf!( + b"void %d %d %d\n", + i, + (a[(0) as usize] as i32), + (a[(1) as usize] as i32) + ); + i = 0; + let mut sum: i16 = ({ + match ({ 2 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as i32) + (__tmp_8 as i32)) as i16; + (*__tmp_9).clone() + } + } + }); + printf!( + b"compound %d %d %d %d\n", + i, + (sum as i32), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32) + ); + i = 0; + let mut assigned: i16 = ({ + match ({ 99_i16 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_10, __tmp_11) => { + (*__tmp_11) = __tmp_10; + (*__tmp_11).clone() + } + } + }); + printf!( + b"simple %d %d %d %d\n", + i, + (assigned as i32), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32) + ); +} +pub fn test_2() { + let mut a: [i32; 3] = [10, 20, 30]; + let mut i: i32 = 0; + a[(i.postfix_inc()) as usize] += 5; + printf!(b"void %d %d %d\n", i, a[(0) as usize], a[(1) as usize]); + i = 0; + let mut sum: i32 = ({ + match ({ 2 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_12, __tmp_13) => { + (*__tmp_13) = (((*__tmp_13) as i32) + (__tmp_12 as i32)) as i32; + (*__tmp_13).clone() + } + } + }); + printf!( + b"compound %d %d %d %d\n", + i, + sum, + a[(0) as usize], + a[(1) as usize] + ); + i = 0; + let mut assigned: i32 = ({ + match ({ 99 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_14, __tmp_15) => { + (*__tmp_15) = __tmp_14; + (*__tmp_15).clone() + } + } + }); + printf!( + b"simple %d %d %d %d\n", + i, + assigned, + a[(0) as usize], + a[(1) as usize] + ); +} +pub fn test_comma_3() { + let x: Value = Rc::new(RefCell::new(10_u32)); + let mut i: i32 = 0; + { + match ( + { 5_u32 }, + &({ + i.prefix_inc(); + x.as_pointer() + }), + ) { + (__tmp_16, __tmp_17) => __tmp_17.with_mut(|__tmp_17| { + (*__tmp_17) = (((*__tmp_17) as u32).wrapping_add((__tmp_16 as u32))) as u32; + }), + } + }; + printf!(b"direct void %d %d\n", i, ((*x.borrow()) as i32)); + let mut result: u32 = ({ + match ( + { 2_u32 }, + &({ + i.prefix_inc(); + x.as_pointer() + }), + ) { + (__tmp_18, __tmp_19) => __tmp_19.with_mut(|__tmp_19| { + (*__tmp_19) = (((*__tmp_19) as u32).wrapping_add((__tmp_18 as u32))) as u32; + (*__tmp_19).clone() + }), + } + }); + printf!( + b"direct compound %d %d %d\n", + i, + (result as i32), + ((*x.borrow()) as i32) + ); + result = ({ + match ( + { 99_u32 }, + &({ + i.prefix_inc(); + x.as_pointer() + }), + ) { + (__tmp_20, __tmp_21) => __tmp_21.with_mut(|__tmp_21| { + (*__tmp_21) = __tmp_20; + (*__tmp_21).clone() + }), + } + }); + printf!( + b"direct simple %d %d %d\n", + i, + (result as i32), + ((*x.borrow()) as i32) + ); + let mut p: Ptr = (x.as_pointer()); + { + match ( + { 5_u32 }, + &({ + i.prefix_inc(); + (p).clone() + }), + ) { + (__tmp_22, __tmp_23) => __tmp_23.with_mut(|__tmp_23| { + (*__tmp_23) = (((*__tmp_23) as u32).wrapping_add((__tmp_22 as u32))) as u32; + }), + } + }; + printf!(b"indirect void %d %d\n", i, ((p.read()) as i32)); + let __rhs = ({ + match ( + { 2_u32 }, + &({ + i.prefix_inc(); + (p).clone() + }), + ) { + (__tmp_24, __tmp_25) => __tmp_25.with_mut(|__tmp_25| { + (*__tmp_25) = (((*__tmp_25) as u32).wrapping_add((__tmp_24 as u32))) as u32; + (*__tmp_25).clone() + }), + } + }); + result = __rhs; + printf!( + b"indirect compound %d %d %d\n", + i, + (result as i32), + ((p.read()) as i32) + ); + let __rhs = ({ + match ( + { 99_u32 }, + &({ + i.prefix_inc(); + (p).clone() + }), + ) { + (__tmp_26, __tmp_27) => __tmp_27.with_mut(|__tmp_27| { + (*__tmp_27) = __tmp_26; + (*__tmp_27).clone() + }), + } + }); + result = __rhs; + printf!( + b"indirect simple %d %d %d\n", + i, + (result as i32), + ((p.read()) as i32) + ); +} +pub fn test_comma_4() { + let x: Value = Rc::new(RefCell::new(10_i16)); + let mut i: i32 = 0; + { + match ( + { 5 }, + &({ + i.prefix_inc(); + x.as_pointer() + }), + ) { + (__tmp_28, __tmp_29) => __tmp_29.with_mut(|__tmp_29| { + (*__tmp_29) = (((*__tmp_29) as i32) + (__tmp_28 as i32)) as i16; + }), + } + }; + printf!(b"direct void %d %d\n", i, ((*x.borrow()) as i32)); + let mut result: i16 = ({ + match ( + { 2 }, + &({ + i.prefix_inc(); + x.as_pointer() + }), + ) { + (__tmp_30, __tmp_31) => __tmp_31.with_mut(|__tmp_31| { + (*__tmp_31) = (((*__tmp_31) as i32) + (__tmp_30 as i32)) as i16; + (*__tmp_31).clone() + }), + } + }); + printf!( + b"direct compound %d %d %d\n", + i, + (result as i32), + ((*x.borrow()) as i32) + ); + result = ({ + match ( + { 99_i16 }, + &({ + i.prefix_inc(); + x.as_pointer() + }), + ) { + (__tmp_32, __tmp_33) => __tmp_33.with_mut(|__tmp_33| { + (*__tmp_33) = __tmp_32; + (*__tmp_33).clone() + }), + } + }); + printf!( + b"direct simple %d %d %d\n", + i, + (result as i32), + ((*x.borrow()) as i32) + ); + let mut p: Ptr = (x.as_pointer()); + { + match ( + { 5 }, + &({ + i.prefix_inc(); + (p).clone() + }), + ) { + (__tmp_34, __tmp_35) => __tmp_35.with_mut(|__tmp_35| { + (*__tmp_35) = (((*__tmp_35) as i32) + (__tmp_34 as i32)) as i16; + }), + } + }; + printf!(b"indirect void %d %d\n", i, ((p.read()) as i32)); + let __rhs = ({ + match ( + { 2 }, + &({ + i.prefix_inc(); + (p).clone() + }), + ) { + (__tmp_36, __tmp_37) => __tmp_37.with_mut(|__tmp_37| { + (*__tmp_37) = (((*__tmp_37) as i32) + (__tmp_36 as i32)) as i16; + (*__tmp_37).clone() + }), + } + }); + result = __rhs; + printf!( + b"indirect compound %d %d %d\n", + i, + (result as i32), + ((p.read()) as i32) + ); + let __rhs = ({ + match ( + { 99_i16 }, + &({ + i.prefix_inc(); + (p).clone() + }), + ) { + (__tmp_38, __tmp_39) => __tmp_39.with_mut(|__tmp_39| { + (*__tmp_39) = __tmp_38; + (*__tmp_39).clone() + }), + } + }); + result = __rhs; + printf!( + b"indirect simple %d %d %d\n", + i, + (result as i32), + ((p.read()) as i32) + ); +} +thread_local!( + pub static global_5: Value = Rc::new(RefCell::new(10)); +); +pub fn observe_global_6(mut assigned: i32) -> i32 { + return (assigned + global_5.with(|rc| *rc.borrow())); +} +pub fn observe_7(mut assigned: i32, mut stored: Ptr) -> i32 { + return ({ assigned } + { (stored.read()) }); +} +pub fn test_borrows_8() { + printf!( + b"%d\n", + ({ + observe_global_6({ + match ({ 99 }, &mut (*global_5.with(Value::clone).borrow_mut())) { + (__tmp_40, __tmp_41) => { + (*__tmp_41) = __tmp_40; + (*__tmp_41).clone() + } + } + }) + }) + ); + printf!( + b"%d\n", + ({ + observe_global_6({ + match ({ 5 }, &mut (*global_5.with(Value::clone).borrow_mut())) { + (__tmp_42, __tmp_43) => { + (*__tmp_43) = (((*__tmp_43) as i32) + (__tmp_42 as i32)) as i32; + (*__tmp_43).clone() + } + } + }) + }) + ); + let local: Value = Rc::new(RefCell::new(10)); + printf!( + b"%d\n", + ({ + let _assigned: i32 = { + match ({ 99 }, &mut (*local.borrow_mut())) { + (__tmp_44, __tmp_45) => { + (*__tmp_45) = __tmp_44; + (*__tmp_45).clone() + } + } + }; + let _stored: Ptr = (local.as_pointer()); + observe_7(_assigned, _stored) + }) + ); + printf!( + b"%d\n", + ({ + let _assigned: i32 = { + match ({ 5 }, &mut (*local.borrow_mut())) { + (__tmp_46, __tmp_47) => { + (*__tmp_47) = (((*__tmp_47) as i32) + (__tmp_46 as i32)) as i32; + (*__tmp_47).clone() + } + } + }; + let _stored: Ptr = (local.as_pointer()); + observe_7(_assigned, _stored) + }) + ); + let record: Value = Rc::new(RefCell::new(Record_9 { value: 10 })); + printf!( + b"%d\n", + ({ + let _assigned: i32 = { + match ({ 99 }, &mut ((*record.borrow_mut()).value)) { + (__tmp_48, __tmp_49) => { + (*__tmp_49) = __tmp_48; + (*__tmp_49).clone() + } + } + }; + let _stored: Ptr = (field_ptr!(record.as_pointer(), value)); + observe_7(_assigned, _stored) + }) + ); + printf!( + b"%d\n", + ({ + let _assigned: i32 = { + match ({ 5 }, &mut ((*record.borrow_mut()).value)) { + (__tmp_50, __tmp_51) => { + (*__tmp_51) = (((*__tmp_51) as i32) + (__tmp_50 as i32)) as i32; + (*__tmp_51).clone() + } + } + }; + let _stored: Ptr = (field_ptr!(record.as_pointer(), value)); + observe_7(_assigned, _stored) + }) + ); + let values: Value> = Rc::new(RefCell::new(vec![10; 1_usize])); + printf!( + b"%d\n", + ({ + let _assigned: i32 = { + match ({ 99 }, &mut ((*values.borrow_mut())[0_usize])) { + (__tmp_52, __tmp_53) => { + (*__tmp_53) = __tmp_52; + (*__tmp_53).clone() + } + } + }; + let _stored: Ptr = (values.decay().offset(0_usize)); + observe_7(_assigned, _stored) + }) + ); + printf!( + b"%d\n", + ({ + let _assigned: i32 = { + match ({ 5 }, &mut ((*values.borrow_mut())[0_usize])) { + (__tmp_54, __tmp_55) => { + (*__tmp_55) = (((*__tmp_55) as i32) + (__tmp_54 as i32)) as i32; + (*__tmp_55).clone() + } + } + }; + let _stored: Ptr = (values.decay().offset(0_usize)); + observe_7(_assigned, _stored) + }) + ); +} +#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(4)] +pub struct Record_9 { + #[offset(0)] + pub value: i32, +} +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + ({ test_0() }); + ({ test_1() }); + ({ test_2() }); + ({ test_comma_3() }); + ({ test_comma_4() }); + let values: Value> = Rc::new(RefCell::new(Box::new([10_u32, 20_u32]))); + let ref_: Ptr = values.decay(); + let mut i: i32 = 0; + let mut result: u32 = ({ + match ( + { 5_u32 }, + &(elem!( + { + i.prefix_inc(); + (ref_).clone() + }, + 0 + )), + ) { + (__tmp_56, __tmp_57) => __tmp_57.with_mut(|__tmp_57| { + (*__tmp_57) = (((*__tmp_57) as u32).wrapping_add((__tmp_56 as u32))) as u32; + (*__tmp_57).clone() + }), + } + }); + printf!( + b"array reference %d %u %u\n", + i, + result, + (*values.borrow())[(0) as usize] + ); + ({ test_borrows_8() }); + return 0; +} +pub fn __cpp2rust_init_globals() { + let _ = global_5.with(|_| ()); +} diff --git a/tests/unit/out/refcount/compound_assign_paren.rs b/tests/unit/out/refcount/compound_assign_paren.rs index eba87b7b6c..7b311ac7df 100644 --- a/tests/unit/out/refcount/compound_assign_paren.rs +++ b/tests/unit/out/refcount/compound_assign_paren.rs @@ -19,23 +19,61 @@ pub fn main() { fn main_0() -> i32 { let item: Value = Rc::new(RefCell::new(Item { flags: 0_u8 })); let mut ptr: Ptr = (item.as_pointer()); - field!((ptr), flags).write({ (((ptr).with(|__s| __s.flags) as i32) | (1 << 0)) as u8 }); - field!((ptr), flags).write({ (((ptr).with(|__s| __s.flags) as i32) | (1 << 1)) as u8 }); + { + match ({ (1 << 0) }, &(field!((ptr), flags))) { + (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { + (*__tmp_1) = (((*__tmp_1) as i32) | (__tmp_0 as i32)) as u8; + }), + } + }; + { + match ({ (1 << 1) }, &(field!((ptr), flags))) { + (__tmp_2, __tmp_3) => __tmp_3.with_mut(|__tmp_3| { + (*__tmp_3) = (((*__tmp_3) as i32) | (__tmp_2 as i32)) as u8; + }), + } + }; assert!(((ptr.with(|__s| __s.flags) as i32) == 3)); - field!((ptr), flags) - .write({ (((ptr).with(|__s| __s.flags) as i32) & ((!(1 << 0) as u8) as i32)) as u8 }); + { + match ({ ((!(1 << 0) as u8) as i32) }, &(field!((ptr), flags))) { + (__tmp_4, __tmp_5) => __tmp_5.with_mut(|__tmp_5| { + (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) as u8; + }), + } + }; assert!(((ptr.with(|__s| __s.flags) as i32) == 2)); let mut bits: [u8; 4] = [0_u8; 4]; - (bits)[((5) / 8) as usize] = - { (((bits)[((5) / 8) as usize] as i32) | (((1 << ((5) & 7)) as u8) as i32)) as u8 }; - (bits)[((13) / 8) as usize] = - { (((bits)[((13) / 8) as usize] as i32) | (((1 << ((13) & 7)) as u8) as i32)) as u8 }; + { + match ( + { (((1 << ((5) & 7)) as u8) as i32) }, + &mut ((bits)[((5) / 8) as usize]), + ) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as i32) | (__tmp_6 as i32)) as u8; + } + } + }; + { + match ( + { (((1 << ((13) & 7)) as u8) as i32) }, + &mut ((bits)[((13) / 8) as usize]), + ) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as i32) | (__tmp_8 as i32)) as u8; + } + } + }; assert!(((bits[(0) as usize] as i32) == 32)); assert!(((bits[(1) as usize] as i32) == 32)); assert!(((bits[(2) as usize] as i32) == 0)); if ((ptr.with(|__s| __s.flags) as i32) != 0) { - field!((ptr), flags) - .write({ (((ptr).with(|__s| __s.flags) as i32) & ((!(1 << 1) as u8) as i32)) as u8 }); + { + match ({ ((!(1 << 1) as u8) as i32) }, &(field!((ptr), flags))) { + (__tmp_10, __tmp_11) => __tmp_11.with_mut(|__tmp_11| { + (*__tmp_11) = (((*__tmp_11) as i32) & (__tmp_10 as i32)) as u8; + }), + } + }; } assert!(((ptr.with(|__s| __s.flags) as i32) == 0)); return 0; diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index fc5ac5d32c..c94d6eb46a 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -292,8 +292,12 @@ fn main_0() -> i32 { let g: Value = Rc::new(RefCell::new(Explicit::new({ 4 }))); let _dtor_g = std::mem::DropGuard::new(g.clone(), |__p| __p.as_pointer().destructor()); (*g.borrow_mut()) = { - (*e.borrow_mut()) = (*f.borrow()).clone(); - (*e.borrow()).clone() + match ({ (*f.borrow()).clone() }, &mut (*e.borrow_mut())) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } }; assert!( ({ same_0(g.as_pointer(), f.as_pointer(),) }) @@ -382,8 +386,8 @@ fn main_0() -> i32 { (*bufs.borrow_mut()).push(__a1) }; { - let mut __tmp_2 = { Buffer::move_from({ bufs.decay().offset(0_usize) }) }; - (*bufs.borrow_mut()).push(__tmp_2); + let mut __tmp_4 = { Buffer::move_from({ bufs.decay().offset(0_usize) }) }; + (*bufs.borrow_mut()).push(__tmp_4); }; assert!( ({ diff --git a/tests/unit/out/refcount/destructor.rs b/tests/unit/out/refcount/destructor.rs index 034b8813ec..1cf63cee9a 100644 --- a/tests/unit/out/refcount/destructor.rs +++ b/tests/unit/out/refcount/destructor.rs @@ -277,12 +277,16 @@ pub trait Templated_char_Impl { } impl Templated_char_Impl for Ptr { fn destructor(&self) { - global_0.with(|rc| { - *rc.borrow_mut() = { - ((global_0.with(|rc| *rc.borrow()) as usize) - .wrapping_add((::std::mem::size_of::() as usize))) as i32 + { + match ( + { ::std::mem::size_of::() }, + &mut (*global_0.with(Value::clone).borrow_mut()), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as usize).wrapping_add((__tmp_0 as usize))) as i32; + } } - }); + }; } } pub trait Templated_int_Impl { @@ -290,12 +294,16 @@ pub trait Templated_int_Impl { } impl Templated_int_Impl for Ptr { fn destructor(&self) { - global_0.with(|rc| { - *rc.borrow_mut() = { - ((global_0.with(|rc| *rc.borrow()) as usize) - .wrapping_add((::std::mem::size_of::() as usize))) as i32 + { + match ( + { ::std::mem::size_of::() }, + &mut (*global_0.with(Value::clone).borrow_mut()), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (((*__tmp_3) as usize).wrapping_add((__tmp_2 as usize))) as i32; + } } - }); + }; } } pub fn __cpp2rust_init_globals() { diff --git a/tests/unit/out/refcount/expr_as_bool_c.rs b/tests/unit/out/refcount/expr_as_bool_c.rs index 2a413f6ae9..2ee65e00d9 100644 --- a/tests/unit/out/refcount/expr_as_bool_c.rs +++ b/tests/unit/out/refcount/expr_as_bool_c.rs @@ -23,13 +23,21 @@ fn main_0() -> i32 { let mut a: i32 = 0; let mut b: i32 = 0_i32; if ({ - b = a; - b + match ({ a }, &mut (b)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } + } } != 0) {} 'loop_: while (({ - b = a; - b + match ({ a }, &mut (b)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } }) != 0) {} if (a != 0) {} @@ -38,18 +46,30 @@ fn main_0() -> i32 { assert!((a == b)); assert!( !(({ - a = b; - a + match ({ b }, &mut (a)) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } }) != 0) ); let mut c: bool = false; c = ({ - a = b; - a + match ({ b }, &mut (a)) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = __tmp_6; + (*__tmp_7).clone() + } + } } != 0); c = (({ - b = a; - b + match ({ a }, &mut (b)) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = __tmp_8; + (*__tmp_9).clone() + } + } }) != 0); c = (a != 0); c = (a == b); diff --git a/tests/unit/out/refcount/expr_as_bool_cpp.rs b/tests/unit/out/refcount/expr_as_bool_cpp.rs index 54e2aebc73..1acb1dd5df 100644 --- a/tests/unit/out/refcount/expr_as_bool_cpp.rs +++ b/tests/unit/out/refcount/expr_as_bool_cpp.rs @@ -23,13 +23,21 @@ fn main_0() -> i32 { let mut a: i32 = 0; let mut b: i32 = 0_i32; if ({ - b = a; - b + match ({ a }, &mut (b)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } + } } != 0) {} 'loop_: while (({ - b = a; - b + match ({ a }, &mut (b)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } }) != 0) {} if (a != 0) {} @@ -38,18 +46,30 @@ fn main_0() -> i32 { assert!((a == b)); assert!( !(({ - a = b; - a + match ({ b }, &mut (a)) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + } }) != 0) ); let mut c: bool = false; c = ({ - a = b; - a + match ({ b }, &mut (a)) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = __tmp_6; + (*__tmp_7).clone() + } + } } != 0); c = (({ - b = a; - b + match ({ a }, &mut (b)) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = __tmp_8; + (*__tmp_9).clone() + } + } }) != 0); c = (a != 0); c = (a == b); diff --git a/tests/unit/out/refcount/field_pointers_malloced_struct.rs b/tests/unit/out/refcount/field_pointers_malloced_struct.rs index dc4b1b0639..e654ce2f19 100644 --- a/tests/unit/out/refcount/field_pointers_malloced_struct.rs +++ b/tests/unit/out/refcount/field_pointers_malloced_struct.rs @@ -51,15 +51,23 @@ fn main_0() -> i32 { assert!((s.with(|__s| __s.a) == 5) && (s.with(|__s| __s.c) == 1)); let mut x: i32 = ({ s.with(|__s| __s.a) } + { ({ - field!(s, b).write(3); - s.with(|__s| __s.b) + match ({ 3 }, &(field!(s, b))) { + (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + }), + } }) }); assert!((x == 8) && (s.with(|__s| __s.b) == 3)); let mut y: i32 = 0; let __rhs = ({ - y = 99; - y + match ({ 99 }, &mut (y)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } }); field!(s, c).write(__rhs); assert!((s.with(|__s| __s.c) == 99) && (y == 99)); diff --git a/tests/unit/out/refcount/fn_ptr.rs b/tests/unit/out/refcount/fn_ptr.rs index 6d2d59afd4..e1f5031064 100644 --- a/tests/unit/out/refcount/fn_ptr.rs +++ b/tests/unit/out/refcount/fn_ptr.rs @@ -16,7 +16,13 @@ pub fn twice_2(mut x: u64) -> u64 { return (x).wrapping_mul(2_u64); } pub fn twice_in_place_3(x: Ptr) -> u64 { - x.write({ (x.read()).wrapping_mul(2_u64) }); + { + match ({ 2_u64 }, &(x)) { + (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { + (*__tmp_1) = (((*__tmp_1) as u64).wrapping_mul((__tmp_0 as u64))) as u64; + }), + } + }; return (x.read()); } pub fn ret_size_4(mut v: i32) -> usize { @@ -86,10 +92,10 @@ fn main_0() -> i32 { assert!(({ ((*m.borrow()) == 42_usize) })); assert!((({ call_fn_5(FnPtr:: usize>::new(ret_size_4), 3,) }) == 8_usize)); let mut hh: HashHolder_unsigned_long__ptr__bool__ = { - let __tmp_0: Value u64>> = Rc::new(RefCell::new( + let __tmp_2: Value u64>> = Rc::new(RefCell::new( (FnPtr:: usize>::new(identity_hash_6)).cast:: u64>(), )); - HashHolder_unsigned_long__ptr__bool__::new({ __tmp_0.as_pointer() }) + HashHolder_unsigned_long__ptr__bool__::new({ __tmp_2.as_pointer() }) }; assert!((({ hh.h.call(true,) }) == 1_u64)); let mut handler: FnPtr = FnPtr::::new(add_to_total_8); diff --git a/tests/unit/out/refcount/global_call_temporaries.rs b/tests/unit/out/refcount/global_call_temporaries.rs index 6beec818a6..9d97328416 100644 --- a/tests/unit/out/refcount/global_call_temporaries.rs +++ b/tests/unit/out/refcount/global_call_temporaries.rs @@ -36,60 +36,78 @@ thread_local!( ); thread_local!( pub static assigned_4: Value = Rc::new(RefCell::new({ - let __tmp_2: Value; - let __tmp_3: Value; + let __tmp_4: Value; + let __tmp_5: Value; ({ - { - let __rhs = { - __tmp_2 = Rc::new(RefCell::new(6)); - __tmp_3 = Rc::new(RefCell::new(5)); - (if CppLess::less(&__tmp_2.as_pointer(), &__tmp_3.as_pointer()) { - __tmp_2.as_pointer() - } else { - __tmp_3.as_pointer() + match ( + { + { + __tmp_4 = Rc::new(RefCell::new(6)); + __tmp_5 = Rc::new(RefCell::new(5)); + (if CppLess::less(&__tmp_4.as_pointer(), &__tmp_5.as_pointer()) { + __tmp_4.as_pointer() + } else { + __tmp_5.as_pointer() + } + .read()) } - .read()) - }; - x_2.with(|rc| *rc.borrow_mut() = __rhs) - }; - x_2.with(|rc| *rc.borrow()) + }, + &mut (*x_2.with(Value::clone).borrow_mut()), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } }) })); ); thread_local!( pub static accumulated_5: Value = Rc::new(RefCell::new({ - let __tmp_4: Value; - let __tmp_5: Value; + let __tmp_8: Value; + let __tmp_9: Value; ({ - { - let __rhs = { - __tmp_4 = Rc::new(RefCell::new(1)); - __tmp_5 = Rc::new(RefCell::new(2)); - (if CppLess::less(&__tmp_4.as_pointer(), &__tmp_5.as_pointer()) { - __tmp_5.as_pointer() - } else { - __tmp_4.as_pointer() + match ( + { + { + __tmp_8 = Rc::new(RefCell::new(1)); + __tmp_9 = Rc::new(RefCell::new(2)); + (if CppLess::less(&__tmp_8.as_pointer(), &__tmp_9.as_pointer()) { + __tmp_9.as_pointer() + } else { + __tmp_8.as_pointer() + } + .read()) } - .read()) - }; - y_3.with(|rc| *rc.borrow_mut() += __rhs) - }; - y_3.with(|rc| *rc.borrow()) + }, + &mut (*y_3.with(Value::clone).borrow_mut()), + ) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as i32) + (__tmp_6 as i32)) as i32; + (*__tmp_7).clone() + } + } }) })); ); thread_local!( pub static call_assigned_6: Value = Rc::new(RefCell::new({ - let __tmp_6: Value; + let __tmp_12: Value; ({ - { - let __rhs = ({ - __tmp_6 = Rc::new(RefCell::new(5)); - read_0(__tmp_6.as_pointer()) - }); - x_2.with(|rc| *rc.borrow_mut() = __rhs) - }; - x_2.with(|rc| *rc.borrow()) + match ( + { + ({ + __tmp_12 = Rc::new(RefCell::new(5)); + read_0(__tmp_12.as_pointer()) + }) + }, + &mut (*x_2.with(Value::clone).borrow_mut()), + ) { + (__tmp_10, __tmp_11) => { + (*__tmp_11) = __tmp_10; + (*__tmp_11).clone() + } + } }) })); ); @@ -107,38 +125,38 @@ pub fn read_record_8(value: Ptr) -> i32 { } thread_local!( pub static aggregate_selected_9: Value = Rc::new(RefCell::new({ - let __tmp_8: Value; - let __tmp_9: Value; - let __tmp_7: Value>; - let __tmp_11: Value; - let __tmp_12: Value; - let __tmp_10: Value; + let __tmp_14: Value; + let __tmp_15: Value; + let __tmp_13: Value>; + let __tmp_17: Value; + let __tmp_18: Value; + let __tmp_16: Value; (({ - __tmp_7 = Rc::new(RefCell::new(Box::new([{ - __tmp_8 = Rc::new(RefCell::new(4)); - __tmp_9 = Rc::new(RefCell::new(3)); - (if CppLess::less(&__tmp_8.as_pointer(), &__tmp_9.as_pointer()) { - __tmp_8.as_pointer() + __tmp_13 = Rc::new(RefCell::new(Box::new([{ + __tmp_14 = Rc::new(RefCell::new(4)); + __tmp_15 = Rc::new(RefCell::new(3)); + (if CppLess::less(&__tmp_14.as_pointer(), &__tmp_15.as_pointer()) { + __tmp_14.as_pointer() } else { - __tmp_9.as_pointer() + __tmp_15.as_pointer() } .read()) }]))); - read_array_7(__tmp_7.decay()) + read_array_7(__tmp_13.decay()) }) + ({ - __tmp_10 = Rc::new(RefCell::new(Item { + __tmp_16 = Rc::new(RefCell::new(Item { value: { - __tmp_11 = Rc::new(RefCell::new(5)); - __tmp_12 = Rc::new(RefCell::new(6)); - (if CppLess::less(&__tmp_11.as_pointer(), &__tmp_12.as_pointer()) { - __tmp_12.as_pointer() + __tmp_17 = Rc::new(RefCell::new(5)); + __tmp_18 = Rc::new(RefCell::new(6)); + (if CppLess::less(&__tmp_17.as_pointer(), &__tmp_18.as_pointer()) { + __tmp_18.as_pointer() } else { - __tmp_11.as_pointer() + __tmp_17.as_pointer() } .read()) }, })); - read_record_8(__tmp_10.as_pointer()) + read_record_8(__tmp_16.as_pointer()) })) })); ); @@ -150,12 +168,12 @@ thread_local!( ); thread_local!( pub static mapped_selected_12: Value = { - let __tmp_13: Value; + let __tmp_19: Value; Rc::new(RefCell::new( (({ - __tmp_13 = Rc::new(RefCell::new((right_11.with(|rc| *rc.borrow()) as u64))); - (if CppLess::less(&__tmp_13.as_pointer(), &left_10.with(|v| v.as_pointer())) { - __tmp_13.as_pointer() + __tmp_19 = Rc::new(RefCell::new((right_11.with(|rc| *rc.borrow()) as u64))); + (if CppLess::less(&__tmp_19.as_pointer(), &left_10.with(|v| v.as_pointer())) { + __tmp_19.as_pointer() } else { left_10.with(|v| v.as_pointer()) } @@ -169,12 +187,12 @@ pub fn get_13() -> usize { } thread_local!( static value_14: Value = { - let __tmp_14: Value; + let __tmp_20: Value; Rc::new(RefCell::new( (({ - __tmp_14 = Rc::new(RefCell::new((right_11.with(|rc| *rc.borrow()) as u64))); - (if CppLess::less(&left_10.with(|v| v.as_pointer()), &__tmp_14.as_pointer()) { - __tmp_14.as_pointer() + __tmp_20 = Rc::new(RefCell::new((right_11.with(|rc| *rc.borrow()) as u64))); + (if CppLess::less(&left_10.with(|v| v.as_pointer()), &__tmp_20.as_pointer()) { + __tmp_20.as_pointer() } else { left_10.with(|v| v.as_pointer()) } @@ -200,38 +218,38 @@ fn main_0() -> i32 { } thread_local!( static aggregate_static_15: Value = Rc::new(RefCell::new({ - let __tmp_16: Value; - let __tmp_17: Value; - let __tmp_15: Value>; - let __tmp_19: Value; - let __tmp_20: Value; - let __tmp_18: Value; + let __tmp_22: Value; + let __tmp_23: Value; + let __tmp_21: Value>; + let __tmp_25: Value; + let __tmp_26: Value; + let __tmp_24: Value; (({ - __tmp_15 = Rc::new(RefCell::new(Box::new([{ - __tmp_16 = Rc::new(RefCell::new(7)); - __tmp_17 = Rc::new(RefCell::new(8)); - (if CppLess::less(&__tmp_16.as_pointer(), &__tmp_17.as_pointer()) { - __tmp_17.as_pointer() + __tmp_21 = Rc::new(RefCell::new(Box::new([{ + __tmp_22 = Rc::new(RefCell::new(7)); + __tmp_23 = Rc::new(RefCell::new(8)); + (if CppLess::less(&__tmp_22.as_pointer(), &__tmp_23.as_pointer()) { + __tmp_23.as_pointer() } else { - __tmp_16.as_pointer() + __tmp_22.as_pointer() } .read()) }]))); - read_array_7(__tmp_15.decay()) + read_array_7(__tmp_21.decay()) }) + ({ - __tmp_18 = Rc::new(RefCell::new(Item { + __tmp_24 = Rc::new(RefCell::new(Item { value: { - __tmp_19 = Rc::new(RefCell::new(10)); - __tmp_20 = Rc::new(RefCell::new(9)); - (if CppLess::less(&__tmp_19.as_pointer(), &__tmp_20.as_pointer()) { - __tmp_19.as_pointer() + __tmp_25 = Rc::new(RefCell::new(10)); + __tmp_26 = Rc::new(RefCell::new(9)); + (if CppLess::less(&__tmp_25.as_pointer(), &__tmp_26.as_pointer()) { + __tmp_25.as_pointer() } else { - __tmp_20.as_pointer() + __tmp_26.as_pointer() } .read()) }, })); - read_record_8(__tmp_18.as_pointer()) + read_record_8(__tmp_24.as_pointer()) })) })); ); diff --git a/tests/unit/out/refcount/immutable_unsigned_arithmetic.rs b/tests/unit/out/refcount/immutable_unsigned_arithmetic.rs index 43533e43c9..ed54398411 100644 --- a/tests/unit/out/refcount/immutable_unsigned_arithmetic.rs +++ b/tests/unit/out/refcount/immutable_unsigned_arithmetic.rs @@ -13,7 +13,13 @@ pub fn main() { fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(0_u32)); let mut p: Ptr = (a.as_pointer()); - p.write({ (p.read()).wrapping_add((p.read())) }); + { + match ({ (p.read()) }, &(p)) { + (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { + (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; + }), + } + }; return ((p.read()) as i32); } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/inet_pton_ntop.rs b/tests/unit/out/refcount/inet_pton_ntop.rs index b855b288c8..2d455589c9 100644 --- a/tests/unit/out/refcount/inet_pton_ntop.rs +++ b/tests/unit/out/refcount/inet_pton_ntop.rs @@ -30,8 +30,13 @@ pub fn test_s6_addr_access_0() { ((((elem!(In6Addr::s6_addr(addr.as_pointer()), 0).read()) as i32) == 32) && (((elem!(In6Addr::s6_addr((ap).clone()), 1).read()) as i32) == 1)) ); - elem!(In6Addr::s6_addr(addr.as_pointer()), 15) - .write({ (((elem!(In6Addr::s6_addr(addr.as_pointer()), 15).read()) as i32) + 4) as u8 }); + { + match ({ 4 }, &(elem!(In6Addr::s6_addr(addr.as_pointer()), 15))) { + (__tmp_1, __tmp_2) => __tmp_2.with_mut(|__tmp_2| { + (*__tmp_2) = (((*__tmp_2) as i32) + (__tmp_1 as i32)) as u8; + }), + } + }; elem!(In6Addr::s6_addr((ap).clone()), 15).with_mut(|__v| __v.postfix_inc()); assert!((((elem!(In6Addr::s6_addr(addr.as_pointer()), 15).read()) as i32) == 6)); let mut bytes: Ptr = In6Addr::s6_addr(addr.as_pointer()); @@ -41,9 +46,9 @@ pub fn test_s6_addr_access_0() { fourth.write(8_u8); assert!((((elem!(In6Addr::s6_addr(addr.as_pointer()), 3).read()) as i32) == 8)); { - let mut __tmp_1 = { (In6Addr::s6_addr((ap).clone())).to_any() }; - __tmp_1.memcpy(&(loopback.decay()).to_any(), 16_usize); - (__tmp_1).clone() + let mut __tmp_3 = { (In6Addr::s6_addr((ap).clone())).to_any() }; + __tmp_3.memcpy(&(loopback.decay()).to_any(), 16_usize); + (__tmp_3).clone() }; assert!( ((In6Addr::s6_addr(addr.as_pointer())) @@ -61,14 +66,14 @@ fn main_0() -> i32 { let buf: Value> = Rc::new(RefCell::new((0..16).map(|_| 0_u8).collect::>())); assert!( ({ - let mut __tmp_2 = { (buf.decay()).to_any() }; + let mut __tmp_4 = { (buf.decay()).to_any() }; if libc::AF_INET == libc::AF_INET { // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"1.2.3.4").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_2 + __tmp_4 .reinterpret_cast::() .with_slice_mut(4, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -80,7 +85,7 @@ fn main_0() -> i32 { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_2 + __tmp_4 .reinterpret_cast::() .with_slice_mut(16, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -103,14 +108,14 @@ fn main_0() -> i32 { ); assert!( ({ - let mut __tmp_3 = { (buf.decay()).to_any() }; + let mut __tmp_5 = { (buf.decay()).to_any() }; if libc::AF_INET == libc::AF_INET { // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"999.1.1.1").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_3 + __tmp_5 .reinterpret_cast::() .with_slice_mut(4, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -122,7 +127,7 @@ fn main_0() -> i32 { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_3 + __tmp_5 .reinterpret_cast::() .with_slice_mut(16, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -137,14 +142,14 @@ fn main_0() -> i32 { ); assert!( ({ - let mut __tmp_4 = { (buf.decay()).to_any() }; + let mut __tmp_6 = { (buf.decay()).to_any() }; if libc::AF_INET == libc::AF_INET { // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"not an ip").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_4 + __tmp_6 .reinterpret_cast::() .with_slice_mut(4, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -156,7 +161,7 @@ fn main_0() -> i32 { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_4 + __tmp_6 .reinterpret_cast::() .with_slice_mut(16, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -171,14 +176,14 @@ fn main_0() -> i32 { ); assert!( ({ - let mut __tmp_5 = { (buf.decay()).to_any() }; + let mut __tmp_7 = { (buf.decay()).to_any() }; if libc::AF_INET6 == libc::AF_INET { // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"::1").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_5 + __tmp_7 .reinterpret_cast::() .with_slice_mut(4, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -190,7 +195,7 @@ fn main_0() -> i32 { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_5 + __tmp_7 .reinterpret_cast::() .with_slice_mut(16, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -211,14 +216,14 @@ fn main_0() -> i32 { ); assert!( ({ - let mut __tmp_6 = { (buf.decay()).to_any() }; + let mut __tmp_8 = { (buf.decay()).to_any() }; if libc::AF_INET6 == libc::AF_INET { // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"2001:db8::5").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_6 + __tmp_8 .reinterpret_cast::() .with_slice_mut(4, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -230,7 +235,7 @@ fn main_0() -> i32 { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_6 + __tmp_8 .reinterpret_cast::() .with_slice_mut(16, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -256,15 +261,15 @@ fn main_0() -> i32 { assert!( ({ let mut __it1 = { - let mut __tmp_7 = { (four.decay()).to_any() }; - let mut __tmp_8 = { text.decay() }; + let mut __tmp_9 = { (four.decay()).to_any() }; + let mut __tmp_10 = { text.decay() }; let __text = if libc::AF_INET == libc::AF_INET { - let __b: [u8; 4] = __tmp_7 + let __b: [u8; 4] = __tmp_9 .reinterpret_cast::() .with_slice(4, |__s| __s.try_into().unwrap()); Some(std::net::Ipv4Addr::from(__b).to_string()) } else if libc::AF_INET == libc::AF_INET6 { - let __b: [u8; 16] = __tmp_7 + let __b: [u8; 16] = __tmp_9 .reinterpret_cast::() .with_slice(16, |__s| __s.try_into().unwrap()); Some(std::net::Ipv6Addr::from(__b).to_string()) @@ -277,9 +282,9 @@ fn main_0() -> i32 { < (::std::mem::size_of::<[i8; 64]>() as libc::socklen_t) => { let __n = __s.len(); - __tmp_8.write_c_bytes(__s.as_bytes()); - elem!(__tmp_8, __n).write(0); - (__tmp_8).clone() + __tmp_10.write_c_bytes(__s.as_bytes()); + elem!(__tmp_10, __n).write(0); + (__tmp_10).clone() } Some(_) => { libcc2rs::cpp2rust_errno().write(::libc::ENOSPC); @@ -310,15 +315,15 @@ fn main_0() -> i32 { assert!( ({ let mut __it1 = { - let mut __tmp_9 = { (sixteen.decay()).to_any() }; - let mut __tmp_10 = { text.decay() }; + let mut __tmp_11 = { (sixteen.decay()).to_any() }; + let mut __tmp_12 = { text.decay() }; let __text = if libc::AF_INET6 == libc::AF_INET { - let __b: [u8; 4] = __tmp_9 + let __b: [u8; 4] = __tmp_11 .reinterpret_cast::() .with_slice(4, |__s| __s.try_into().unwrap()); Some(std::net::Ipv4Addr::from(__b).to_string()) } else if libc::AF_INET6 == libc::AF_INET6 { - let __b: [u8; 16] = __tmp_9 + let __b: [u8; 16] = __tmp_11 .reinterpret_cast::() .with_slice(16, |__s| __s.try_into().unwrap()); Some(std::net::Ipv6Addr::from(__b).to_string()) @@ -331,9 +336,9 @@ fn main_0() -> i32 { < (::std::mem::size_of::<[i8; 64]>() as libc::socklen_t) => { let __n = __s.len(); - __tmp_10.write_c_bytes(__s.as_bytes()); - elem!(__tmp_10, __n).write(0); - (__tmp_10).clone() + __tmp_12.write_c_bytes(__s.as_bytes()); + elem!(__tmp_12, __n).write(0); + (__tmp_12).clone() } Some(_) => { libcc2rs::cpp2rust_errno().write(::libc::ENOSPC); @@ -361,15 +366,15 @@ fn main_0() -> i32 { ); assert!( (({ - let mut __tmp_11 = { (four.decay()).to_any() }; - let mut __tmp_12 = { text.decay() }; + let mut __tmp_13 = { (four.decay()).to_any() }; + let mut __tmp_14 = { text.decay() }; let __text = if libc::AF_INET == libc::AF_INET { - let __b: [u8; 4] = __tmp_11 + let __b: [u8; 4] = __tmp_13 .reinterpret_cast::() .with_slice(4, |__s| __s.try_into().unwrap()); Some(std::net::Ipv4Addr::from(__b).to_string()) } else if libc::AF_INET == libc::AF_INET6 { - let __b: [u8; 16] = __tmp_11 + let __b: [u8; 16] = __tmp_13 .reinterpret_cast::() .with_slice(16, |__s| __s.try_into().unwrap()); Some(std::net::Ipv6Addr::from(__b).to_string()) @@ -379,9 +384,9 @@ fn main_0() -> i32 { match __text { Some(__s) if (__s.len() as u32) < (4 as libc::socklen_t) => { let __n = __s.len(); - __tmp_12.write_c_bytes(__s.as_bytes()); - elem!(__tmp_12, __n).write(0); - (__tmp_12).clone() + __tmp_14.write_c_bytes(__s.as_bytes()); + elem!(__tmp_14, __n).write(0); + (__tmp_14).clone() } Some(_) => { libcc2rs::cpp2rust_errno().write(::libc::ENOSPC); diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index 6f97f26588..6cd9cf4d02 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -221,7 +221,13 @@ fn main_0() -> i32 { k.prefix_inc(); } } - c.write({ (((c.read()) as i32) + 5) as i16 }); + { + match ({ 5 }, &(c)) { + (__tmp_2, __tmp_3) => __tmp_3.with_mut(|__tmp_3| { + (*__tmp_3) = (((*__tmp_3) as i32) + (__tmp_2 as i32)) as i16; + }), + } + }; id.write(11); (*s.borrow_mut()).count = 3; assert!( diff --git a/tests/unit/out/refcount/lambda_generic.rs b/tests/unit/out/refcount/lambda_generic.rs index dd8ba5dac1..55edb96118 100644 --- a/tests/unit/out/refcount/lambda_generic.rs +++ b/tests/unit/out/refcount/lambda_generic.rs @@ -55,7 +55,13 @@ fn main_0() -> i32 { }; }, |mut x: u32, mut y: u32| { - total.write({ (((total.read()) as u32).wrapping_add((x).wrapping_mul(y))) as i32 }); + { + match ({ (x).wrapping_mul(y) }, &(total)) { + (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { + (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as i32; + }), + } + }; } ))); ({ (*accumulate.borrow()).spec::(0).call(2, 3) }); diff --git a/tests/unit/out/refcount/lambda_generic_explicit_args.rs b/tests/unit/out/refcount/lambda_generic_explicit_args.rs index 0933e93300..a80638a898 100644 --- a/tests/unit/out/refcount/lambda_generic_explicit_args.rs +++ b/tests/unit/out/refcount/lambda_generic_explicit_args.rs @@ -27,22 +27,36 @@ fn main_0() -> i32 { let total: Ptr = total.as_pointer(); }, || { - total.write({ - (((total.read()) as usize).wrapping_add( - ((::std::mem::size_of::() as usize) - .wrapping_add((::std::mem::size_of::() as usize)) - as usize), - )) as i32 - }); + { + match ( + { + (::std::mem::size_of::() as usize) + .wrapping_add((::std::mem::size_of::() as usize)) + }, + &(total), + ) { + (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { + (*__tmp_1) = + (((*__tmp_1) as usize).wrapping_add((__tmp_0 as usize))) as i32; + }), + } + }; }, || { - total.write({ - (((total.read()) as usize).wrapping_add( - ((::std::mem::size_of::() as usize) - .wrapping_add((::std::mem::size_of::() as usize)) - as usize), - )) as i32 - }); + { + match ( + { + (::std::mem::size_of::() as usize) + .wrapping_add((::std::mem::size_of::() as usize)) + }, + &(total), + ) { + (__tmp_2, __tmp_3) => __tmp_3.with_mut(|__tmp_3| { + (*__tmp_3) = + (((*__tmp_3) as usize).wrapping_add((__tmp_2 as usize))) as i32; + }), + } + }; } ))); ({ (*tally.borrow()).spec::(0).call() }); diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index 2e7f91d5b6..4a7631ba90 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -76,86 +76,152 @@ fn main_0() -> i32 { (__tmp_0,) => ({ (*m.borrow_mut()).subscript(__tmp_0, || 0_i32) }), } .write(10); - ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == 1) as i32)) != 0 }; + { + match ( + { ((copies_0.with(|rc| *rc.borrow()) == 1) as i32) }, + &mut (ok), + ) { + (__tmp_1, __tmp_2) => { + (*__tmp_2) = (((*__tmp_2) as i32) & (__tmp_1 as i32)) != 0; + } + } + }; match (b.as_pointer(),) { - (__tmp_1,) => ({ (*m.borrow_mut()).subscript(__tmp_1, || 0_i32) }), + (__tmp_3,) => ({ (*m.borrow_mut()).subscript(__tmp_3, || 0_i32) }), } .write(20); - ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; + { + match ( + { ((copies_0.with(|rc| *rc.borrow()) == 2) as i32) }, + &mut (ok), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) != 0; + } + } + }; match (a.as_pointer(),) { - (__tmp_2,) => ({ (*m.borrow_mut()).subscript(__tmp_2, || 0_i32) }), + (__tmp_6,) => ({ (*m.borrow_mut()).subscript(__tmp_6, || 0_i32) }), } .write(11); - ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; { - let rhs_0 = ((ok as i32) - & (((*(*m - .as_pointer() - .with(|__m: &Map, Value)>| __m.find(&a.as_pointer())) - .iter_deref() - .upgrade() - .deref()) - .1 - .borrow()) - == 11) as i32)) - != 0; - ok = rhs_0 + match ( + { ((copies_0.with(|rc| *rc.borrow()) == 2) as i32) }, + &mut (ok), + ) { + (__tmp_7, __tmp_8) => { + (*__tmp_8) = (((*__tmp_8) as i32) & (__tmp_7 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & (((({ - (*m.borrow()) - .get(&b.as_pointer()) - .expect("out of range!") - .borrow() - .1 + match ( + { + (((*(*m .as_pointer() - }) - .read()) - == 20) as i32)) - != 0; - ok = rhs_0 + .with(|__m: &Map, Value)>| __m.find(&a.as_pointer())) + .iter_deref() + .upgrade() + .deref()) + .1 + .borrow()) + == 11) as i32) + }, + &mut (ok), + ) { + (__tmp_9, __tmp_10) => { + (*__tmp_10) = (((*__tmp_10) as i32) & (__tmp_9 as i32)) != 0; + } + } + }; + { + match ( + { + (((({ + (*m.borrow()) + .get(&b.as_pointer()) + .expect("out of range!") + .borrow() + .1 + .as_pointer() + }) + .read()) + == 20) as i32) + }, + &mut (ok), + ) { + (__tmp_11, __tmp_12) => { + (*__tmp_12) = (((*__tmp_12) as i32) & (__tmp_11 as i32)) != 0; + } + } + }; + { + match ( + { ((copies_0.with(|rc| *rc.borrow()) == 2) as i32) }, + &mut (ok), + ) { + (__tmp_13, __tmp_14) => { + (*__tmp_14) = (((*__tmp_14) as i32) & (__tmp_13 as i32)) != 0; + } + } }; - ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; match (Rc::new(RefCell::new(({ make_key_3(4) }))).as_pointer(),) { - (__tmp_3,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_3, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_15,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_15, |__k| cpp_move!(__k), || 0_i32) }) } } .write(40); match (Rc::new(RefCell::new(({ make_key_3(4) }))).as_pointer(),) { - (__tmp_4,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_4, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_16,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_16, |__k| cpp_move!(__k), || 0_i32) }) } } .write(41); - ok = { - ((ok as i32) - & ((((made_2.with(|rc| *rc.borrow()) == 2) && (moves_1.with(|rc| *rc.borrow()) == 1)) - && (copies_0.with(|rc| *rc.borrow()) == 2)) as i32)) - != 0 + { + match ( + { + ((((made_2.with(|rc| *rc.borrow()) == 2) && (moves_1.with(|rc| *rc.borrow()) == 1)) + && (copies_0.with(|rc| *rc.borrow()) == 2)) as i32) + }, + &mut (ok), + ) { + (__tmp_17, __tmp_18) => { + (*__tmp_18) = (((*__tmp_18) as i32) & (__tmp_17 as i32)) != 0; + } + } }; match (c.as_pointer(),) { - (__tmp_5,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_5, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_19,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_19, |__k| cpp_move!(__k), || 0_i32) }) } } .write(30); match (c.as_pointer(),) { - (__tmp_6,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_6, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_20,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_20, |__k| cpp_move!(__k), || 0_i32) }) } } .write(31); - ok = { - ((ok as i32) - & ((((moves_1.with(|rc| *rc.borrow()) == 2) && (copies_0.with(|rc| *rc.borrow()) == 2)) - && ({ (*c.borrow()).k } == 3)) as i32)) - != 0 + { + match ( + { + ((((moves_1.with(|rc| *rc.borrow()) == 2) + && (copies_0.with(|rc| *rc.borrow()) == 2)) + && ({ (*c.borrow()).k } == 3)) as i32) + }, + &mut (ok), + ) { + (__tmp_21, __tmp_22) => { + (*__tmp_22) = (((*__tmp_22) as i32) & (__tmp_21 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) & (((*m.borrow()).len() == 4_usize) as i32)) != 0; - ok = rhs_0 + match ({ (((*m.borrow()).len() == 4_usize) as i32) }, &mut (ok)) { + (__tmp_23, __tmp_24) => { + (*__tmp_24) = (((*__tmp_24) as i32) & (__tmp_23 as i32)) != 0; + } + } }; { match ((*m @@ -167,20 +233,26 @@ fn main_0() -> i32 { .0 .as_pointer(),) { - (__tmp_7,) => ({ (*m.borrow_mut()).subscript(__tmp_7, || 0_i32) }), + (__tmp_25,) => ({ (*m.borrow_mut()).subscript(__tmp_25, || 0_i32) }), } .with_mut(|__v| *__v = *__v + 1) }; { - let rhs_0 = ((ok as i32) - & (((copies_0.with(|rc| *rc.borrow()) == 2) - && ((match (a.as_pointer(),) { - (__tmp_8,) => ({ (*m.borrow_mut()).subscript(__tmp_8, || 0_i32) }), - } - .read()) - == 12)) as i32)) - != 0; - ok = rhs_0 + match ( + { + (((copies_0.with(|rc| *rc.borrow()) == 2) + && ((match (a.as_pointer(),) { + (__tmp_28,) => ({ (*m.borrow_mut()).subscript(__tmp_28, || 0_i32) }), + } + .read()) + == 12)) as i32) + }, + &mut (ok), + ) { + (__tmp_26, __tmp_27) => { + (*__tmp_27) = (((*__tmp_27) as i32) & (__tmp_26 as i32)) != 0; + } + } }; let mut first: Ptr = ((*m .as_pointer() @@ -191,38 +263,68 @@ fn main_0() -> i32 { .0 .as_pointer()); match (Rc::new(RefCell::new(Key::new({ 0 }))).as_pointer(),) { - (__tmp_9,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_9, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_29,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_29, |__k| cpp_move!(__k), || 0_i32) }) } } .write(0); - ok = { ((ok as i32) & ((moves_1.with(|rc| *rc.borrow()) == 3) as i32)) != 0 }; { - let rhs_0 = ((ok as i32) - & (({ - ((*m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&a.as_pointer())) - .iter_deref() - .upgrade() - .deref()) - .0 - .as_pointer()) - } == { (first).clone() }) as i32)) - != 0; - ok = rhs_0 + match ( + { ((moves_1.with(|rc| *rc.borrow()) == 3) as i32) }, + &mut (ok), + ) { + (__tmp_30, __tmp_31) => { + (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; + } + } + }; + { + match ( + { + (({ + ((*m.as_pointer() + .with(|__m: &Map, Value)>| __m.find(&a.as_pointer())) + .iter_deref() + .upgrade() + .deref()) + .0 + .as_pointer()) + } == { (first).clone() }) as i32) + }, + &mut (ok), + ) { + (__tmp_32, __tmp_33) => { + (*__tmp_33) = (((*__tmp_33) as i32) & (__tmp_32 as i32)) != 0; + } + } }; let n: Value, Value)>> = Rc::new(RefCell::new((*m.borrow()).clone())); - ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == (2 + 5)) as i32)) != 0 }; { - let rhs_0 = ((ok as i32) - & ((((*n.borrow()).len() == 5_usize) - && ((match (a.as_pointer(),) { - (__tmp_10,) => ({ (*n.borrow_mut()).subscript(__tmp_10, || 0_i32) }), - } - .read()) - == 12)) as i32)) - != 0; - ok = rhs_0 + match ( + { ((copies_0.with(|rc| *rc.borrow()) == (2 + 5)) as i32) }, + &mut (ok), + ) { + (__tmp_34, __tmp_35) => { + (*__tmp_35) = (((*__tmp_35) as i32) & (__tmp_34 as i32)) != 0; + } + } + }; + { + match ( + { + ((((*n.borrow()).len() == 5_usize) + && ((match (a.as_pointer(),) { + (__tmp_38,) => ({ (*n.borrow_mut()).subscript(__tmp_38, || 0_i32) }), + } + .read()) + == 12)) as i32) + }, + &mut (ok), + ) { + (__tmp_36, __tmp_37) => { + (*__tmp_37) = (((*__tmp_37) as i32) & (__tmp_36 as i32)) != 0; + } + } }; Map::erase( m.as_pointer(), @@ -230,43 +332,68 @@ fn main_0() -> i32 { .with(|__m: &Map, Value)>| __m.find(&a.as_pointer())), ); { - let rhs_0 = ((ok as i32) - & ((Map::erase_key(m.as_pointer(), &b.as_pointer()) == 1_usize) as i32)) - != 0; - ok = rhs_0 + match ( + { ((Map::erase_key(m.as_pointer(), &b.as_pointer()) == 1_usize) as i32) }, + &mut (ok), + ) { + (__tmp_39, __tmp_40) => { + (*__tmp_40) = (((*__tmp_40) as i32) & (__tmp_39 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & ((Map::erase_key(m.as_pointer(), &b.as_pointer()) == 0_usize) as i32)) - != 0; - ok = rhs_0 + match ( + { ((Map::erase_key(m.as_pointer(), &b.as_pointer()) == 0_usize) as i32) }, + &mut (ok), + ) { + (__tmp_41, __tmp_42) => { + (*__tmp_42) = (((*__tmp_42) as i32) & (__tmp_41 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & ((Map::erase_key( - m.as_pointer(), - &(*m.as_pointer() - .with(|__m: &Map, Value)>| __m.begin()) - .iter_deref() - .upgrade() - .deref()) - .0 - .as_pointer(), - ) == 1_usize) as i32)) - != 0; - ok = rhs_0 + match ( + { + ((Map::erase_key( + m.as_pointer(), + &(*m.as_pointer() + .with(|__m: &Map, Value)>| __m.begin()) + .iter_deref() + .upgrade() + .deref()) + .0 + .as_pointer(), + ) == 1_usize) as i32) + }, + &mut (ok), + ) { + (__tmp_43, __tmp_44) => { + (*__tmp_44) = (((*__tmp_44) as i32) & (__tmp_43 as i32)) != 0; + } + } }; - ok = { - ((ok as i32) - & (((copies_0.with(|rc| *rc.borrow()) == 7) && (moves_1.with(|rc| *rc.borrow()) == 3)) - as i32)) - != 0 + { + match ( + { + (((copies_0.with(|rc| *rc.borrow()) == 7) && (moves_1.with(|rc| *rc.borrow()) == 3)) + as i32) + }, + &mut (ok), + ) { + (__tmp_45, __tmp_46) => { + (*__tmp_46) = (((*__tmp_46) as i32) & (__tmp_45 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & ((((*m.borrow()).len() == 2_usize) && ((*n.borrow()).len() == 5_usize)) as i32)) - != 0; - ok = rhs_0 + match ( + { ((((*m.borrow()).len() == 2_usize) && ((*n.borrow()).len() == 5_usize)) as i32) }, + &mut (ok), + ) { + (__tmp_47, __tmp_48) => { + (*__tmp_48) = (((*__tmp_48) as i32) & (__tmp_47 as i32)) != 0; + } + } }; let mut sum: i32 = 0; 'loop_: for entry in IterRange::new( @@ -280,12 +407,25 @@ fn main_0() -> i32 { (*(*entry.upgrade().deref()).1.borrow()) }); } - ok = { ((ok as i32) & ((sum == ((3 * 31) + (4 * 41))) as i32)) != 0 }; - ok = { - ((ok as i32) - & (((copies_0.with(|rc| *rc.borrow()) == 7) && (moves_1.with(|rc| *rc.borrow()) == 3)) - as i32)) - != 0 + { + match ({ ((sum == ((3 * 31) + (4 * 41))) as i32) }, &mut (ok)) { + (__tmp_49, __tmp_50) => { + (*__tmp_50) = (((*__tmp_50) as i32) & (__tmp_49 as i32)) != 0; + } + } + }; + { + match ( + { + (((copies_0.with(|rc| *rc.borrow()) == 7) && (moves_1.with(|rc| *rc.borrow()) == 3)) + as i32) + }, + &mut (ok), + ) { + (__tmp_51, __tmp_52) => { + (*__tmp_52) = (((*__tmp_52) as i32) & (__tmp_51 as i32)) != 0; + } + } }; printf!( b"%d %d %d\n", diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index 8d9695dd17..8368d10990 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -66,13 +66,19 @@ fn main_0() -> i32 { identity: 7, })); { - let rhs_0 = ((ok as i32) - & (({ - let _a: Ptr = distinct_a.as_pointer(); - operator_eq_2(_a, distinct_b.as_pointer()) - }) as i32)) - != 0; - ok = rhs_0 + match ( + { + (({ + let _a: Ptr = distinct_a.as_pointer(); + operator_eq_2(_a, distinct_b.as_pointer()) + }) as i32) + }, + &mut (ok), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as i32) & (__tmp_0 as i32)) != 0; + } + } }; let distinct: Value, Value)>> = Rc::new(RefCell::new(Map::new())); let a: Ptr = @@ -85,7 +91,16 @@ fn main_0() -> i32 { let mut a_value: Ptr = ((*({ (*a_it.borrow()).iter_deref() }).upgrade().deref()) .1 .as_pointer()); - ok = { ((ok as i32) & ((default_constructions_0.with(|rc| *rc.borrow()) == 1) as i32)) != 0 }; + { + match ( + { ((default_constructions_0.with(|rc| *rc.borrow()) == 1) as i32) }, + &mut (ok), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (((*__tmp_3) as i32) & (__tmp_2 as i32)) != 0; + } + } + }; let b: Ptr = ({ (*distinct.borrow_mut()).subscript(distinct_b.as_pointer(), || ::default()) }); field!(b, value).write(22); @@ -93,74 +108,136 @@ fn main_0() -> i32 { Rc::new(RefCell::new(distinct.as_pointer().with( |__m: &Map, Value)>| __m.find(&distinct_b.as_pointer()), ))); - ok = { ((ok as i32) & ((default_constructions_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; - { - let rhs_0 = ((ok as i32) & (((*distinct.borrow()).len() == 2_usize) as i32)) != 0; - ok = rhs_0 - }; - ok = { ((ok as i32) & (({ (a).clone() } != { (b).clone() }) as i32)) != 0 }; - ok = { - ((ok as i32) - & (((a.with(|__s| __s.value) == 11) && (b.with(|__s| __s.value) == 22)) as i32)) - != 0 - }; - { - let rhs_0 = ((ok as i32) - & (((*a_it.borrow()) - == distinct - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&distinct_a.as_pointer()) - })) as i32)) - != 0; - ok = rhs_0 - }; - { - let rhs_0 = ((ok as i32) - & (((*b_it.borrow()) - == distinct - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&distinct_b.as_pointer()) - })) as i32)) - != 0; - ok = rhs_0 - }; - { - let rhs_0 = ((ok as i32) - & (((*b_it.borrow()) - != distinct - .as_pointer() - .with(|__m: &Map, Value)>| __m.end())) - as i32)) - != 0; - ok = rhs_0 - }; - { - let rhs_0 = ((ok as i32) - & (({ - ((*({ (*a_it.borrow()).iter_deref() }).upgrade().deref()) - .1 - .as_pointer()) - } == { (a_value).clone() }) as i32)) - != 0; - ok = rhs_0 - }; - { - let rhs_0 = ((ok as i32) - & ((({ (*a_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) == 11) - as i32)) - != 0; - ok = rhs_0 - }; - { - let rhs_0 = ((ok as i32) - & (({ - let _a: Ptr = distinct_a.as_pointer(); - operator_eq_2(_a, distinct_b.as_pointer()) - }) as i32)) - != 0; - ok = rhs_0 + { + match ( + { ((default_constructions_0.with(|rc| *rc.borrow()) == 2) as i32) }, + &mut (ok), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) != 0; + } + } + }; + { + match ( + { (((*distinct.borrow()).len() == 2_usize) as i32) }, + &mut (ok), + ) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as i32) & (__tmp_6 as i32)) != 0; + } + } + }; + { + match ({ (({ (a).clone() } != { (b).clone() }) as i32) }, &mut (ok)) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as i32) & (__tmp_8 as i32)) != 0; + } + } + }; + { + match ( + { (((a.with(|__s| __s.value) == 11) && (b.with(|__s| __s.value) == 22)) as i32) }, + &mut (ok), + ) { + (__tmp_10, __tmp_11) => { + (*__tmp_11) = (((*__tmp_11) as i32) & (__tmp_10 as i32)) != 0; + } + } + }; + { + match ( + { + (((*a_it.borrow()) + == distinct + .as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&distinct_a.as_pointer()) + })) as i32) + }, + &mut (ok), + ) { + (__tmp_12, __tmp_13) => { + (*__tmp_13) = (((*__tmp_13) as i32) & (__tmp_12 as i32)) != 0; + } + } + }; + { + match ( + { + (((*b_it.borrow()) + == distinct + .as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&distinct_b.as_pointer()) + })) as i32) + }, + &mut (ok), + ) { + (__tmp_14, __tmp_15) => { + (*__tmp_15) = (((*__tmp_15) as i32) & (__tmp_14 as i32)) != 0; + } + } + }; + { + match ( + { + (((*b_it.borrow()) + != distinct + .as_pointer() + .with(|__m: &Map, Value)>| __m.end())) + as i32) + }, + &mut (ok), + ) { + (__tmp_16, __tmp_17) => { + (*__tmp_17) = (((*__tmp_17) as i32) & (__tmp_16 as i32)) != 0; + } + } + }; + { + match ( + { + (({ + ((*({ (*a_it.borrow()).iter_deref() }).upgrade().deref()) + .1 + .as_pointer()) + } == { (a_value).clone() }) as i32) + }, + &mut (ok), + ) { + (__tmp_18, __tmp_19) => { + (*__tmp_19) = (((*__tmp_19) as i32) & (__tmp_18 as i32)) != 0; + } + } + }; + { + match ( + { + ((({ (*a_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) == 11) + as i32) + }, + &mut (ok), + ) { + (__tmp_20, __tmp_21) => { + (*__tmp_21) = (((*__tmp_21) as i32) & (__tmp_20 as i32)) != 0; + } + } + }; + { + match ( + { + (({ + let _a: Ptr = distinct_a.as_pointer(); + operator_eq_2(_a, distinct_b.as_pointer()) + }) as i32) + }, + &mut (ok), + ) { + (__tmp_22, __tmp_23) => { + (*__tmp_23) = (((*__tmp_23) as i32) & (__tmp_22 as i32)) != 0; + } + } }; let mut distinct_count: usize = 0_usize; 'loop_: for entry in IterRange::new( @@ -173,25 +250,45 @@ fn main_0() -> i32 { ) { let entry: Ptr<(Value, Value)> = entry.iter_deref(); if (distinct_count == 0_usize) { - ok = { - ((ok as i32) - & ((({ (*(*entry.upgrade().deref()).0.borrow()).order } == 1) - && ({ (*(*entry.upgrade().deref()).1.borrow()).value } == 11)) - as i32)) - != 0 + { + match ( + { + ((({ (*(*entry.upgrade().deref()).0.borrow()).order } == 1) + && ({ (*(*entry.upgrade().deref()).1.borrow()).value } == 11)) + as i32) + }, + &mut (ok), + ) { + (__tmp_24, __tmp_25) => { + (*__tmp_25) = (((*__tmp_25) as i32) & (__tmp_24 as i32)) != 0; + } + } }; } else if (distinct_count == 1_usize) { - ok = { - ((ok as i32) - & ((({ (*(*entry.upgrade().deref()).0.borrow()).order } == 2) - && ({ (*(*entry.upgrade().deref()).1.borrow()).value } == 22)) - as i32)) - != 0 + { + match ( + { + ((({ (*(*entry.upgrade().deref()).0.borrow()).order } == 2) + && ({ (*(*entry.upgrade().deref()).1.borrow()).value } == 22)) + as i32) + }, + &mut (ok), + ) { + (__tmp_26, __tmp_27) => { + (*__tmp_27) = (((*__tmp_27) as i32) & (__tmp_26 as i32)) != 0; + } + } }; } distinct_count.prefix_inc(); } - ok = { ((ok as i32) & ((distinct_count == 2_usize) as i32)) != 0 }; + { + match ({ ((distinct_count == 2_usize) as i32) }, &mut (ok)) { + (__tmp_28, __tmp_29) => { + (*__tmp_29) = (((*__tmp_29) as i32) & (__tmp_28 as i32)) != 0; + } + } + }; let equivalent_a: Value = Rc::new(RefCell::new(Key { order: 3, identity: 8, @@ -201,13 +298,19 @@ fn main_0() -> i32 { identity: 9, })); { - let rhs_0 = ((ok as i32) - & (!({ - let _a: Ptr = equivalent_a.as_pointer(); - operator_eq_2(_a, equivalent_b.as_pointer()) - }) as i32)) - != 0; - ok = rhs_0 + match ( + { + (!({ + let _a: Ptr = equivalent_a.as_pointer(); + operator_eq_2(_a, equivalent_b.as_pointer()) + }) as i32) + }, + &mut (ok), + ) { + (__tmp_30, __tmp_31) => { + (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; + } + } }; let equivalent: Value, Value)>> = Rc::new(RefCell::new(Map::new())); @@ -224,72 +327,131 @@ fn main_0() -> i32 { ((*({ (*first_it.borrow()).iter_deref() }).upgrade().deref()) .1 .as_pointer()); - ok = { - ((ok as i32) - & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_equivalent + 1)) as i32)) - != 0 + { + match ( + { + ((default_constructions_0.with(|rc| *rc.borrow()) == (before_equivalent + 1)) + as i32) + }, + &mut (ok), + ) { + (__tmp_32, __tmp_33) => { + (*__tmp_33) = (((*__tmp_33) as i32) & (__tmp_32 as i32)) != 0; + } + } }; let second: Ptr = ({ (*equivalent.borrow_mut()).subscript(equivalent_b.as_pointer(), || ::default()) }); let mut reused: bool = (default_constructions_0.with(|rc| *rc.borrow()) == (before_equivalent + 1)); - ok = { ((ok as i32) & (reused as i32)) != 0 }; { - let rhs_0 = ((ok as i32) & (((*equivalent.borrow()).len() == 1_usize) as i32)) != 0; - ok = rhs_0 + match ({ (reused as i32) }, &mut (ok)) { + (__tmp_34, __tmp_35) => { + (*__tmp_35) = (((*__tmp_35) as i32) & (__tmp_34 as i32)) != 0; + } + } + }; + { + match ( + { (((*equivalent.borrow()).len() == 1_usize) as i32) }, + &mut (ok), + ) { + (__tmp_36, __tmp_37) => { + (*__tmp_37) = (((*__tmp_37) as i32) & (__tmp_36 as i32)) != 0; + } + } }; if reused { { - let rhs_0 = ((ok as i32) - & (((*first_it.borrow()) - != equivalent - .as_pointer() - .with(|__m: &Map, Value)>| __m.end())) - as i32)) - != 0; - ok = rhs_0 + match ( + { + (((*first_it.borrow()) + != equivalent + .as_pointer() + .with(|__m: &Map, Value)>| __m.end())) + as i32) + }, + &mut (ok), + ) { + (__tmp_38, __tmp_39) => { + (*__tmp_39) = (((*__tmp_39) as i32) & (__tmp_38 as i32)) != 0; + } + } }; - ok = { ((ok as i32) & (({ (first).clone() } == { (second).clone() }) as i32)) != 0 }; { - let rhs_0 = ((ok as i32) - & (((*first_it.borrow()) - == equivalent.as_pointer().with( - |__m: &Map, Value)>| { - __m.find(&equivalent_a.as_pointer()) - }, - )) as i32)) - != 0; - ok = rhs_0 + match ( + { (({ (first).clone() } == { (second).clone() }) as i32) }, + &mut (ok), + ) { + (__tmp_40, __tmp_41) => { + (*__tmp_41) = (((*__tmp_41) as i32) & (__tmp_40 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & (((*first_it.borrow()) - == equivalent.as_pointer().with( - |__m: &Map, Value)>| { - __m.find(&equivalent_b.as_pointer()) - }, - )) as i32)) - != 0; - ok = rhs_0 + match ( + { + (((*first_it.borrow()) + == equivalent.as_pointer().with( + |__m: &Map, Value)>| { + __m.find(&equivalent_a.as_pointer()) + }, + )) as i32) + }, + &mut (ok), + ) { + (__tmp_42, __tmp_43) => { + (*__tmp_43) = (((*__tmp_43) as i32) & (__tmp_42 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & (({ - ((*({ (*first_it.borrow()).iter_deref() }).upgrade().deref()) - .1 - .as_pointer()) - } == { (first_value).clone() }) as i32)) - != 0; - ok = rhs_0 + match ( + { + (((*first_it.borrow()) + == equivalent.as_pointer().with( + |__m: &Map, Value)>| { + __m.find(&equivalent_b.as_pointer()) + }, + )) as i32) + }, + &mut (ok), + ) { + (__tmp_44, __tmp_45) => { + (*__tmp_45) = (((*__tmp_45) as i32) & (__tmp_44 as i32)) != 0; + } + } + }; + { + match ( + { + (({ + ((*({ (*first_it.borrow()).iter_deref() }).upgrade().deref()) + .1 + .as_pointer()) + } == { (first_value).clone() }) as i32) + }, + &mut (ok), + ) { + (__tmp_46, __tmp_47) => { + (*__tmp_47) = (((*__tmp_47) as i32) & (__tmp_46 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & (((({ (*first_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) - == 31) - && (second.with(|__s| __s.value) == 31)) as i32)) - != 0; - ok = rhs_0 + match ( + { + (((({ (*first_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) + == 31) + && (second.with(|__s| __s.value) == 31)) as i32) + }, + &mut (ok), + ) { + (__tmp_48, __tmp_49) => { + (*__tmp_49) = (((*__tmp_49) as i32) & (__tmp_48 as i32)) != 0; + } + } }; let mut equivalent_count: usize = 0_usize; 'loop_: for entry in IterRange::new( @@ -301,25 +463,44 @@ fn main_0() -> i32 { .with(|__m: &Map, Value)>| __m.end()), ) { let entry: Ptr<(Value, Value)> = entry.iter_deref(); - ok = { - ((ok as i32) - & ((({ (*(*entry.upgrade().deref()).0.borrow()).order } == 3) - && ({ (*(*entry.upgrade().deref()).1.borrow()).value } == 31)) - as i32)) - != 0 + { + match ( + { + ((({ (*(*entry.upgrade().deref()).0.borrow()).order } == 3) + && ({ (*(*entry.upgrade().deref()).1.borrow()).value } == 31)) + as i32) + }, + &mut (ok), + ) { + (__tmp_50, __tmp_51) => { + (*__tmp_51) = (((*__tmp_51) as i32) & (__tmp_50 as i32)) != 0; + } + } }; equivalent_count.prefix_inc(); } - ok = { ((ok as i32) & ((equivalent_count == 1_usize) as i32)) != 0 }; + { + match ({ ((equivalent_count == 1_usize) as i32) }, &mut (ok)) { + (__tmp_52, __tmp_53) => { + (*__tmp_53) = (((*__tmp_53) as i32) & (__tmp_52 as i32)) != 0; + } + } + }; } { - let rhs_0 = ((ok as i32) - & (!({ - let _a: Ptr = equivalent_a.as_pointer(); - operator_eq_2(_a, equivalent_b.as_pointer()) - }) as i32)) - != 0; - ok = rhs_0 + match ( + { + (!({ + let _a: Ptr = equivalent_a.as_pointer(); + operator_eq_2(_a, equivalent_b.as_pointer()) + }) as i32) + }, + &mut (ok), + ) { + (__tmp_54, __tmp_55) => { + (*__tmp_55) = (((*__tmp_55) as i32) & (__tmp_54 as i32)) != 0; + } + } }; let later_key: Value = Rc::new(RefCell::new(Key { order: 4, @@ -328,43 +509,75 @@ fn main_0() -> i32 { let later: Ptr = ({ (*equivalent.borrow_mut()).subscript(later_key.as_pointer(), || ::default()) }); field!(later, value).write(41); - ok = { - ((ok as i32) - & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_equivalent + 2)) as i32)) - != 0 + { + match ( + { + ((default_constructions_0.with(|rc| *rc.borrow()) == (before_equivalent + 2)) + as i32) + }, + &mut (ok), + ) { + (__tmp_56, __tmp_57) => { + (*__tmp_57) = (((*__tmp_57) as i32) & (__tmp_56 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) & (((*equivalent.borrow()).len() == 2_usize) as i32)) != 0; - ok = rhs_0 + match ( + { (((*equivalent.borrow()).len() == 2_usize) as i32) }, + &mut (ok), + ) { + (__tmp_58, __tmp_59) => { + (*__tmp_59) = (((*__tmp_59) as i32) & (__tmp_58 as i32)) != 0; + } + } }; if reused { { - let rhs_0 = ((ok as i32) - & (((*first_it.borrow()) - == equivalent.as_pointer().with( - |__m: &Map, Value)>| { - __m.find(&equivalent_a.as_pointer()) - }, - )) as i32)) - != 0; - ok = rhs_0 + match ( + { + (((*first_it.borrow()) + == equivalent.as_pointer().with( + |__m: &Map, Value)>| { + __m.find(&equivalent_a.as_pointer()) + }, + )) as i32) + }, + &mut (ok), + ) { + (__tmp_60, __tmp_61) => { + (*__tmp_61) = (((*__tmp_61) as i32) & (__tmp_60 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & (({ - ((*({ (*first_it.borrow()).iter_deref() }).upgrade().deref()) - .1 - .as_pointer()) - } == { (first_value).clone() }) as i32)) - != 0; - ok = rhs_0 + match ( + { + (({ + ((*({ (*first_it.borrow()).iter_deref() }).upgrade().deref()) + .1 + .as_pointer()) + } == { (first_value).clone() }) as i32) + }, + &mut (ok), + ) { + (__tmp_62, __tmp_63) => { + (*__tmp_63) = (((*__tmp_63) as i32) & (__tmp_62 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & ((({ (*first_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) - == 31) as i32)) - != 0; - ok = rhs_0 + match ( + { + ((({ (*first_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) + == 31) as i32) + }, + &mut (ok), + ) { + (__tmp_64, __tmp_65) => { + (*__tmp_65) = (((*__tmp_65) as i32) & (__tmp_64 as i32)) != 0; + } + } }; } let matching_a: Value = Rc::new(RefCell::new(Key { @@ -392,90 +605,162 @@ fn main_0() -> i32 { ((*({ (*matched_it.borrow()).iter_deref() }).upgrade().deref()) .1 .as_pointer()); - ok = { - ((ok as i32) - & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 1)) as i32)) - != 0 + { + match ( + { ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 1)) as i32) }, + &mut (ok), + ) { + (__tmp_66, __tmp_67) => { + (*__tmp_67) = (((*__tmp_67) as i32) & (__tmp_66 as i32)) != 0; + } + } }; let matched_again: Ptr = ({ (*matching.borrow_mut()).subscript(matching_b.as_pointer(), || ::default()) }); - ok = { - ((ok as i32) - & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 1)) as i32)) - != 0 + { + match ( + { ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 1)) as i32) }, + &mut (ok), + ) { + (__tmp_68, __tmp_69) => { + (*__tmp_69) = (((*__tmp_69) as i32) & (__tmp_68 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) & (((*matching.borrow()).len() == 1_usize) as i32)) != 0; - ok = rhs_0 + match ( + { (((*matching.borrow()).len() == 1_usize) as i32) }, + &mut (ok), + ) { + (__tmp_70, __tmp_71) => { + (*__tmp_71) = (((*__tmp_71) as i32) & (__tmp_70 as i32)) != 0; + } + } }; - ok = { ((ok as i32) & (({ (matched).clone() } == { (matched_again).clone() }) as i32)) != 0 }; { - let rhs_0 = ((ok as i32) - & (((*matched_it.borrow()) - == matching - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&matching_b.as_pointer()) - })) as i32)) - != 0; - ok = rhs_0 + match ( + { (({ (matched).clone() } == { (matched_again).clone() }) as i32) }, + &mut (ok), + ) { + (__tmp_72, __tmp_73) => { + (*__tmp_73) = (((*__tmp_73) as i32) & (__tmp_72 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & (({ - ((*({ (*matched_it.borrow()).iter_deref() }).upgrade().deref()) - .1 - .as_pointer()) - } == { (matched_value).clone() }) as i32)) - != 0; - ok = rhs_0 + match ( + { + (((*matched_it.borrow()) + == matching + .as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&matching_b.as_pointer()) + })) as i32) + }, + &mut (ok), + ) { + (__tmp_74, __tmp_75) => { + (*__tmp_75) = (((*__tmp_75) as i32) & (__tmp_74 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & ((({ (*matched_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) == 51) - as i32)) - != 0; - ok = rhs_0 + match ( + { + (({ + ((*({ (*matched_it.borrow()).iter_deref() }).upgrade().deref()) + .1 + .as_pointer()) + } == { (matched_value).clone() }) as i32) + }, + &mut (ok), + ) { + (__tmp_76, __tmp_77) => { + (*__tmp_77) = (((*__tmp_77) as i32) & (__tmp_76 as i32)) != 0; + } + } + }; + { + match ( + { + ((({ (*matched_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) + == 51) as i32) + }, + &mut (ok), + ) { + (__tmp_78, __tmp_79) => { + (*__tmp_79) = (((*__tmp_79) as i32) & (__tmp_78 as i32)) != 0; + } + } }; let other: Ptr = ({ (*matching.borrow_mut()).subscript(matching_c.as_pointer(), || ::default()) }); field!(other, value).write(61); - ok = { - ((ok as i32) - & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 2)) as i32)) - != 0 - }; - { - let rhs_0 = ((ok as i32) & (((*matching.borrow()).len() == 2_usize) as i32)) != 0; - ok = rhs_0 - }; - { - let rhs_0 = ((ok as i32) - & (((*matched_it.borrow()) - == matching - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&matching_a.as_pointer()) - })) as i32)) - != 0; - ok = rhs_0 - }; - { - let rhs_0 = ((ok as i32) - & (({ - ((*({ (*matched_it.borrow()).iter_deref() }).upgrade().deref()) - .1 - .as_pointer()) - } == { (matched_value).clone() }) as i32)) - != 0; - ok = rhs_0 - }; - { - let rhs_0 = ((ok as i32) - & ((({ (*matched_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) == 51) - as i32)) - != 0; - ok = rhs_0 + { + match ( + { ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 2)) as i32) }, + &mut (ok), + ) { + (__tmp_80, __tmp_81) => { + (*__tmp_81) = (((*__tmp_81) as i32) & (__tmp_80 as i32)) != 0; + } + } + }; + { + match ( + { (((*matching.borrow()).len() == 2_usize) as i32) }, + &mut (ok), + ) { + (__tmp_82, __tmp_83) => { + (*__tmp_83) = (((*__tmp_83) as i32) & (__tmp_82 as i32)) != 0; + } + } + }; + { + match ( + { + (((*matched_it.borrow()) + == matching + .as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&matching_a.as_pointer()) + })) as i32) + }, + &mut (ok), + ) { + (__tmp_84, __tmp_85) => { + (*__tmp_85) = (((*__tmp_85) as i32) & (__tmp_84 as i32)) != 0; + } + } + }; + { + match ( + { + (({ + ((*({ (*matched_it.borrow()).iter_deref() }).upgrade().deref()) + .1 + .as_pointer()) + } == { (matched_value).clone() }) as i32) + }, + &mut (ok), + ) { + (__tmp_86, __tmp_87) => { + (*__tmp_87) = (((*__tmp_87) as i32) & (__tmp_86 as i32)) != 0; + } + } + }; + { + match ( + { + ((({ (*matched_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) + == 51) as i32) + }, + &mut (ok), + ) { + (__tmp_88, __tmp_89) => { + (*__tmp_89) = (((*__tmp_89) as i32) & (__tmp_88 as i32)) != 0; + } + } }; return if ok { 0 } else { 1 }; } diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index f64adfeced..ea33c79036 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -80,11 +80,12 @@ impl RefItem { pub fn new_2(counter: Ptr, mut amount: i32) -> Self { let __this: RefItem = Self { value: { - { - let __rhs = { amount }; - counter.with_mut(|__v| *__v = *__v + __rhs) - }; - (counter.read()) + match ({ amount }, &(counter)) { + (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { + (*__tmp_1) = (((*__tmp_1) as i32) + (__tmp_0 as i32)) as i32; + (*__tmp_1).clone() + }), + } }, }; (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); @@ -126,21 +127,21 @@ thread_local!( Value, )> = Rc::new(RefCell::new( match ({ - let __tmp_1 = global_counter_8.with(|v| v.as_pointer()); - __tmp_1.with_mut(|__v| { + let __tmp_3 = global_counter_8.with(|v| v.as_pointer()); + __tmp_3.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_1 + __tmp_3 },) { - (__tmp_0,) => { + (__tmp_2,) => { let (__it, __inserted) = Map::emplace( global_map_6.with(|v| v.as_pointer()), &global_key_7.with(|v| v.as_pointer()), || { ( Rc::new(RefCell::new(global_key_7.with(|v| v.as_pointer()).read())), - Rc::new(RefCell::new((__tmp_0.read()))), + Rc::new(RefCell::new((__tmp_2.read()))), ) }, ); @@ -220,23 +221,23 @@ fn main_0() -> i32 { >, Value, )> = Rc::new(RefCell::new({ - let __tmp_3: Value; + let __tmp_5: Value; if (post != 0) { match ({ - __tmp_3 = Rc::new(RefCell::new( + __tmp_5 = Rc::new(RefCell::new( (*counter.borrow_mut()) .postfix_inc(), )); - __tmp_3.as_pointer() + __tmp_5.as_pointer() },) { - (__tmp_2,) => { + (__tmp_4,) => { let (__it, __inserted) = Map::emplace( m.as_pointer(), &key.as_pointer(), || { - (Rc::new(RefCell::new(key .as_pointer() .read())), Rc::new(RefCell::new((__tmp_2.read()) ))) + (Rc::new(RefCell::new(key .as_pointer() .read())), Rc::new(RefCell::new((__tmp_4.read()) ))) }, ); ( @@ -249,20 +250,20 @@ fn main_0() -> i32 { } } else { match ({ - let __tmp_5 = counter.as_pointer(); - __tmp_5.with_mut(|__v| { + let __tmp_7 = counter.as_pointer(); + __tmp_7.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_5 + __tmp_7 },) { - (__tmp_4,) => { + (__tmp_6,) => { let (__it, __inserted) = Map::emplace( m.as_pointer(), &key.as_pointer(), || { - (Rc::new(RefCell::new(key .as_pointer() .read())), Rc::new(RefCell::new((__tmp_4.read()) ))) + (Rc::new(RefCell::new(key .as_pointer() .read())), Rc::new(RefCell::new((__tmp_6.read()) ))) }, ); ( @@ -277,66 +278,121 @@ fn main_0() -> i32 { })); let mut hit: bool = ((subset & (1 << (*key.borrow()))) != 0); - ok = { - ((ok as i32) - & (((*counter.borrow()) - == (initial + 1)) - as i32)) - != 0 + { + match ( + { + (((*counter.borrow()) + == (initial + 1)) + as i32) + }, + &mut (ok), + ) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as i32) + & (__tmp_8 as i32)) + != 0; + } + } }; - ok = { - ((ok as i32) - & ((((*(*result.borrow()).1.borrow()) - as i32) - == (!(hit) as i32)) - as i32)) - != 0 + { + match ( + { + ((((*(*result.borrow()).1.borrow()) + as i32) + == (!(hit) as i32)) + as i32) + }, + &mut (ok), + ) { + (__tmp_10, __tmp_11) => { + (*__tmp_11) = (((*__tmp_11) + as i32) + & (__tmp_10 as i32)) + != 0; + } + } }; let mut found : bool = (*(*result.borrow()) .0.borrow()) == m .as_pointer() .with(|__m: &Map, Value)>| __m.find(&key .as_pointer() )) ; - ok = { ((ok as i32) & (found as i32)) != 0 }; { - let rhs_0 = ((ok as i32) - & (((*(*({ - (*(*result.borrow()).0.borrow()) - .iter_deref() - }) - .upgrade() - .deref()) - .0 - .borrow()) - == (*key.borrow())) - as i32)) - != 0; - ok = rhs_0 + match ({ (found as i32) }, &mut (ok)) { + (__tmp_12, __tmp_13) => { + (*__tmp_13) = (((*__tmp_13) + as i32) + & (__tmp_12 as i32)) + != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & (((*(*({ - (*(*result.borrow()).0.borrow()) - .iter_deref() - }) - .upgrade() - .deref()) - .1 - .borrow()) - == (if hit { - (10 + (*key.borrow())) - } else { - (initial - + (!(post != 0) as i32)) - })) - as i32)) - != 0; - ok = rhs_0 + match ( + { + (((*(*({ + (*(*result.borrow()).0.borrow()) + .iter_deref() + }) + .upgrade() + .deref()) + .0 + .borrow()) + == (*key.borrow())) + as i32) + }, + &mut (ok), + ) { + (__tmp_14, __tmp_15) => { + (*__tmp_15) = (((*__tmp_15) + as i32) + & (__tmp_14 as i32)) + != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & (((*m.borrow()).len() - == ((size + (!(hit) as i32)) - as usize)) - as i32)) - != 0; - ok = rhs_0 + match ( + { + (((*(*({ + (*(*result.borrow()).0.borrow()) + .iter_deref() + }) + .upgrade() + .deref()) + .1 + .borrow()) + == (if hit { + (10 + (*key.borrow())) + } else { + (initial + + (!(post != 0) as i32)) + })) + as i32) + }, + &mut (ok), + ) { + (__tmp_16, __tmp_17) => { + (*__tmp_17) = (((*__tmp_17) + as i32) + & (__tmp_16 as i32)) + != 0; + } + } + }; + { + match ( + { + (((*m.borrow()).len() + == ((size + (!(hit) as i32)) + as usize)) + as i32) + }, + &mut (ok), + ) { + (__tmp_18, __tmp_19) => { + (*__tmp_19) = (((*__tmp_19) + as i32) + & (__tmp_18 as i32)) + != 0; + } + } }; rows.prefix_inc(); } @@ -372,13 +428,24 @@ fn main_0() -> i32 { let source: Value = Rc::new(RefCell::new(Item::new_1({ 20 }))); made_1.with(|rc| { *rc.borrow_mut() = { - copies_2.with(|rc| { - *rc.borrow_mut() = { - moves_3.with(|rc| *rc.borrow_mut() = 0); - moves_3.with(|rc| *rc.borrow()) + match ( + { + { + match ({ 0 }, &mut (*moves_3.with(Value::clone).borrow_mut())) { + (__tmp_22, __tmp_23) => { + (*__tmp_23) = __tmp_22; + (*__tmp_23).clone() + } + } + } + }, + &mut (*copies_2.with(Value::clone).borrow_mut()), + ) { + (__tmp_20, __tmp_21) => { + (*__tmp_21) = __tmp_20; + (*__tmp_21).clone() } - }); - copies_2.with(|rc| *rc.borrow()) + } } }); let hit: Value<( @@ -386,12 +453,12 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_6,) => { + (__tmp_24,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::copy_from({ (__tmp_6).clone() }))), + Rc::new(RefCell::new(Item::copy_from({ (__tmp_24).clone() }))), ) }); ( @@ -401,33 +468,47 @@ fn main_0() -> i32 { } }, )); - ok = { - ((ok as i32) - & (((((calls_0.with(|rc| *rc.borrow()) == 1) && (made_1.with(|rc| *rc.borrow()) == 0)) - && (copies_2.with(|rc| *rc.borrow()) == 0)) - && (moves_3.with(|rc| *rc.borrow()) == 0)) as i32)) - != 0 + { + match ( + { + (((((calls_0.with(|rc| *rc.borrow()) == 1) + && (made_1.with(|rc| *rc.borrow()) == 0)) + && (copies_2.with(|rc| *rc.borrow()) == 0)) + && (moves_3.with(|rc| *rc.borrow()) == 0)) as i32) + }, + &mut (ok), + ) { + (__tmp_25, __tmp_26) => { + (*__tmp_26) = (((*__tmp_26) as i32) & (__tmp_25 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & (((!(*(*hit.borrow()).1.borrow())) - && (({ (*(*hit.borrow()).0.borrow()).iter_deref() }) - .with(|__s| (*__s.1.borrow()).value) - == 10)) as i32)) - != 0; - ok = rhs_0 + match ( + { + (((!(*(*hit.borrow()).1.borrow())) + && (({ (*(*hit.borrow()).0.borrow()).iter_deref() }) + .with(|__s| (*__s.1.borrow()).value) + == 10)) as i32) + }, + &mut (ok), + ) { + (__tmp_27, __tmp_28) => { + (*__tmp_28) = (((*__tmp_28) as i32) & (__tmp_27 as i32)) != 0; + } + } }; let move_hit: Value<( Value, Value)>>, Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_7,) => { + (__tmp_29,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_7).clone() }))), + Rc::new(RefCell::new(Item::move_from({ (__tmp_29).clone() }))), ) }); ( @@ -437,18 +518,33 @@ fn main_0() -> i32 { } }, )); - ok = { - ((ok as i32) - & (((((calls_0.with(|rc| *rc.borrow()) == 2) && (made_1.with(|rc| *rc.borrow()) == 0)) - && (copies_2.with(|rc| *rc.borrow()) == 0)) - && (moves_3.with(|rc| *rc.borrow()) == 0)) as i32)) - != 0 + { + match ( + { + (((((calls_0.with(|rc| *rc.borrow()) == 2) + && (made_1.with(|rc| *rc.borrow()) == 0)) + && (copies_2.with(|rc| *rc.borrow()) == 0)) + && (moves_3.with(|rc| *rc.borrow()) == 0)) as i32) + }, + &mut (ok), + ) { + (__tmp_30, __tmp_31) => { + (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; + } + } }; - ok = { - ((ok as i32) - & (((!(*(*move_hit.borrow()).1.borrow())) && ({ (*source.borrow()).value } == 20)) - as i32)) - != 0 + { + match ( + { + (((!(*(*move_hit.borrow()).1.borrow())) && ({ (*source.borrow()).value } == 20)) + as i32) + }, + &mut (ok), + ) { + (__tmp_32, __tmp_33) => { + (*__tmp_33) = (((*__tmp_33) as i32) & (__tmp_32 as i32)) != 0; + } + } }; (*key.borrow_mut()).prefix_inc(); let copied: Value<( @@ -456,12 +552,12 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_8,) => { + (__tmp_34,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::copy_from({ (__tmp_8).clone() }))), + Rc::new(RefCell::new(Item::copy_from({ (__tmp_34).clone() }))), ) }); ( @@ -471,21 +567,35 @@ fn main_0() -> i32 { } }, )); - ok = { - ((ok as i32) - & (((((calls_0.with(|rc| *rc.borrow()) == 3) && (made_1.with(|rc| *rc.borrow()) == 0)) - && (copies_2.with(|rc| *rc.borrow()) == 1)) - && (moves_3.with(|rc| *rc.borrow()) == 0)) as i32)) - != 0 + { + match ( + { + (((((calls_0.with(|rc| *rc.borrow()) == 3) + && (made_1.with(|rc| *rc.borrow()) == 0)) + && (copies_2.with(|rc| *rc.borrow()) == 1)) + && (moves_3.with(|rc| *rc.borrow()) == 0)) as i32) + }, + &mut (ok), + ) { + (__tmp_35, __tmp_36) => { + (*__tmp_36) = (((*__tmp_36) as i32) & (__tmp_35 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & (((*(*copied.borrow()).1.borrow()) - && (({ (*(*copied.borrow()).0.borrow()).iter_deref() }) - .with(|__s| (*__s.1.borrow()).value) - == 20)) as i32)) - != 0; - ok = rhs_0 + match ( + { + (((*(*copied.borrow()).1.borrow()) + && (({ (*(*copied.borrow()).0.borrow()).iter_deref() }) + .with(|__s| (*__s.1.borrow()).value) + == 20)) as i32) + }, + &mut (ok), + ) { + (__tmp_37, __tmp_38) => { + (*__tmp_38) = (((*__tmp_38) as i32) & (__tmp_37 as i32)) != 0; + } + } }; (*key.borrow_mut()).prefix_inc(); let moved: Value<( @@ -493,12 +603,12 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_9,) => { + (__tmp_39,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_9).clone() }))), + Rc::new(RefCell::new(Item::move_from({ (__tmp_39).clone() }))), ) }); ( @@ -508,22 +618,36 @@ fn main_0() -> i32 { } }, )); - ok = { - ((ok as i32) - & (((((calls_0.with(|rc| *rc.borrow()) == 4) && (made_1.with(|rc| *rc.borrow()) == 0)) - && (copies_2.with(|rc| *rc.borrow()) == 1)) - && (moves_3.with(|rc| *rc.borrow()) == 1)) as i32)) - != 0 + { + match ( + { + (((((calls_0.with(|rc| *rc.borrow()) == 4) + && (made_1.with(|rc| *rc.borrow()) == 0)) + && (copies_2.with(|rc| *rc.borrow()) == 1)) + && (moves_3.with(|rc| *rc.borrow()) == 1)) as i32) + }, + &mut (ok), + ) { + (__tmp_40, __tmp_41) => { + (*__tmp_41) = (((*__tmp_41) as i32) & (__tmp_40 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & ((((*(*moved.borrow()).1.borrow()) - && (({ (*(*moved.borrow()).0.borrow()).iter_deref() }) - .with(|__s| (*__s.1.borrow()).value) - == 20)) - && ({ (*source.borrow()).value } == -1_i32)) as i32)) - != 0; - ok = rhs_0 + match ( + { + ((((*(*moved.borrow()).1.borrow()) + && (({ (*(*moved.borrow()).0.borrow()).iter_deref() }) + .with(|__s| (*__s.1.borrow()).value) + == 20)) + && ({ (*source.borrow()).value } == -1_i32)) as i32) + }, + &mut (ok), + ) { + (__tmp_42, __tmp_43) => { + (*__tmp_43) = (((*__tmp_43) as i32) & (__tmp_42 as i32)) != 0; + } + } }; let refs: Value, Value)>> = Rc::new(RefCell::new(Map::new())); (*key.borrow_mut()) = 0; @@ -548,11 +672,11 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ reference_5(counter.as_pointer()) }),) { - (__tmp_10,) => { + (__tmp_44,) => { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(RefItem::new_2({ (__tmp_10).clone() }, { 2 }))), + Rc::new(RefCell::new(RefItem::new_2({ (__tmp_44).clone() }, { 2 }))), ) }); ( @@ -562,12 +686,19 @@ fn main_0() -> i32 { } }, )); - ok = { - ((ok as i32) - & (((((calls_0.with(|rc| *rc.borrow()) == 5) && ((*counter.borrow()) == 5)) - && (made_1.with(|rc| *rc.borrow()) == 0)) - && (!(*(*ref_hit.borrow()).1.borrow()))) as i32)) - != 0 + { + match ( + { + (((((calls_0.with(|rc| *rc.borrow()) == 5) && ((*counter.borrow()) == 5)) + && (made_1.with(|rc| *rc.borrow()) == 0)) + && (!(*(*ref_hit.borrow()).1.borrow()))) as i32) + }, + &mut (ok), + ) { + (__tmp_45, __tmp_46) => { + (*__tmp_46) = (((*__tmp_46) as i32) & (__tmp_45 as i32)) != 0; + } + } }; (*key.borrow_mut()).prefix_inc(); let ref_new: Value<( @@ -575,11 +706,11 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ reference_5(counter.as_pointer()) }),) { - (__tmp_11,) => { + (__tmp_47,) => { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(RefItem::new_2({ (__tmp_11).clone() }, { 2 }))), + Rc::new(RefCell::new(RefItem::new_2({ (__tmp_47).clone() }, { 2 }))), ) }); ( @@ -589,52 +720,76 @@ fn main_0() -> i32 { } }, )); - ok = { - ((ok as i32) - & (((((calls_0.with(|rc| *rc.borrow()) == 6) && ((*counter.borrow()) == 7)) - && (made_1.with(|rc| *rc.borrow()) == 1)) - && (*(*ref_new.borrow()).1.borrow())) as i32)) - != 0 + { + match ( + { + (((((calls_0.with(|rc| *rc.borrow()) == 6) && ((*counter.borrow()) == 7)) + && (made_1.with(|rc| *rc.borrow()) == 1)) + && (*(*ref_new.borrow()).1.borrow())) as i32) + }, + &mut (ok), + ) { + (__tmp_48, __tmp_49) => { + (*__tmp_49) = (((*__tmp_49) as i32) & (__tmp_48 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & (((({ (*(*ref_hit.borrow()).0.borrow()).iter_deref() }) - .with(|__s| (*__s.1.borrow()).value) - == 5) - && (({ (*(*ref_new.borrow()).0.borrow()).iter_deref() }) + match ( + { + (((({ (*(*ref_hit.borrow()).0.borrow()).iter_deref() }) .with(|__s| (*__s.1.borrow()).value) - == 7)) as i32)) - != 0; - ok = rhs_0 + == 5) + && (({ (*(*ref_new.borrow()).0.borrow()).iter_deref() }) + .with(|__s| (*__s.1.borrow()).value) + == 7)) as i32) + }, + &mut (ok), + ) { + (__tmp_50, __tmp_51) => { + (*__tmp_51) = (((*__tmp_51) as i32) & (__tmp_50 as i32)) != 0; + } + } }; (*key.borrow_mut()) = 0; made_1.with(|rc| { *rc.borrow_mut() = { - copies_2.with(|rc| { - *rc.borrow_mut() = { - moves_3.with(|rc| *rc.borrow_mut() = 0); - moves_3.with(|rc| *rc.borrow()) + match ( + { + { + match ({ 0 }, &mut (*moves_3.with(Value::clone).borrow_mut())) { + (__tmp_54, __tmp_55) => { + (*__tmp_55) = __tmp_54; + (*__tmp_55).clone() + } + } + } + }, + &mut (*copies_2.with(Value::clone).borrow_mut()), + ) { + (__tmp_52, __tmp_53) => { + (*__tmp_53) = __tmp_52; + (*__tmp_53).clone() } - }); - copies_2.with(|rc| *rc.borrow()) + } } }); let temporary_hit: Value<( Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_13: Value; + let __tmp_57: Value; match ({ - __tmp_13 = Rc::new(RefCell::new(Item::new_1({ 30 }))); - __tmp_13.as_pointer() + __tmp_57 = Rc::new(RefCell::new(Item::new_1({ 30 }))); + __tmp_57.as_pointer() },) { - (__tmp_12,) => { + (__tmp_56,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_12).clone() }))), + Rc::new(RefCell::new(Item::move_from({ (__tmp_56).clone() }))), ) }); ( @@ -644,13 +799,20 @@ fn main_0() -> i32 { } } })); - ok = { - ((ok as i32) - & (((((made_1.with(|rc| *rc.borrow()) == 1) - && (copies_2.with(|rc| *rc.borrow()) == 0)) - && (moves_3.with(|rc| *rc.borrow()) == 0)) - && (!(*(*temporary_hit.borrow()).1.borrow()))) as i32)) - != 0 + { + match ( + { + (((((made_1.with(|rc| *rc.borrow()) == 1) + && (copies_2.with(|rc| *rc.borrow()) == 0)) + && (moves_3.with(|rc| *rc.borrow()) == 0)) + && (!(*(*temporary_hit.borrow()).1.borrow()))) as i32) + }, + &mut (ok), + ) { + (__tmp_58, __tmp_59) => { + (*__tmp_59) = (((*__tmp_59) as i32) & (__tmp_58 as i32)) != 0; + } + } }; (*key.borrow_mut()).prefix_inc(); (*key.borrow_mut()).prefix_inc(); @@ -659,18 +821,18 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_15: Value; + let __tmp_61: Value; match ({ - __tmp_15 = Rc::new(RefCell::new(Item::new_1({ 40 }))); - __tmp_15.as_pointer() + __tmp_61 = Rc::new(RefCell::new(Item::new_1({ 40 }))); + __tmp_61.as_pointer() },) { - (__tmp_14,) => { + (__tmp_60,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_14).clone() }))), + Rc::new(RefCell::new(Item::move_from({ (__tmp_60).clone() }))), ) }); ( @@ -680,21 +842,34 @@ fn main_0() -> i32 { } } })); - ok = { - ((ok as i32) - & (((((made_1.with(|rc| *rc.borrow()) == 2) - && (copies_2.with(|rc| *rc.borrow()) == 0)) - && (moves_3.with(|rc| *rc.borrow()) == 1)) - && (*(*temporary_new.borrow()).1.borrow())) as i32)) - != 0 + { + match ( + { + (((((made_1.with(|rc| *rc.borrow()) == 2) + && (copies_2.with(|rc| *rc.borrow()) == 0)) + && (moves_3.with(|rc| *rc.borrow()) == 1)) + && (*(*temporary_new.borrow()).1.borrow())) as i32) + }, + &mut (ok), + ) { + (__tmp_62, __tmp_63) => { + (*__tmp_63) = (((*__tmp_63) as i32) & (__tmp_62 as i32)) != 0; + } + } }; { - let rhs_0 = ((ok as i32) - & ((({ (*(*temporary_new.borrow()).0.borrow()).iter_deref() }) - .with(|__s| (*__s.1.borrow()).value) - == 40) as i32)) - != 0; - ok = rhs_0 + match ( + { + ((({ (*(*temporary_new.borrow()).0.borrow()).iter_deref() }) + .with(|__s| (*__s.1.borrow()).value) + == 40) as i32) + }, + &mut (ok), + ) { + (__tmp_64, __tmp_65) => { + (*__tmp_65) = (((*__tmp_65) as i32) & (__tmp_64 as i32)) != 0; + } + } }; printf!( b"%d %d %d %d %d\n", diff --git a/tests/unit/out/refcount/map_try_emplace_lvalues.rs b/tests/unit/out/refcount/map_try_emplace_lvalues.rs index 906db21ba5..ff9bdbbe5b 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -25,11 +25,12 @@ impl Item { pub fn new_2(counter: Ptr, mut amount: i32) -> Self { let __this: Item = Self { value: { - { - let __rhs = { amount }; - counter.with_mut(|__v| *__v = *__v + __rhs) - }; - (counter.read()) + match ({ amount }, &(counter)) { + (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { + (*__tmp_1) = (((*__tmp_1) as i32) + (__tmp_0 as i32)) as i32; + (*__tmp_1).clone() + }), + } }, }; (*made_0.with(Value::clone).borrow_mut()).prefix_inc(); @@ -179,22 +180,22 @@ thread_local!( Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_2: Value; + let __tmp_4: Value; match ((match { - __tmp_2 = Rc::new(RefCell::new(({ make_temporary_5() }))); - __tmp_2.as_pointer() + __tmp_4 = Rc::new(RefCell::new(({ make_temporary_5() }))); + __tmp_4.as_pointer() } { - __tmp_1 => field_ptr!(__tmp_1, n), + __tmp_3 => field_ptr!(__tmp_3, n), }),) { - (__tmp_0,) => { + (__tmp_2,) => { let (__it, __inserted) = Map::emplace( global_values_7.with(|v| v.as_pointer()), &global_key_8.with(|v| v.as_pointer()), || { ( Rc::new(RefCell::new(global_key_8.with(|v| v.as_pointer()).read())), - Rc::new(RefCell::new((__tmp_0.read()))), + Rc::new(RefCell::new((__tmp_2.read()))), ) }, ); @@ -213,23 +214,23 @@ thread_local!( )> = Rc::new(RefCell::new( match (if global_choose_13.with(|rc| *rc.borrow()) { { - let __tmp_4 = global_a_11.with(|v| v.as_pointer()); - __tmp_4.with_mut(|__v| { + let __tmp_6 = global_a_11.with(|v| v.as_pointer()); + __tmp_6.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_4 + __tmp_6 } } else { { - let __tmp_5 = global_b_12.with(|v| v.as_pointer()); - __tmp_5.with_mut(|__v| { + let __tmp_7 = global_b_12.with(|v| v.as_pointer()); + __tmp_7.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_5 + __tmp_7 } },) { - (__tmp_3,) => { + (__tmp_5,) => { let (__it, __inserted) = Map::emplace( global_values_7.with(|v| v.as_pointer()), &conditional_key_9.with(|v| v.as_pointer()), @@ -238,7 +239,7 @@ thread_local!( Rc::new(RefCell::new( conditional_key_9.with(|v| v.as_pointer()).read(), )), - Rc::new(RefCell::new((__tmp_3.read()))), + Rc::new(RefCell::new((__tmp_5.read()))), ) }, ); @@ -255,24 +256,24 @@ thread_local!( Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_7: Option>; + let mut __tmp_9: Option>; match (field_ptr!( (*{ - __tmp_7 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_7 + __tmp_9 = Some(Rc::new(RefCell::new(Temporary::new()))); + &mut __tmp_9 }) .as_pointer(), n ),) { - (__tmp_6,) => { + (__tmp_8,) => { let (__it, __inserted) = Map::emplace( global_values_7.with(|v| v.as_pointer()), &owned_key_10.with(|v| v.as_pointer()), || { ( Rc::new(RefCell::new(owned_key_10.with(|v| v.as_pointer()).read())), - Rc::new(RefCell::new((__tmp_6.read()))), + Rc::new(RefCell::new((__tmp_8.read()))), ) }, ); @@ -361,19 +362,20 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ receiver_2(m.as_pointer()) }), { - let __tmp_10 = ({ place_3(counter.as_pointer()) }); - __tmp_10.with_mut(|__v| { + let __tmp_12 = ({ place_3(counter.as_pointer()) }); + __tmp_12.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_10 + __tmp_12 }) { - (__tmp_8, __tmp_9) => { - let (__it, __inserted) = Map::emplace((__tmp_8).clone(), &key.as_pointer(), || { - ( - Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_9).clone() }, { 2 }))), - ) - }); + (__tmp_10, __tmp_11) => { + let (__it, __inserted) = + Map::emplace((__tmp_10).clone(), &key.as_pointer(), || { + ( + Rc::new(RefCell::new(key.as_pointer().read())), + Rc::new(RefCell::new(Item::new_2({ (__tmp_11).clone() }, { 2 }))), + ) + }); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -394,18 +396,18 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match ({ - let __tmp_12 = counter.as_pointer(); - __tmp_12.with_mut(|__v| { + let __tmp_14 = counter.as_pointer(); + __tmp_14.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_12 + __tmp_14 },) { - (__tmp_11,) => { + (__tmp_13,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_11).clone() }, { 2 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_13).clone() }, { 2 }))), ) }); ( @@ -426,17 +428,17 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (match ({ 9 }, counter.as_pointer()) { - (__tmp_15, __tmp_14) => { - __tmp_14.write(__tmp_15); - __tmp_14 + (__tmp_17, __tmp_16) => { + __tmp_16.write(__tmp_17); + __tmp_16 } },) { - (__tmp_13,) => { + (__tmp_15,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_13).clone() }, { 2 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_15).clone() }, { 2 }))), ) }); ( @@ -458,17 +460,17 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (match ({ 4 }, counter.as_pointer()) { - (__tmp_18, __tmp_17) => { - __tmp_17.with_mut(|__v| *__v = (((*__v) as i32) + (__tmp_18 as i32)) as i32); - __tmp_17 + (__tmp_20, __tmp_19) => { + __tmp_19.with_mut(|__v| *__v = (((*__v) as i32) + (__tmp_20 as i32)) as i32); + __tmp_19 } },) { - (__tmp_16,) => { + (__tmp_18,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_16).clone() }, { 2 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_18).clone() }, { 2 }))), ) }); ( @@ -498,18 +500,18 @@ fn main_0() -> i32 { let mut index: i32 = 0; (*key.borrow_mut()).prefix_inc(); match ({ - let __tmp_20 = array.decay().offset(index.postfix_inc()); - __tmp_20.with_mut(|__v| { + let __tmp_22 = array.decay().offset(index.postfix_inc()); + __tmp_22.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_20 + __tmp_22 },) { - (__tmp_19,) => { + (__tmp_21,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_19).clone() }, { 3 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_21).clone() }, { 3 }))), ) }); ( @@ -526,17 +528,17 @@ fn main_0() -> i32 { ); (*key.borrow_mut()).prefix_inc(); match (match ({ 5 }, array.decay().offset(index.postfix_inc())) { - (__tmp_23, __tmp_22) => { - __tmp_22.write(__tmp_23); - __tmp_22 + (__tmp_25, __tmp_24) => { + __tmp_24.write(__tmp_25); + __tmp_24 } },) { - (__tmp_21,) => { + (__tmp_23,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_21).clone() }, { 3 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_23).clone() }, { 3 }))), ) }); ( @@ -553,17 +555,17 @@ fn main_0() -> i32 { ); match ( match ({ ((*counter.borrow()) + 1) }, counter.as_pointer()) { - (__tmp_26, __tmp_25) => { - __tmp_25.write(__tmp_26); - __tmp_25 + (__tmp_28, __tmp_27) => { + __tmp_27.write(__tmp_28); + __tmp_27 } }, ) { - (__tmp_24,) => { + (__tmp_26,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_24).clone() }, { 3 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_26).clone() }, { 3 }))), ) }); ( @@ -578,27 +580,27 @@ fn main_0() -> i32 { let mut choose: bool = false; match (if choose { { - let __tmp_28 = a.as_pointer(); - __tmp_28.with_mut(|__v| { + let __tmp_30 = a.as_pointer(); + __tmp_30.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_28 + __tmp_30 } } else { { - let __tmp_29 = b.as_pointer(); - __tmp_29.with_mut(|__v| { + let __tmp_31 = b.as_pointer(); + __tmp_31.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_29 + __tmp_31 } },) { - (__tmp_27,) => { + (__tmp_29,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_27).clone() }, { 3 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_29).clone() }, { 3 }))), ) }); ( @@ -615,27 +617,27 @@ fn main_0() -> i32 { choose = true; match (if choose { { - let __tmp_31 = a.as_pointer(); - __tmp_31.with_mut(|__v| { + let __tmp_33 = a.as_pointer(); + __tmp_33.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_31 + __tmp_33 } } else { { - let __tmp_32 = b.as_pointer(); - __tmp_32.with_mut(|__v| { + let __tmp_34 = b.as_pointer(); + __tmp_34.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_32 + __tmp_34 } },) { - (__tmp_30,) => { + (__tmp_32,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_30).clone() }, { 3 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_32).clone() }, { 3 }))), ) }); ( @@ -654,11 +656,11 @@ fn main_0() -> i32 { counter.as_pointer() },) { - (__tmp_33,) => { + (__tmp_35,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_33).clone() }, { 3 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_35).clone() }, { 3 }))), ) }); ( @@ -675,20 +677,20 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (match ({ 1_u32 }, n.as_pointer()) { - (__tmp_36, __tmp_35) => { - __tmp_35.with_mut(|__v| { - *__v = (((*__v) as u32).wrapping_add((__tmp_36 as u32))) as u32 + (__tmp_38, __tmp_37) => { + __tmp_37.with_mut(|__v| { + *__v = (((*__v) as u32).wrapping_add((__tmp_38 as u32))) as u32 }); - __tmp_35 + __tmp_37 } },) { - (__tmp_34,) => { + (__tmp_36,) => { let (__it, __inserted) = Map::emplace(unsigned_map.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new((__tmp_34.read()))), + Rc::new(RefCell::new((__tmp_36.read()))), ) }); ( @@ -717,18 +719,18 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (match ({ 2 }, bytes.decay().offset(index.postfix_inc())) { - (__tmp_39, __tmp_38) => { - __tmp_38.with_mut(|__v| *__v = (((*__v) as i32) + (__tmp_39 as i32)) as u8); - __tmp_38 + (__tmp_41, __tmp_40) => { + __tmp_40.with_mut(|__v| *__v = (((*__v) as i32) + (__tmp_41 as i32)) as u8); + __tmp_40 } },) { - (__tmp_37,) => { + (__tmp_39,) => { let (__it, __inserted) = Map::emplace(unsigned_map.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(((__tmp_37.read()) as u32))), + Rc::new(RefCell::new(((__tmp_39.read()) as u32))), ) }); ( @@ -759,20 +761,20 @@ fn main_0() -> i32 { match ({ Map::erase_key(changed.as_pointer(), &key.as_pointer()); { - let __tmp_41 = effects.as_pointer(); - __tmp_41.with_mut(|__v| { + let __tmp_43 = effects.as_pointer(); + __tmp_43.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_41 + __tmp_43 } },) { - (__tmp_40,) => { + (__tmp_42,) => { let (__it, __inserted) = Map::emplace(changed.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new((__tmp_40.read()))), + Rc::new(RefCell::new((__tmp_42.read()))), ) }); ( @@ -802,20 +804,20 @@ fn main_0() -> i32 { __v.prefix_inc(); }); { - let __tmp_43 = effects.as_pointer(); - __tmp_43.with_mut(|__v| { + let __tmp_45 = effects.as_pointer(); + __tmp_45.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_43 + __tmp_45 } },) { - (__tmp_42,) => { + (__tmp_44,) => { let (__it, __inserted) = Map::emplace(changed.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new((__tmp_42.read()))), + Rc::new(RefCell::new((__tmp_44.read()))), ) }); ( @@ -844,18 +846,18 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (match ({ 1 }, p.as_pointer()) { - (__tmp_46, __tmp_45) => { - __tmp_45.with_mut(|__v| *__v = (*__v).offset((__tmp_46 as isize))); - __tmp_45 + (__tmp_48, __tmp_47) => { + __tmp_47.with_mut(|__v| *__v = (*__v).offset((__tmp_48 as isize))); + __tmp_47 } },) { - (__tmp_44,) => { + (__tmp_46,) => { let (__it, __inserted) = Map::emplace(pointers.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new((__tmp_44.read()))), + Rc::new(RefCell::new((__tmp_46.read()))), ) }); ( @@ -904,19 +906,19 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match ({ - let __tmp_48 = moved.as_pointer(); - __tmp_48.with_mut(|__v| { + let __tmp_50 = moved.as_pointer(); + __tmp_50.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_48 + __tmp_50 },) { - (__tmp_47,) => { + (__tmp_49,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(0), || { ( Rc::new(RefCell::new(keys.decay().offset(0).read())), - Rc::new(RefCell::new((__tmp_47.read()))), + Rc::new(RefCell::new((__tmp_49.read()))), ) }); ( @@ -931,19 +933,19 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match ({ - let __tmp_50 = forwarded.as_pointer(); - __tmp_50.with_mut(|__v| { + let __tmp_52 = forwarded.as_pointer(); + __tmp_52.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_50 + __tmp_52 },) { - (__tmp_49,) => { + (__tmp_51,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(1), || { ( Rc::new(RefCell::new(keys.decay().offset(1).read())), - Rc::new(RefCell::new((__tmp_49.read()))), + Rc::new(RefCell::new((__tmp_51.read()))), ) }); ( @@ -958,19 +960,19 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match ({ - let __tmp_52 = xvalue.as_pointer(); - __tmp_52.with_mut(|__v| { + let __tmp_54 = xvalue.as_pointer(); + __tmp_54.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_52 + __tmp_54 },) { - (__tmp_51,) => { + (__tmp_53,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(2), || { ( Rc::new(RefCell::new(keys.decay().offset(2).read())), - Rc::new(RefCell::new((__tmp_51.read()))), + Rc::new(RefCell::new((__tmp_53.read()))), ) }); ( @@ -985,19 +987,19 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match ({ - let __tmp_54 = lvalue.as_pointer(); - __tmp_54.with_mut(|__v| { + let __tmp_56 = lvalue.as_pointer(); + __tmp_56.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_54 + __tmp_56 },) { - (__tmp_53,) => { + (__tmp_55,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(3), || { ( Rc::new(RefCell::new(keys.decay().offset(3).read())), - Rc::new(RefCell::new((__tmp_53.read()))), + Rc::new(RefCell::new((__tmp_55.read()))), ) }); ( @@ -1012,18 +1014,18 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (match ({ 5 }, assigned.as_pointer()) { - (__tmp_57, __tmp_56) => { - __tmp_56.write(__tmp_57); - __tmp_56 + (__tmp_59, __tmp_58) => { + __tmp_58.write(__tmp_59); + __tmp_58 } },) { - (__tmp_55,) => { + (__tmp_57,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(4), || { ( Rc::new(RefCell::new(keys.decay().offset(4).read())), - Rc::new(RefCell::new((__tmp_55.read()))), + Rc::new(RefCell::new((__tmp_57.read()))), ) }); ( @@ -1038,20 +1040,20 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (match ({ 1 }, nested.as_pointer()) { - (__tmp_60, __tmp_59) => { - __tmp_59.with_mut(|__v| { - *__v = (((*__v) as i32) + (__tmp_60 as i32)) as i32 + (__tmp_62, __tmp_61) => { + __tmp_61.with_mut(|__v| { + *__v = (((*__v) as i32) + (__tmp_62 as i32)) as i32 }); - __tmp_59 + __tmp_61 } },) { - (__tmp_58,) => { + (__tmp_60,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(5), || { ( Rc::new(RefCell::new(keys.decay().offset(5).read())), - Rc::new(RefCell::new((__tmp_58.read()))), + Rc::new(RefCell::new((__tmp_60.read()))), ) }); ( @@ -1139,23 +1141,23 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new( match (if (choose != 0) { { - let __tmp_62 = a.as_pointer(); - __tmp_62.with_mut(|__v| { + let __tmp_64 = a.as_pointer(); + __tmp_64.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_62 + __tmp_64 } } else { { - let __tmp_63 = b.as_pointer(); - __tmp_63.with_mut(|__v| { + let __tmp_65 = b.as_pointer(); + __tmp_65.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_63 + __tmp_65 } },) { - (__tmp_61,) => { + (__tmp_63,) => { let (__it, __inserted) = Map::emplace( selected.as_pointer(), &keys.decay().offset(0), @@ -1165,7 +1167,7 @@ fn main_0() -> i32 { keys.decay().offset(0).read(), )), Rc::new(RefCell::new(Item::new_2( - { (__tmp_61).clone() }, + { (__tmp_63).clone() }, { 2 }, ))), ) @@ -1184,21 +1186,21 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new( match (if (choose != 0) { (match ({ 5 }, c.as_pointer()) { - (__tmp_66, __tmp_65) => { - __tmp_65.write(__tmp_66); - __tmp_65 + (__tmp_68, __tmp_67) => { + __tmp_67.write(__tmp_68); + __tmp_67 } }) } else { (match ({ 6 }, d.as_pointer()) { - (__tmp_68, __tmp_67) => { - __tmp_67.write(__tmp_68); - __tmp_67 + (__tmp_70, __tmp_69) => { + __tmp_69.write(__tmp_70); + __tmp_69 } }) },) { - (__tmp_64,) => { + (__tmp_66,) => { let (__it, __inserted) = Map::emplace( selected.as_pointer(), &keys.decay().offset(1), @@ -1208,7 +1210,7 @@ fn main_0() -> i32 { keys.decay().offset(1).read(), )), Rc::new(RefCell::new(Item::new_2( - { (__tmp_64).clone() }, + { (__tmp_66).clone() }, { 2 }, ))), ) @@ -1227,25 +1229,25 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new( match (if (choose != 0) { (match ({ 1 }, e.as_pointer()) { - (__tmp_71, __tmp_70) => { - __tmp_70.with_mut(|__v| { - *__v = (((*__v) as i32) + (__tmp_71 as i32)) as i32 + (__tmp_73, __tmp_72) => { + __tmp_72.with_mut(|__v| { + *__v = (((*__v) as i32) + (__tmp_73 as i32)) as i32 }); - __tmp_70 + __tmp_72 } }) } else { (match ({ 2 }, f.as_pointer()) { - (__tmp_73, __tmp_72) => { - __tmp_72.with_mut(|__v| { - *__v = (((*__v) as i32) + (__tmp_73 as i32)) as i32 + (__tmp_75, __tmp_74) => { + __tmp_74.with_mut(|__v| { + *__v = (((*__v) as i32) + (__tmp_75 as i32)) as i32 }); - __tmp_72 + __tmp_74 } }) },) { - (__tmp_69,) => { + (__tmp_71,) => { let (__it, __inserted) = Map::emplace( selected.as_pointer(), &keys.decay().offset(2), @@ -1255,7 +1257,7 @@ fn main_0() -> i32 { keys.decay().offset(2).read(), )), Rc::new(RefCell::new(Item::new_2( - { (__tmp_69).clone() }, + { (__tmp_71).clone() }, { 2 }, ))), ) @@ -1376,20 +1378,20 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_76: Value; + let __tmp_78: Value; match ((match { - __tmp_76 = Rc::new(RefCell::new(({ make_temporary_5() }))); - __tmp_76.as_pointer() + __tmp_78 = Rc::new(RefCell::new(({ make_temporary_5() }))); + __tmp_78.as_pointer() } { - __tmp_75 => field_ptr!(__tmp_75, n), + __tmp_77 => field_ptr!(__tmp_77, n), }),) { - (__tmp_74,) => { + (__tmp_76,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(0), || { ( Rc::new(RefCell::new(keys.decay().offset(0).read())), - Rc::new(RefCell::new((__tmp_74.read()))), + Rc::new(RefCell::new((__tmp_76.read()))), ) }); ( @@ -1403,20 +1405,20 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_79: Value; + let __tmp_81: Value; match ((match { - __tmp_79 = Rc::new(RefCell::new(({ make_nested_6() }))); - __tmp_79.as_pointer() + __tmp_81 = Rc::new(RefCell::new(({ make_nested_6() }))); + __tmp_81.as_pointer() } { - __tmp_78 => field_ptr!(field_ptr!(__tmp_78, inner), n), + __tmp_80 => field_ptr!(field_ptr!(__tmp_80, inner), n), }),) { - (__tmp_77,) => { + (__tmp_79,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(1), || { ( Rc::new(RefCell::new(keys.decay().offset(1).read())), - Rc::new(RefCell::new((__tmp_77.read()))), + Rc::new(RefCell::new((__tmp_79.read()))), ) }); ( @@ -1430,21 +1432,21 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_82: Value; + let __tmp_84: Value; match ((match { - __tmp_82 = Rc::new(RefCell::new(({ make_temporary_5() }))); - __tmp_82.as_pointer() + __tmp_84 = Rc::new(RefCell::new(({ make_temporary_5() }))); + __tmp_84.as_pointer() } { - __tmp_81 => array_field_ptr!(__tmp_81, data), + __tmp_83 => array_field_ptr!(__tmp_83, data), }) .offset((index.postfix_inc()) as isize),) { - (__tmp_80,) => { + (__tmp_82,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(2), || { ( Rc::new(RefCell::new(keys.decay().offset(2).read())), - Rc::new(RefCell::new((__tmp_80.read()))), + Rc::new(RefCell::new((__tmp_82.read()))), ) }); ( @@ -1517,28 +1519,28 @@ fn main_0() -> i32 { index = 0; let mut value: i32 = 0; { - let __tmp_85: Value; - let __tmp_87: Value; + let __tmp_87: Value; + let __tmp_89: Value; { match (if (choose != 0) { (match { - __tmp_85 = Rc::new(RefCell::new(({ make_nested_6() }))); - __tmp_85.as_pointer() + __tmp_87 = Rc::new(RefCell::new(({ make_nested_6() }))); + __tmp_87.as_pointer() } { - __tmp_84 => field_ptr!(field_ptr!(__tmp_84, inner), n), + __tmp_86 => field_ptr!(field_ptr!(__tmp_86, inner), n), }) } else { (match { - __tmp_87 = + __tmp_89 = Rc::new(RefCell::new(({ make_temporary_5() }))); - __tmp_87.as_pointer() + __tmp_89.as_pointer() } { - __tmp_86 => array_field_ptr!(__tmp_86, data), + __tmp_88 => array_field_ptr!(__tmp_88, data), }) .offset((index.postfix_inc()) as isize) },) { - (__tmp_83,) => { + (__tmp_85,) => { let (__it, __inserted) = Map::emplace( references.as_pointer(), &key.as_pointer(), @@ -1548,7 +1550,7 @@ fn main_0() -> i32 { key.as_pointer().read(), )), Rc::new(RefCell::new(Held::new_1({ - (__tmp_83).clone() + (__tmp_85).clone() }))), ) }, @@ -1607,29 +1609,29 @@ fn main_0() -> i32 { } before = temporary_calls_4.with(|rc| *rc.borrow()); { - let __tmp_90: Value; - let __tmp_92: Value; + let __tmp_92: Value; + let __tmp_94: Value; { match (if (choose != 0) { (match { - __tmp_90 = Rc::new(RefCell::new(({ make_nested_6() }))); - __tmp_90.as_pointer() + __tmp_92 = Rc::new(RefCell::new(({ make_nested_6() }))); + __tmp_92.as_pointer() } { - __tmp_89 => { - array_field_ptr!(field_ptr!(__tmp_89, inner), data) + __tmp_91 => { + array_field_ptr!(field_ptr!(__tmp_91, inner), data) } }) } else { (match { - __tmp_92 = + __tmp_94 = Rc::new(RefCell::new(({ make_temporary_5() }))); - __tmp_92.as_pointer() + __tmp_94.as_pointer() } { - __tmp_91 => array_field_ptr!(__tmp_91, data), + __tmp_93 => array_field_ptr!(__tmp_93, data), }) },) { - (__tmp_88,) => { + (__tmp_90,) => { let (__it, __inserted) = Map::emplace( arrays.as_pointer(), &key.as_pointer(), @@ -1639,7 +1641,7 @@ fn main_0() -> i32 { key.as_pointer().read(), )), Rc::new(RefCell::new(Held::new_3( - { (__tmp_88).clone() }, + { (__tmp_90).clone() }, { 0 }, ))), ) @@ -1696,22 +1698,22 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_94: Option>; + let mut __tmp_96: Option>; match (field_ptr!( (*{ - __tmp_94 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_94 + __tmp_96 = Some(Rc::new(RefCell::new(Temporary::new()))); + &mut __tmp_96 }) .as_pointer(), n ),) { - (__tmp_93,) => { + (__tmp_95,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(0), || { ( Rc::new(RefCell::new(keys.decay().offset(0).read())), - Rc::new(RefCell::new((__tmp_93.read()))), + Rc::new(RefCell::new((__tmp_95.read()))), ) }); ( @@ -1725,12 +1727,12 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_96: Option>; + let mut __tmp_98: Option>; match (field_ptr!( field_ptr!( (*{ - __tmp_96 = Some(Rc::new(RefCell::new(::default()))); - &mut __tmp_96 + __tmp_98 = Some(Rc::new(RefCell::new(::default()))); + &mut __tmp_98 }) .as_pointer(), inner @@ -1738,12 +1740,12 @@ fn main_0() -> i32 { n ),) { - (__tmp_95,) => { + (__tmp_97,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(1), || { ( Rc::new(RefCell::new(keys.decay().offset(1).read())), - Rc::new(RefCell::new((__tmp_95.read()))), + Rc::new(RefCell::new((__tmp_97.read()))), ) }); ( @@ -1757,23 +1759,23 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_98: Option>; + let mut __tmp_100: Option>; match (array_field_ptr!( (*{ - __tmp_98 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_98 + __tmp_100 = Some(Rc::new(RefCell::new(Temporary::new()))); + &mut __tmp_100 }) .as_pointer(), data ) .offset((index.postfix_inc()) as isize),) { - (__tmp_97,) => { + (__tmp_99,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(2), || { ( Rc::new(RefCell::new(keys.decay().offset(2).read())), - Rc::new(RefCell::new((__tmp_97.read()))), + Rc::new(RefCell::new((__tmp_99.read()))), ) }); ( @@ -1787,22 +1789,22 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_100: Option>; + let mut __tmp_102: Option>; match (field_ptr!( (*{ - __tmp_100 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_100 + __tmp_102 = Some(Rc::new(RefCell::new(Temporary::new()))); + &mut __tmp_102 }) .as_pointer(), n ),) { - (__tmp_99,) => { + (__tmp_101,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(3), || { ( Rc::new(RefCell::new(keys.decay().offset(3).read())), - Rc::new(RefCell::new((__tmp_99.read()))), + Rc::new(RefCell::new((__tmp_101.read()))), ) }); ( @@ -1816,22 +1818,22 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_102: Option>; + let mut __tmp_104: Option>; match (field_ptr!( ((*{ - __tmp_102 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_102 + __tmp_104 = Some(Rc::new(RefCell::new(Temporary::new()))); + &mut __tmp_104 }) .as_pointer()), n ),) { - (__tmp_101,) => { + (__tmp_103,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(4), || { ( Rc::new(RefCell::new(keys.decay().offset(4).read())), - Rc::new(RefCell::new((__tmp_101.read()))), + Rc::new(RefCell::new((__tmp_103.read()))), ) }); ( @@ -1845,13 +1847,13 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_104: Option>>>; + let mut __tmp_106: Option>>>; match (field_ptr!( ((*(*{ - __tmp_104 = Some(Rc::new(RefCell::new(Some(Rc::new(RefCell::new( + __tmp_106 = Some(Rc::new(RefCell::new(Some(Rc::new(RefCell::new( Temporary::new(), )))))); - &mut __tmp_104 + &mut __tmp_106 }) .as_pointer() .upgrade() @@ -1860,12 +1862,12 @@ fn main_0() -> i32 { n ),) { - (__tmp_103,) => { + (__tmp_105,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(5), || { ( Rc::new(RefCell::new(keys.decay().offset(5).read())), - Rc::new(RefCell::new((__tmp_103.read()))), + Rc::new(RefCell::new((__tmp_105.read()))), ) }); ( @@ -1936,15 +1938,15 @@ fn main_0() -> i32 { index = 0; let mut value: i32 = 0; { - let mut __tmp_106: Option>; - let mut __tmp_107: Option>; + let mut __tmp_108: Option>; + let mut __tmp_109: Option>; { match (if (choose != 0) { field_ptr!( (*{ - __tmp_106 = + __tmp_108 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_106 + &mut __tmp_108 }) .as_pointer(), n @@ -1952,9 +1954,9 @@ fn main_0() -> i32 { } else { array_field_ptr!( (*{ - __tmp_107 = + __tmp_109 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_107 + &mut __tmp_109 }) .as_pointer(), data @@ -1962,7 +1964,7 @@ fn main_0() -> i32 { .offset((index.postfix_inc()) as isize) },) { - (__tmp_105,) => { + (__tmp_107,) => { let (__it, __inserted) = Map::emplace( references.as_pointer(), &key.as_pointer(), @@ -1972,7 +1974,7 @@ fn main_0() -> i32 { key.as_pointer().read(), )), Rc::new(RefCell::new(Held::new_1({ - (__tmp_105).clone() + (__tmp_107).clone() }))), ) }, @@ -2007,16 +2009,16 @@ fn main_0() -> i32 { let owners: Value, Value)>> = Rc::new(RefCell::new(Map::new())); { - let __tmp_109: Value; + let __tmp_111: Value; { match (({ OwnerImpl::value(&{ - __tmp_109 = Rc::new(RefCell::new(Owner::new())); - __tmp_109.as_pointer() + __tmp_111 = Rc::new(RefCell::new(Owner::new())); + __tmp_111.as_pointer() }) }),) { - (__tmp_108,) => { + (__tmp_110,) => { let (__it, __inserted) = Map::emplace( owners.as_pointer(), &key.as_pointer(), @@ -2026,7 +2028,7 @@ fn main_0() -> i32 { key.as_pointer().read(), )), Rc::new(RefCell::new(Held::new_1({ - (__tmp_108).clone() + (__tmp_110).clone() }))), ) }, @@ -2073,22 +2075,22 @@ fn main_0() -> i32 { >, Value, )> = Rc::new(RefCell::new({ - let __tmp_111: Value>>; + let __tmp_113: Value>>; match ({ - __tmp_111 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( + __tmp_113 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( ::default(), ))))); - __tmp_111.as_pointer() + __tmp_113.as_pointer() },) { - (__tmp_110,) => { + (__tmp_112,) => { let (__it, __inserted) = Map::emplace(move_only.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), Rc::new(RefCell::new(( Rc::new(RefCell::new( - __tmp_110 + __tmp_112 .with_mut(|__v: &mut Option>| __v.take()), )), Rc::new(RefCell::new(7)), @@ -2111,22 +2113,22 @@ fn main_0() -> i32 { >, Value, )> = Rc::new(RefCell::new({ - let __tmp_113: Value>>; + let __tmp_115: Value>>; match ({ - __tmp_113 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( + __tmp_115 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( ::default(), ))))); - __tmp_113.as_pointer() + __tmp_115.as_pointer() },) { - (__tmp_112,) => { + (__tmp_114,) => { let (__it, __inserted) = Map::emplace(move_only.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), Rc::new(RefCell::new(( Rc::new(RefCell::new( - __tmp_112 + __tmp_114 .with_mut(|__v: &mut Option>| __v.take()), )), Rc::new(RefCell::new(9)), @@ -2196,13 +2198,13 @@ fn main_0() -> i32 { text.as_pointer() },) { - (__tmp_114,) => { + (__tmp_116,) => { let (__it, __inserted) = Map::emplace(strings.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), Rc::new(RefCell::new( - __tmp_114.with_mut(|__v| std::mem::replace(__v, vec![0])), + __tmp_116.with_mut(|__v| std::mem::replace(__v, vec![0])), )), ) }); @@ -2231,13 +2233,13 @@ fn main_0() -> i32 { text.as_pointer() },) { - (__tmp_115,) => { + (__tmp_117,) => { let (__it, __inserted) = Map::emplace(strings.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), Rc::new(RefCell::new( - __tmp_115.with_mut(|__v| std::mem::replace(__v, vec![0])), + __tmp_117.with_mut(|__v| std::mem::replace(__v, vec![0])), )), ) }); @@ -2257,9 +2259,9 @@ fn main_0() -> i32 { .1 .as_pointer(),) { - (__tmp_116,) => Ptr::::from_string_literal(b"value").with_c_str(|__s| { - (*__tmp_116.upgrade().deref()) - [..(*__tmp_116.upgrade().deref()).len().saturating_sub(1)] + (__tmp_118,) => Ptr::::from_string_literal(b"value").with_c_str(|__s| { + (*__tmp_118.upgrade().deref()) + [..(*__tmp_118.upgrade().deref()).len().saturating_sub(1)] == *__s }), }) diff --git a/tests/unit/out/refcount/operator_compound_assignment_free.rs b/tests/unit/out/refcount/operator_compound_assignment_free.rs index 4d7df98b39..76509ce0db 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_free.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_free.rs @@ -13,23 +13,53 @@ pub struct S { pub v: u32, } pub fn operator_add_assign_0(a: Ptr, b: Ptr) -> Ptr { - field!(a, v).write({ (a.with(|__s| __s.v)).wrapping_add(b.with(|__s| __s.v)) }); + { + match ({ b.with(|__s| __s.v) }, &(field!(a, v))) { + (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { + (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; + }), + } + }; return (a).clone(); } pub fn operator_sub_assign_1(a: Ptr, b: Ptr) -> Ptr { - field!(a, v).write({ (a.with(|__s| __s.v)).wrapping_sub(b.with(|__s| __s.v)) }); + { + match ({ b.with(|__s| __s.v) }, &(field!(a, v))) { + (__tmp_2, __tmp_3) => __tmp_3.with_mut(|__tmp_3| { + (*__tmp_3) = (((*__tmp_3) as u32).wrapping_sub((__tmp_2 as u32))) as u32; + }), + } + }; return (a).clone(); } pub fn operator_mul_assign_2(a: Ptr, b: Ptr) -> Ptr { - field!(a, v).write({ (a.with(|__s| __s.v)).wrapping_mul(b.with(|__s| __s.v)) }); + { + match ({ b.with(|__s| __s.v) }, &(field!(a, v))) { + (__tmp_4, __tmp_5) => __tmp_5.with_mut(|__tmp_5| { + (*__tmp_5) = (((*__tmp_5) as u32).wrapping_mul((__tmp_4 as u32))) as u32; + }), + } + }; return (a).clone(); } pub fn operator_div_assign_3(a: Ptr, b: Ptr) -> Ptr { - field!(a, v).write({ (a.with(|__s| __s.v)).wrapping_div(b.with(|__s| __s.v)) }); + { + match ({ b.with(|__s| __s.v) }, &(field!(a, v))) { + (__tmp_6, __tmp_7) => __tmp_7.with_mut(|__tmp_7| { + (*__tmp_7) = (((*__tmp_7) as u32).wrapping_div((__tmp_6 as u32))) as u32; + }), + } + }; return (a).clone(); } pub fn operator_rem_assign_4(a: Ptr, b: Ptr) -> Ptr { - field!(a, v).write({ (a.with(|__s| __s.v)).wrapping_rem(b.with(|__s| __s.v)) }); + { + match ({ b.with(|__s| __s.v) }, &(field!(a, v))) { + (__tmp_8, __tmp_9) => __tmp_9.with_mut(|__tmp_9| { + (*__tmp_9) = (((*__tmp_9) as u32).wrapping_rem((__tmp_8 as u32))) as u32; + }), + } + }; return (a).clone(); } pub fn operator_bitand_assign_5(a: Ptr, b: Ptr) -> Ptr { diff --git a/tests/unit/out/refcount/operator_compound_assignment_member.rs b/tests/unit/out/refcount/operator_compound_assignment_member.rs index 4452be00d5..d33ff8a464 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_member.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_member.rs @@ -76,23 +76,53 @@ impl SImpl for Ptr { return (*self).clone(); } fn operator_add_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_add(o.with(|__s| __s.v)) }); + { + match ({ o.with(|__s| __s.v) }, &(field!((*self), v))) { + (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { + (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; + }), + } + }; return (*self).clone(); } fn operator_sub_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_sub(o.with(|__s| __s.v)) }); + { + match ({ o.with(|__s| __s.v) }, &(field!((*self), v))) { + (__tmp_2, __tmp_3) => __tmp_3.with_mut(|__tmp_3| { + (*__tmp_3) = (((*__tmp_3) as u32).wrapping_sub((__tmp_2 as u32))) as u32; + }), + } + }; return (*self).clone(); } fn operator_mul_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_mul(o.with(|__s| __s.v)) }); + { + match ({ o.with(|__s| __s.v) }, &(field!((*self), v))) { + (__tmp_4, __tmp_5) => __tmp_5.with_mut(|__tmp_5| { + (*__tmp_5) = (((*__tmp_5) as u32).wrapping_mul((__tmp_4 as u32))) as u32; + }), + } + }; return (*self).clone(); } fn operator_div_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_div(o.with(|__s| __s.v)) }); + { + match ({ o.with(|__s| __s.v) }, &(field!((*self), v))) { + (__tmp_6, __tmp_7) => __tmp_7.with_mut(|__tmp_7| { + (*__tmp_7) = (((*__tmp_7) as u32).wrapping_div((__tmp_6 as u32))) as u32; + }), + } + }; return (*self).clone(); } fn operator_rem_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_rem(o.with(|__s| __s.v)) }); + { + match ({ o.with(|__s| __s.v) }, &(field!((*self), v))) { + (__tmp_8, __tmp_9) => __tmp_9.with_mut(|__tmp_9| { + (*__tmp_9) = (((*__tmp_9) as u32).wrapping_rem((__tmp_8 as u32))) as u32; + }), + } + }; return (*self).clone(); } fn operator_bitand_assign(&self, o: Ptr) -> Ptr { diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index e329c56467..03b2ae6611 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -35,9 +35,27 @@ fn main_0() -> i32 { (chain == (((20 + 10) + 5) as usize).wrapping_add((::std::mem::size_of::() as usize))) ); let mut acc: usize = 100_usize; - acc = { ((acc as u64).wrapping_add((::std::mem::size_of::() as u64))) as usize }; - acc = { (acc).wrapping_mul(2_usize) }; - acc = { ((acc as u64).wrapping_sub((*ul.borrow()))) as usize }; + { + match ({ ::std::mem::size_of::() }, &mut (acc)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as u64).wrapping_add((__tmp_0 as u64))) as usize; + } + } + }; + { + match ({ 2_usize }, &mut (acc)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (((*__tmp_3) as usize).wrapping_mul((__tmp_2 as usize))) as usize; + } + } + }; + { + match ({ (*ul.borrow()) }, &mut (acc)) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = (((*__tmp_5) as u64).wrapping_sub((__tmp_4 as u64))) as usize; + } + } + }; assert!( (acc == ((((100_usize).wrapping_add((::std::mem::size_of::() as usize))) as usize) .wrapping_mul(2_usize) as usize) @@ -58,37 +76,37 @@ fn main_0() -> i32 { let mut fr2: u64 = ({ take_ulong_1((sz as u64)) }); assert!((fr2 == 21_u64)); let mut lo: usize = (({ - let __tmp_0: Value = Rc::new(RefCell::new( + let __tmp_6: Value = Rc::new(RefCell::new( (::std::mem::size_of::() as u64).wrapping_add((*ul.borrow())), )); - let __tmp_1: Value = Rc::new(RefCell::new((sz as u64))); - (if CppLess::less(&__tmp_0.as_pointer(), &__tmp_1.as_pointer()) { - __tmp_0.as_pointer() + let __tmp_7: Value = Rc::new(RefCell::new((sz as u64))); + (if CppLess::less(&__tmp_6.as_pointer(), &__tmp_7.as_pointer()) { + __tmp_6.as_pointer() } else { - __tmp_1.as_pointer() + __tmp_7.as_pointer() } .read()) }) as usize); let mut hi: usize = (({ - let __tmp_2: Value = Rc::new(RefCell::new( + let __tmp_8: Value = Rc::new(RefCell::new( (::std::mem::size_of::() as u64).wrapping_add((sz as u64)), )); - (if CppLess::less(&__tmp_2.as_pointer(), &ul.as_pointer()) { + (if CppLess::less(&__tmp_8.as_pointer(), &ul.as_pointer()) { ul.as_pointer() } else { - __tmp_2.as_pointer() + __tmp_8.as_pointer() } .read()) }) as usize); assert!((lo == (::std::mem::size_of::() as usize).wrapping_add(10_usize))); assert!((hi == (::std::mem::size_of::() as usize).wrapping_add(21_usize))); let mut bound: usize = (({ - let __tmp_3: Value = Rc::new(RefCell::new((4_usize as u64))); - let __tmp_4: Value = Rc::new(RefCell::new((sz as u64))); - (if CppLess::less(&__tmp_3.as_pointer(), &__tmp_4.as_pointer()) { - __tmp_3.as_pointer() + let __tmp_9: Value = Rc::new(RefCell::new((4_usize as u64))); + let __tmp_10: Value = Rc::new(RefCell::new((sz as u64))); + (if CppLess::less(&__tmp_9.as_pointer(), &__tmp_10.as_pointer()) { + __tmp_9.as_pointer() } else { - __tmp_4.as_pointer() + __tmp_10.as_pointer() } .read()) }) as usize); @@ -110,7 +128,14 @@ fn main_0() -> i32 { let mut i: usize = 0_usize; 'loop_: while (i < count) { 'for_body: { - total = { (total).wrapping_add((data[(i) as usize] as usize)) }; + { + match ({ (data[(i) as usize] as usize) }, &mut (total)) { + (__tmp_11, __tmp_12) => { + (*__tmp_12) = + (((*__tmp_12) as usize).wrapping_add((__tmp_11 as usize))) as usize; + } + } + }; } i.postfix_inc(); } @@ -139,22 +164,22 @@ fn main_0() -> i32 { assert!((sm == 15_isize)); assert!((sm > (l as isize))); let mut smin: isize = (({ - let __tmp_5: Value = Rc::new(RefCell::new((sm as i64))); - let __tmp_6: Value = Rc::new(RefCell::new((sd as i64))); - (if CppLess::less(&__tmp_5.as_pointer(), &__tmp_6.as_pointer()) { - __tmp_5.as_pointer() + let __tmp_13: Value = Rc::new(RefCell::new((sm as i64))); + let __tmp_14: Value = Rc::new(RefCell::new((sd as i64))); + (if CppLess::less(&__tmp_13.as_pointer(), &__tmp_14.as_pointer()) { + __tmp_13.as_pointer() } else { - __tmp_6.as_pointer() + __tmp_14.as_pointer() } .read()) }) as isize); let mut smax: isize = (({ - let __tmp_7: Value = Rc::new(RefCell::new((sd as i64))); - let __tmp_8: Value = Rc::new(RefCell::new((sm as i64))); - (if CppLess::less(&__tmp_7.as_pointer(), &__tmp_8.as_pointer()) { - __tmp_8.as_pointer() + let __tmp_15: Value = Rc::new(RefCell::new((sd as i64))); + let __tmp_16: Value = Rc::new(RefCell::new((sm as i64))); + (if CppLess::less(&__tmp_15.as_pointer(), &__tmp_16.as_pointer()) { + __tmp_16.as_pointer() } else { - __tmp_7.as_pointer() + __tmp_15.as_pointer() } .read()) }) as isize); @@ -176,22 +201,22 @@ fn main_0() -> i32 { let mut mins: [usize; 4] = [ 0_usize, (({ - let __tmp_9: Value = Rc::new(RefCell::new((mx as u64))); - let __tmp_10: Value = Rc::new(RefCell::new(1_u64)); - (if CppLess::less(&__tmp_9.as_pointer(), &__tmp_10.as_pointer()) { - __tmp_9.as_pointer() + let __tmp_17: Value = Rc::new(RefCell::new((mx as u64))); + let __tmp_18: Value = Rc::new(RefCell::new(1_u64)); + (if CppLess::less(&__tmp_17.as_pointer(), &__tmp_18.as_pointer()) { + __tmp_17.as_pointer() } else { - __tmp_10.as_pointer() + __tmp_18.as_pointer() } .read()) }) as usize), (({ - let __tmp_11: Value = Rc::new(RefCell::new(((mx).wrapping_sub(3_usize) as u64))); - let __tmp_12: Value = Rc::new(RefCell::new((mx as u64))); - (if CppLess::less(&__tmp_11.as_pointer(), &__tmp_12.as_pointer()) { - __tmp_11.as_pointer() + let __tmp_19: Value = Rc::new(RefCell::new(((mx).wrapping_sub(3_usize) as u64))); + let __tmp_20: Value = Rc::new(RefCell::new((mx as u64))); + (if CppLess::less(&__tmp_19.as_pointer(), &__tmp_20.as_pointer()) { + __tmp_19.as_pointer() } else { - __tmp_12.as_pointer() + __tmp_20.as_pointer() } .read()) }) as usize), diff --git a/tests/unit/out/refcount/size_t_template_param.rs b/tests/unit/out/refcount/size_t_template_param.rs index 51b7557e55..b04baa0887 100644 --- a/tests/unit/out/refcount/size_t_template_param.rs +++ b/tests/unit/out/refcount/size_t_template_param.rs @@ -7,7 +7,13 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn array_ref_0(a: Ptr) -> u64 { - elem!(a, 0).write({ (elem!(a, 0).read()).wrapping_add(1_u64) }); + { + match ({ 1_u64 }, &(elem!(a, 0))) { + (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { + (*__tmp_1) = (((*__tmp_1) as u64).wrapping_add((__tmp_0 as u64))) as u64; + }), + } + }; return (elem!(a, (3_u64 as u64).wrapping_sub(1_u64)).read()); } #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] diff --git a/tests/unit/out/refcount/swap_map_no_copy.rs b/tests/unit/out/refcount/swap_map_no_copy.rs index 1e6b008c52..cf3942380c 100644 --- a/tests/unit/out/refcount/swap_map_no_copy.rs +++ b/tests/unit/out/refcount/swap_map_no_copy.rs @@ -221,13 +221,24 @@ pub fn swapped_once_6() -> bool { && (moved_dtors_5.with(|rc| *rc.borrow()) == 1); moves_3.with(|rc| { *rc.borrow_mut() = { - move_assigns_4.with(|rc| { - *rc.borrow_mut() = { - moved_dtors_5.with(|rc| *rc.borrow_mut() = 0); - moved_dtors_5.with(|rc| *rc.borrow()) + match ( + { + { + match ({ 0 }, &mut (*moved_dtors_5.with(Value::clone).borrow_mut())) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } + } + }, + &mut (*move_assigns_4.with(Value::clone).borrow_mut()), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() } - }); - move_assigns_4.with(|rc| *rc.borrow()) + } } }); return ok; @@ -261,10 +272,10 @@ fn main_0() -> i32 { let _o: Value = Rc::new(RefCell::new(Tracked::new_1({ 10 }))); TrackedImpl::move_assign( &match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_0,) => { + (__tmp_4,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_0, + __tmp_4, |__k| cpp_move!(__k), || ::default(), ) @@ -278,10 +289,10 @@ fn main_0() -> i32 { let _o: Value = Rc::new(RefCell::new(Tracked::new_1({ 20 }))); TrackedImpl::move_assign( &match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_1,) => { + (__tmp_5,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_1, + __tmp_5, |__k| cpp_move!(__k), || ::default(), ) @@ -296,10 +307,10 @@ fn main_0() -> i32 { let _o: Value = Rc::new(RefCell::new(Tracked::new_1({ 30 }))); TrackedImpl::move_assign( &match (Rc::new(RefCell::new(3)).as_pointer(),) { - (__tmp_2,) => { + (__tmp_6,) => { ({ (*m2.borrow_mut()).subscript_move( - __tmp_2, + __tmp_6, |__k| cpp_move!(__k), || ::default(), ) @@ -312,10 +323,10 @@ fn main_0() -> i32 { assert!((copies_0.with(|rc| *rc.borrow()) == 0)); cpp_swap!( match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_3,) => { + (__tmp_7,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_3, + __tmp_7, |__k| cpp_move!(__k), || ::default(), ) @@ -323,10 +334,10 @@ fn main_0() -> i32 { } }, match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_4,) => { + (__tmp_8,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_4, + __tmp_8, |__k| cpp_move!(__k), || ::default(), ) @@ -336,10 +347,10 @@ fn main_0() -> i32 { ); assert!( (match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_5,) => { + (__tmp_9,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_5, + __tmp_9, |__k| cpp_move!(__k), || ::default(), ) @@ -349,10 +360,10 @@ fn main_0() -> i32 { .with(|__s| __s.v) == 20) && (match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_6,) => { + (__tmp_10,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_6, + __tmp_10, |__k| cpp_move!(__k), || ::default(), ) @@ -367,10 +378,10 @@ fn main_0() -> i32 { assert!( ((*m1.borrow()).len() == 1_usize) && (match (Rc::new(RefCell::new(3)).as_pointer(),) { - (__tmp_7,) => { + (__tmp_11,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_7, + __tmp_11, |__k| cpp_move!(__k), || ::default(), ) @@ -383,10 +394,10 @@ fn main_0() -> i32 { assert!( (((*m2.borrow()).len() == 2_usize) && (match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_8,) => { + (__tmp_12,) => { ({ (*m2.borrow_mut()).subscript_move( - __tmp_8, + __tmp_12, |__k| cpp_move!(__k), || ::default(), ) @@ -396,10 +407,10 @@ fn main_0() -> i32 { .with(|__s| __s.v) == 20)) && (match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_9,) => { + (__tmp_13,) => { ({ (*m2.borrow_mut()).subscript_move( - __tmp_9, + __tmp_13, |__k| cpp_move!(__k), || ::default(), ) @@ -426,12 +437,12 @@ fn main_0() -> i32 { assert!((copies_0.with(|rc| *rc.borrow()) == 0)); let vec_: Value> = Rc::new(RefCell::new(Vec::new())); { - let mut __tmp_10 = { Tracked::new_1({ 4 }) }; - (*vec_.borrow_mut()).push(__tmp_10); + let mut __tmp_14 = { Tracked::new_1({ 4 }) }; + (*vec_.borrow_mut()).push(__tmp_14); }; { - let mut __tmp_11 = { Tracked::new_1({ 5 }) }; - (*vec_.borrow_mut()).push(__tmp_11); + let mut __tmp_15 = { Tracked::new_1({ 5 }) }; + (*vec_.borrow_mut()).push(__tmp_15); }; cpp_swap!(vec_.decay().offset(0_usize), vec_.decay().offset(1_usize)); assert!(({ ({ (*vec_.borrow())[0_usize].v } == 5) && ({ (*vec_.borrow())[1_usize].v } == 4) })); @@ -499,18 +510,18 @@ fn main_0() -> i32 { let grid: Value>> = Rc::new(RefCell::new(Vec::from_fn(2_usize, |_| Default::default()))); match (grid.decay().offset(0_usize), { Tracked::new_1({ 1 }) }) { - (__tmp_12, mut __tmp_13) => { - __tmp_12.with_mut(|__v: &mut Vec| __v.push(__tmp_13)); + (__tmp_16, mut __tmp_17) => { + __tmp_16.with_mut(|__v: &mut Vec| __v.push(__tmp_17)); } }; match (grid.decay().offset(0_usize), { Tracked::new_1({ 2 }) }) { - (__tmp_14, mut __tmp_15) => { - __tmp_14.with_mut(|__v: &mut Vec| __v.push(__tmp_15)); + (__tmp_18, mut __tmp_19) => { + __tmp_18.with_mut(|__v: &mut Vec| __v.push(__tmp_19)); } }; match (grid.decay().offset(1_usize), { Tracked::new_1({ 3 }) }) { - (__tmp_16, mut __tmp_17) => { - __tmp_16.with_mut(|__v: &mut Vec| __v.push(__tmp_17)); + (__tmp_20, mut __tmp_21) => { + __tmp_20.with_mut(|__v: &mut Vec| __v.push(__tmp_21)); } }; cpp_swap!( @@ -538,10 +549,10 @@ fn main_0() -> i32 { let _o: Value = Rc::new(RefCell::new(Tracked::new_1({ 1 }))); TrackedImpl::move_assign( &match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_18,) => { + (__tmp_22,) => { ({ (*maps.borrow_mut())[(0) as usize].subscript_move( - __tmp_18, + __tmp_22, |__k| cpp_move!(__k), || ::default(), ) @@ -555,10 +566,10 @@ fn main_0() -> i32 { let _o: Value = Rc::new(RefCell::new(Tracked::new_1({ 2 }))); TrackedImpl::move_assign( &match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_19,) => { + (__tmp_23,) => { ({ (*maps.borrow_mut())[(1) as usize].subscript_move( - __tmp_19, + __tmp_23, |__k| cpp_move!(__k), || ::default(), ) @@ -572,10 +583,10 @@ fn main_0() -> i32 { assert!( ((*maps.borrow())[(0) as usize].len() == 1_usize) && (match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_20,) => { + (__tmp_24,) => { ({ (*maps.borrow_mut())[(0) as usize].subscript_move( - __tmp_20, + __tmp_24, |__k| cpp_move!(__k), || ::default(), ) @@ -588,10 +599,10 @@ fn main_0() -> i32 { assert!( ((*maps.borrow())[(1) as usize].len() == 1_usize) && (match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_21,) => { + (__tmp_25,) => { ({ (*maps.borrow_mut())[(1) as usize].subscript_move( - __tmp_21, + __tmp_25, |__k| cpp_move!(__k), || ::default(), ) diff --git a/tests/unit/out/refcount/switch_on_assignment.rs b/tests/unit/out/refcount/switch_on_assignment.rs index 997126b24b..02cf599092 100644 --- a/tests/unit/out/refcount/switch_on_assignment.rs +++ b/tests/unit/out/refcount/switch_on_assignment.rs @@ -12,8 +12,12 @@ pub fn switch_on_assignment_0(mut x: i32) -> i32 { 'switch: { match { { - y = (x + 1); - y + match ({ (x + 1) }, &mut (y)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } + } } } { __v if __v == 1 => { diff --git a/tests/unit/out/refcount/va_arg_concat.rs b/tests/unit/out/refcount/va_arg_concat.rs index c39ccdc634..062db46290 100644 --- a/tests/unit/out/refcount/va_arg_concat.rs +++ b/tests/unit/out/refcount/va_arg_concat.rs @@ -14,8 +14,12 @@ pub fn sum_ints_0(first: i32, __args: Box<[VaArg]>) -> i32 { (*args.borrow_mut()) = __args.decay(); let mut val: i32 = 0_i32; 'loop_: while (({ - val = (*args.borrow_mut()).arg::(); - val + match ({ (*args.borrow_mut()).arg::() }, &mut (val)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } + } }) != 0) { total += val; diff --git a/tests/unit/out/refcount/va_arg_two_passes.rs b/tests/unit/out/refcount/va_arg_two_passes.rs index 1f8cf40efd..34f1245cb9 100644 --- a/tests/unit/out/refcount/va_arg_two_passes.rs +++ b/tests/unit/out/refcount/va_arg_two_passes.rs @@ -15,16 +15,24 @@ pub fn sum_then_product_0(first: i32, __args: Box<[VaArg]>) -> i32 { (*ap.borrow_mut()) = __args.decay(); let mut val: i32 = 0_i32; 'loop_: while (({ - val = (*ap.borrow_mut()).arg::(); - val + match ({ (*ap.borrow_mut()).arg::() }, &mut (val)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } + } }) != 0) { sum += val; } (*ap.borrow_mut()) = __args.decay(); 'loop_: while (({ - val = (*ap.borrow_mut()).arg::(); - val + match ({ (*ap.borrow_mut()).arg::() }, &mut (val)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } }) != 0) { product *= val; diff --git a/tests/unit/out/refcount/vector_subscript_borrow.rs b/tests/unit/out/refcount/vector_subscript_borrow.rs index 01b8b4b57a..5c95f96ad1 100644 --- a/tests/unit/out/refcount/vector_subscript_borrow.rs +++ b/tests/unit/out/refcount/vector_subscript_borrow.rs @@ -34,8 +34,11 @@ fn main_0() -> i32 { } } { - let rhs_0 = (items[1_usize]).wrapping_add(5_u32); - items[1_usize] = rhs_0 + match ({ 5_u32 }, &mut (items[1_usize])) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; + } + } }; items[2_usize].postfix_inc(); assert!(((items[0_usize] == 0_u32) && (items[1_usize] == 7_u32)) && (items[2_usize] == 5_u32)); diff --git a/tests/unit/out/unsafe/anonymous-struct.rs b/tests/unit/out/unsafe/anonymous-struct.rs index c2dcdd39c8..23ce4405af 100644 --- a/tests/unit/out/unsafe/anonymous-struct.rs +++ b/tests/unit/out/unsafe/anonymous-struct.rs @@ -90,15 +90,19 @@ unsafe fn main_0() -> i32 { s.x = 1; s.z = 2; assert!( - ({ - s.x = 1; - s.x + (match ({ 1 }, &mut (s.x)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } } != 0) ); assert!( - ({ - s.z = 2; - s.z + (match ({ 2 }, &mut (s.z)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } } != 0) ); return 0; diff --git a/tests/unit/out/unsafe/anonymous-struct_c.rs b/tests/unit/out/unsafe/anonymous-struct_c.rs index 942e68464a..a773bae7af 100644 --- a/tests/unit/out/unsafe/anonymous-struct_c.rs +++ b/tests/unit/out/unsafe/anonymous-struct_c.rs @@ -96,15 +96,19 @@ unsafe fn main_0() -> i32 { s.x = 1; s.z = 2; assert!( - ({ - s.x = 1; - s.x + (match ({ 1 }, &mut (s.x)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } } != 0) ); assert!( - ({ - s.z = 2; - s.z + (match ({ 2 }, &mut (s.z)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } } != 0) ); return 0; diff --git a/tests/unit/out/unsafe/assign_as_value.rs b/tests/unit/out/unsafe/assign_as_value.rs index d49d3e54fb..55f2edd5f4 100644 --- a/tests/unit/out/unsafe/assign_as_value.rs +++ b/tests/unit/out/unsafe/assign_as_value.rs @@ -16,17 +16,29 @@ unsafe fn main_0() -> i32 { let mut buf: [libc::c_char; 2] = [(0 as libc::c_char); 2]; let mut p: *mut libc::c_char = buf.as_mut_ptr(); let mut q: *mut libc::c_char = std::ptr::null_mut(); - q = { - p = (p).wrapping_add((1 as i32) as usize); - p + q = match ({ 1 }, &mut (p)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (*__tmp_1).offset((__tmp_0 as isize)); + (*__tmp_1).clone() + } }; assert!(((q) == (buf.as_mut_ptr().offset((1) as isize)))); + q = match ({ 1 }, &mut (p)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (*__tmp_3).offset(-(__tmp_2 as isize)); + (*__tmp_3).clone() + } + }; + assert!(((p) == (buf.as_mut_ptr()))); + assert!(((q) == (buf.as_mut_ptr()))); let mut out: libc::c_char = (0 as libc::c_char); 'switch: { match { - (({ - out = (('x' as i32) as libc::c_char); - out + ((match ({ (('x' as i32) as libc::c_char) }, &mut (out)) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } }) as i32) } { __v if __v == ('x' as i32) => { diff --git a/tests/unit/out/unsafe/assign_rhs_first.rs b/tests/unit/out/unsafe/assign_rhs_first.rs index 62e5e05779..0eb608b98d 100644 --- a/tests/unit/out/unsafe/assign_rhs_first.rs +++ b/tests/unit/out/unsafe/assign_rhs_first.rs @@ -52,7 +52,11 @@ unsafe fn main_0() -> i32 { assert!(((s.ptr) == (a.as_mut_ptr().offset((2) as isize))) && ((a[(3) as usize]) == (24))); let mut b: *mut u8 = (a.as_mut_ptr() as *mut u8); (*b.offset((0) as isize)) = 7_u8; - (*b.offset((4) as isize)) = (((*b.offset((4) as isize)) as i32) + 1) as u8; + match ({ 1 }, &mut (*b.offset((4) as isize))) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as i32) + (__tmp_0 as i32)) as u8; + } + }; assert!(((a[(0) as usize]) == (7)) && ((a[(1) as usize]) == (3))); return 0; } diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs new file mode 100644 index 0000000000..143a1de024 --- /dev/null +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -0,0 +1,577 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub unsafe fn test_0() { + let mut a: [u32; 3] = [10_u32, 20_u32, 30_u32]; + let mut i: i32 = 0; + match ({ 5_u32 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; + } + }; + (unsafe { + libc::printf( + c"void %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32), + ) + }); + i = 0; + let mut sum: u32 = (match ({ 2_u32 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (((*__tmp_3) as u32).wrapping_add((__tmp_2 as u32))) as u32; + (*__tmp_3).clone() + } + }); + (unsafe { + libc::printf( + c"compound %d %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (sum as i32), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32), + ) + }); + i = 0; + let mut assigned: u32 = (match ({ 99_u32 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } + }); + (unsafe { + libc::printf( + c"simple %d %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (assigned as i32), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32), + ) + }); +} +pub unsafe fn test_1() { + let mut a: [i16; 3] = [10_i16, 20_i16, 30_i16]; + let mut i: i32 = 0; + match ({ 5 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as i32) + (__tmp_6 as i32)) as i16; + } + }; + (unsafe { + libc::printf( + c"void %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32), + ) + }); + i = 0; + let mut sum: i16 = (match ({ 2 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as i32) + (__tmp_8 as i32)) as i16; + (*__tmp_9).clone() + } + }); + (unsafe { + libc::printf( + c"compound %d %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (sum as i32), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32), + ) + }); + i = 0; + let mut assigned: i16 = (match ({ 99_i16 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_10, __tmp_11) => { + (*__tmp_11) = __tmp_10; + (*__tmp_11).clone() + } + }); + (unsafe { + libc::printf( + c"simple %d %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (assigned as i32), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32), + ) + }); +} +pub unsafe fn test_2() { + let mut a: [i32; 3] = [10, 20, 30]; + let mut i: i32 = 0; + a[(i.postfix_inc()) as usize] += 5; + (unsafe { + libc::printf( + c"void %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (a[(0) as usize]), + (a[(1) as usize]), + ) + }); + i = 0; + let mut sum: i32 = (match ({ 2 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_12, __tmp_13) => { + (*__tmp_13) = (((*__tmp_13) as i32) + (__tmp_12 as i32)) as i32; + (*__tmp_13).clone() + } + }); + (unsafe { + libc::printf( + c"compound %d %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (sum), + (a[(0) as usize]), + (a[(1) as usize]), + ) + }); + i = 0; + let mut assigned: i32 = (match ({ 99 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_14, __tmp_15) => { + (*__tmp_15) = __tmp_14; + (*__tmp_15).clone() + } + }); + (unsafe { + libc::printf( + c"simple %d %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (assigned), + (a[(0) as usize]), + (a[(1) as usize]), + ) + }); +} +pub unsafe fn test_comma_3() { + let mut x: u32 = 10_u32; + let mut i: i32 = 0; + match ( + { 5_u32 }, + &mut (*({ + i.prefix_inc(); + &mut x + })), + ) { + (__tmp_16, __tmp_17) => { + (*__tmp_17) = (((*__tmp_17) as u32).wrapping_add((__tmp_16 as u32))) as u32; + } + }; + (unsafe { + libc::printf( + c"direct void %d %d\n".as_ptr() as *const libc::c_char, + (i), + (x as i32), + ) + }); + let mut result: u32 = (match ( + { 2_u32 }, + &mut (*({ + i.prefix_inc(); + &mut x + })), + ) { + (__tmp_18, __tmp_19) => { + (*__tmp_19) = (((*__tmp_19) as u32).wrapping_add((__tmp_18 as u32))) as u32; + (*__tmp_19).clone() + } + }); + (unsafe { + libc::printf( + c"direct compound %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (result as i32), + (x as i32), + ) + }); + result = (match ( + { 99_u32 }, + &mut (*({ + i.prefix_inc(); + &mut x + })), + ) { + (__tmp_20, __tmp_21) => { + (*__tmp_21) = __tmp_20; + (*__tmp_21).clone() + } + }); + (unsafe { + libc::printf( + c"direct simple %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (result as i32), + (x as i32), + ) + }); + let mut p: *mut u32 = (&mut x as *mut u32); + match ( + { 5_u32 }, + &mut (*({ + i.prefix_inc(); + (p).clone() + })), + ) { + (__tmp_22, __tmp_23) => { + (*__tmp_23) = (((*__tmp_23) as u32).wrapping_add((__tmp_22 as u32))) as u32; + } + }; + (unsafe { + libc::printf( + c"indirect void %d %d\n".as_ptr() as *const libc::c_char, + (i), + ((*p) as i32), + ) + }); + result = (match ( + { 2_u32 }, + &mut (*({ + i.prefix_inc(); + (p).clone() + })), + ) { + (__tmp_24, __tmp_25) => { + (*__tmp_25) = (((*__tmp_25) as u32).wrapping_add((__tmp_24 as u32))) as u32; + (*__tmp_25).clone() + } + }); + (unsafe { + libc::printf( + c"indirect compound %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (result as i32), + ((*p) as i32), + ) + }); + result = (match ( + { 99_u32 }, + &mut (*({ + i.prefix_inc(); + (p).clone() + })), + ) { + (__tmp_26, __tmp_27) => { + (*__tmp_27) = __tmp_26; + (*__tmp_27).clone() + } + }); + (unsafe { + libc::printf( + c"indirect simple %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (result as i32), + ((*p) as i32), + ) + }); +} +pub unsafe fn test_comma_4() { + let mut x: i16 = 10_i16; + let mut i: i32 = 0; + match ( + { 5 }, + &mut (*({ + i.prefix_inc(); + &mut x + })), + ) { + (__tmp_28, __tmp_29) => { + (*__tmp_29) = (((*__tmp_29) as i32) + (__tmp_28 as i32)) as i16; + } + }; + (unsafe { + libc::printf( + c"direct void %d %d\n".as_ptr() as *const libc::c_char, + (i), + (x as i32), + ) + }); + let mut result: i16 = (match ( + { 2 }, + &mut (*({ + i.prefix_inc(); + &mut x + })), + ) { + (__tmp_30, __tmp_31) => { + (*__tmp_31) = (((*__tmp_31) as i32) + (__tmp_30 as i32)) as i16; + (*__tmp_31).clone() + } + }); + (unsafe { + libc::printf( + c"direct compound %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (result as i32), + (x as i32), + ) + }); + result = (match ( + { 99_i16 }, + &mut (*({ + i.prefix_inc(); + &mut x + })), + ) { + (__tmp_32, __tmp_33) => { + (*__tmp_33) = __tmp_32; + (*__tmp_33).clone() + } + }); + (unsafe { + libc::printf( + c"direct simple %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (result as i32), + (x as i32), + ) + }); + let mut p: *mut i16 = (&mut x as *mut i16); + match ( + { 5 }, + &mut (*({ + i.prefix_inc(); + (p).clone() + })), + ) { + (__tmp_34, __tmp_35) => { + (*__tmp_35) = (((*__tmp_35) as i32) + (__tmp_34 as i32)) as i16; + } + }; + (unsafe { + libc::printf( + c"indirect void %d %d\n".as_ptr() as *const libc::c_char, + (i), + ((*p) as i32), + ) + }); + result = (match ( + { 2 }, + &mut (*({ + i.prefix_inc(); + (p).clone() + })), + ) { + (__tmp_36, __tmp_37) => { + (*__tmp_37) = (((*__tmp_37) as i32) + (__tmp_36 as i32)) as i16; + (*__tmp_37).clone() + } + }); + (unsafe { + libc::printf( + c"indirect compound %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (result as i32), + ((*p) as i32), + ) + }); + result = (match ( + { 99_i16 }, + &mut (*({ + i.prefix_inc(); + (p).clone() + })), + ) { + (__tmp_38, __tmp_39) => { + (*__tmp_39) = __tmp_38; + (*__tmp_39).clone() + } + }); + (unsafe { + libc::printf( + c"indirect simple %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (result as i32), + ((*p) as i32), + ) + }); +} +pub static mut global_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10 }); +pub unsafe fn observe_global_6(mut assigned: i32) -> i32 { + return ((assigned) + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5))); +} +pub unsafe fn observe_7(mut assigned: i32, mut stored: *const i32) -> i32 { + return ((assigned) + (*stored)); +} +pub unsafe fn test_borrows_8() { + (unsafe { + libc::printf( + c"%d\n".as_ptr() as *const libc::c_char, + (unsafe { + observe_global_6( + match ( + { 99 }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)), + ) { + (__tmp_40, __tmp_41) => { + (*__tmp_41) = __tmp_40; + (*__tmp_41).clone() + } + }, + ) + }), + ) + }); + (unsafe { + libc::printf( + c"%d\n".as_ptr() as *const libc::c_char, + (unsafe { + observe_global_6( + match ( + { 5 }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)), + ) { + (__tmp_42, __tmp_43) => { + (*__tmp_43) = (((*__tmp_43) as i32) + (__tmp_42 as i32)) as i32; + (*__tmp_43).clone() + } + }, + ) + }), + ) + }); + let mut local: i32 = 10; + (unsafe { + libc::printf( + c"%d\n".as_ptr() as *const libc::c_char, + (unsafe { + let _assigned: i32 = match ({ 99 }, &mut (local)) { + (__tmp_44, __tmp_45) => { + (*__tmp_45) = __tmp_44; + (*__tmp_45).clone() + } + }; + let _stored: *const i32 = (&mut local as *mut i32).cast_const(); + observe_7(_assigned, _stored) + }), + ) + }); + (unsafe { + libc::printf( + c"%d\n".as_ptr() as *const libc::c_char, + (unsafe { + let _assigned: i32 = match ({ 5 }, &mut (local)) { + (__tmp_46, __tmp_47) => { + (*__tmp_47) = (((*__tmp_47) as i32) + (__tmp_46 as i32)) as i32; + (*__tmp_47).clone() + } + }; + let _stored: *const i32 = (&mut local as *mut i32).cast_const(); + observe_7(_assigned, _stored) + }), + ) + }); + let mut record: Record_9 = Record_9 { value: 10 }; + (unsafe { + libc::printf( + c"%d\n".as_ptr() as *const libc::c_char, + (unsafe { + let _assigned: i32 = match ({ 99 }, &mut (record.value)) { + (__tmp_48, __tmp_49) => { + (*__tmp_49) = __tmp_48; + (*__tmp_49).clone() + } + }; + let _stored: *const i32 = (&mut record.value as *mut i32).cast_const(); + observe_7(_assigned, _stored) + }), + ) + }); + (unsafe { + libc::printf( + c"%d\n".as_ptr() as *const libc::c_char, + (unsafe { + let _assigned: i32 = match ({ 5 }, &mut (record.value)) { + (__tmp_50, __tmp_51) => { + (*__tmp_51) = (((*__tmp_51) as i32) + (__tmp_50 as i32)) as i32; + (*__tmp_51).clone() + } + }; + let _stored: *const i32 = (&mut record.value as *mut i32).cast_const(); + observe_7(_assigned, _stored) + }), + ) + }); + let mut values: Vec = vec![10; 1_usize]; + (unsafe { + libc::printf( + c"%d\n".as_ptr() as *const libc::c_char, + (unsafe { + let _assigned: i32 = match ({ 99 }, &mut (values[(0_usize)])) { + (__tmp_52, __tmp_53) => { + (*__tmp_53) = __tmp_52; + (*__tmp_53).clone() + } + }; + let _stored: *const i32 = (&mut values[(0_usize)] as *mut i32).cast_const(); + observe_7(_assigned, _stored) + }), + ) + }); + (unsafe { + libc::printf( + c"%d\n".as_ptr() as *const libc::c_char, + (unsafe { + let _assigned: i32 = match ({ 5 }, &mut (values[(0_usize)])) { + (__tmp_54, __tmp_55) => { + (*__tmp_55) = (((*__tmp_55) as i32) + (__tmp_54 as i32)) as i32; + (*__tmp_55).clone() + } + }; + let _stored: *const i32 = (&mut values[(0_usize)] as *mut i32).cast_const(); + observe_7(_assigned, _stored) + }), + ) + }); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Record_9 { + pub value: i32, +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_0() }); + (unsafe { test_1() }); + (unsafe { test_2() }); + (unsafe { test_comma_3() }); + (unsafe { test_comma_4() }); + let mut values: [u32; 2] = [10_u32, 20_u32]; + let ref_: *mut [u32; 2] = &mut values; + let mut i: i32 = 0; + let mut result: u32 = (match ( + { 5_u32 }, + &mut ((*({ + i.prefix_inc(); + (ref_).clone() + }))[(0) as usize]), + ) { + (__tmp_56, __tmp_57) => { + (*__tmp_57) = (((*__tmp_57) as u32).wrapping_add((__tmp_56 as u32))) as u32; + (*__tmp_57).clone() + } + }); + (unsafe { + libc::printf( + c"array reference %d %u %u\n".as_ptr() as *const libc::c_char, + (i), + (result), + (values[(0) as usize]), + ) + }); + (unsafe { test_borrows_8() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const global_5); +} diff --git a/tests/unit/out/unsafe/compound_assign_paren.rs b/tests/unit/out/unsafe/compound_assign_paren.rs index 62b97b7011..0705b27804 100644 --- a/tests/unit/out/unsafe/compound_assign_paren.rs +++ b/tests/unit/out/unsafe/compound_assign_paren.rs @@ -20,21 +20,49 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut item: Item = Item { flags: 0_u8 }; let mut ptr: *mut Item = (&mut item as *mut Item); - (*(ptr)).flags = (((*(ptr)).flags as i32) | ((1) << (0))) as u8; - (*(ptr)).flags = (((*(ptr)).flags as i32) | ((1) << (1))) as u8; + match ({ ((1) << (0)) }, &mut ((*(ptr)).flags)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as i32) | (__tmp_0 as i32)) as u8; + } + }; + match ({ ((1) << (1)) }, &mut ((*(ptr)).flags)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (((*__tmp_3) as i32) | (__tmp_2 as i32)) as u8; + } + }; assert!((((*ptr).flags as i32) == (3))); - (*(ptr)).flags = (((*(ptr)).flags as i32) & ((!((1) << (0)) as u8) as i32)) as u8; + match ({ ((!((1) << (0)) as u8) as i32) }, &mut ((*(ptr)).flags)) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) as u8; + } + }; assert!((((*ptr).flags as i32) == (2))); let mut bits: [u8; 4] = [0_u8; 4]; - (bits)[((5) / (8)) as usize] = - (((bits)[((5) / (8)) as usize] as i32) | ((((1) << ((5) & (7))) as u8) as i32)) as u8; - (bits)[((13) / (8)) as usize] = - (((bits)[((13) / (8)) as usize] as i32) | ((((1) << ((13) & (7))) as u8) as i32)) as u8; + match ( + { ((((1) << ((5) & (7))) as u8) as i32) }, + &mut ((bits)[((5) / (8)) as usize]), + ) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as i32) | (__tmp_6 as i32)) as u8; + } + }; + match ( + { ((((1) << ((13) & (7))) as u8) as i32) }, + &mut ((bits)[((13) / (8)) as usize]), + ) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as i32) | (__tmp_8 as i32)) as u8; + } + }; assert!(((bits[(0) as usize] as i32) == (32))); assert!(((bits[(1) as usize] as i32) == (32))); assert!(((bits[(2) as usize] as i32) == (0))); if (((*ptr).flags as i32) != (0)) { - (*(ptr)).flags = (((*(ptr)).flags as i32) & ((!((1) << (1)) as u8) as i32)) as u8; + match ({ ((!((1) << (1)) as u8) as i32) }, &mut ((*(ptr)).flags)) { + (__tmp_10, __tmp_11) => { + (*__tmp_11) = (((*__tmp_11) as i32) & (__tmp_10 as i32)) as u8; + } + }; } assert!((((*ptr).flags as i32) == (0))); return 0; diff --git a/tests/unit/out/unsafe/copy_move_defaulted.rs b/tests/unit/out/unsafe/copy_move_defaulted.rs index 88fb268944..884c0e59cc 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -283,9 +283,11 @@ unsafe fn main_0() -> i32 { assert!((unsafe { same_0(&e, &b,) }) && (unsafe { same_0(&f, &c,) })); let mut g: Explicit = Explicit::new({ 4 }); let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { (*__p).destructor() }); - g = { - e = (f).clone(); - (e).clone() + g = match ({ (f).clone() }, &mut (e)) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } }; assert!((unsafe { same_0(&g, &f,) }) && (unsafe { same_0(&e, &f,) })); let mut i: Implicit = Implicit { @@ -354,8 +356,8 @@ unsafe fn main_0() -> i32 { bufs.push(__a1) }; { - let mut __tmp_4 = { Buffer::move_from({ &mut bufs[(0_usize)] }) }; - bufs.push_mut(__tmp_4) + let mut __tmp_6 = { Buffer::move_from({ &mut bufs[(0_usize)] }) }; + bufs.push_mut(__tmp_6) }; assert!( (((bufs[(1_usize)].n) == (3)) && ((bufs[(1_usize)].data.len()) == (3_usize))) diff --git a/tests/unit/out/unsafe/destructor.rs b/tests/unit/out/unsafe/destructor.rs index 7779f7c8f6..beb2b9aac3 100644 --- a/tests/unit/out/unsafe/destructor.rs +++ b/tests/unit/out/unsafe/destructor.rs @@ -74,9 +74,14 @@ pub struct Templated_char_ { } impl Templated_char_ { pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) = - (((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) as usize) - .wrapping_add((::std::mem::size_of::() as usize))) as i32; + match ( + { ::std::mem::size_of::() }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as usize).wrapping_add((__tmp_0 as usize))) as i32; + } + }; } } #[repr(C)] @@ -86,9 +91,14 @@ pub struct Templated_int_ { } impl Templated_int_ { pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) = - (((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) as usize) - .wrapping_add((::std::mem::size_of::() as usize))) as i32; + match ( + { ::std::mem::size_of::() }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (((*__tmp_3) as usize).wrapping_add((__tmp_2 as usize))) as i32; + } + }; } } #[repr(C)] diff --git a/tests/unit/out/unsafe/expr_as_bool_c.rs b/tests/unit/out/unsafe/expr_as_bool_c.rs index 81d5a5f240..e15c20838e 100644 --- a/tests/unit/out/unsafe/expr_as_bool_c.rs +++ b/tests/unit/out/unsafe/expr_as_bool_c.rs @@ -24,14 +24,18 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut a: i32 = 0; let mut b: i32 = 0_i32; - if ({ - b = a; - b + if (match ({ a }, &mut (b)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } } != 0) {} - 'loop_: while (({ - b = a; - b + 'loop_: while ((match ({ a }, &mut (b)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } }) != (0)) {} if (a != 0) {} @@ -39,19 +43,25 @@ unsafe fn main_0() -> i32 { if ((a) < (b)) {} assert!(((a) == (b))); assert!( - !(({ - a = b; - a + !((match ({ b }, &mut (a)) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } }) != 0) ); let mut c: bool = false; - c = ({ - a = b; - a + c = (match ({ b }, &mut (a)) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = __tmp_6; + (*__tmp_7).clone() + } } != 0); - c = (({ - b = a; - b + c = ((match ({ a }, &mut (b)) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = __tmp_8; + (*__tmp_9).clone() + } }) != (0)); c = (a != 0); c = ((a) == (b)); diff --git a/tests/unit/out/unsafe/expr_as_bool_cpp.rs b/tests/unit/out/unsafe/expr_as_bool_cpp.rs index 65c2f1add3..aef0ea8963 100644 --- a/tests/unit/out/unsafe/expr_as_bool_cpp.rs +++ b/tests/unit/out/unsafe/expr_as_bool_cpp.rs @@ -24,14 +24,18 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut a: i32 = 0; let mut b: i32 = 0_i32; - if ({ - b = a; - b + if (match ({ a }, &mut (b)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } } != 0) {} - 'loop_: while (({ - b = a; - b + 'loop_: while ((match ({ a }, &mut (b)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } }) != (0)) {} if (a != 0) {} @@ -39,19 +43,25 @@ unsafe fn main_0() -> i32 { if ((a) < (b)) {} assert!(((a) == (b))); assert!( - !(({ - a = b; - a + !((match ({ b }, &mut (a)) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = __tmp_4; + (*__tmp_5).clone() + } }) != 0) ); let mut c: bool = false; - c = ({ - a = b; - a + c = (match ({ b }, &mut (a)) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = __tmp_6; + (*__tmp_7).clone() + } } != 0); - c = (({ - b = a; - b + c = ((match ({ a }, &mut (b)) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = __tmp_8; + (*__tmp_9).clone() + } }) != (0)); c = (a != 0); c = ((a) == (b)); diff --git a/tests/unit/out/unsafe/field_pointers_malloced_struct.rs b/tests/unit/out/unsafe/field_pointers_malloced_struct.rs index 6081feceef..d95c685436 100644 --- a/tests/unit/out/unsafe/field_pointers_malloced_struct.rs +++ b/tests/unit/out/unsafe/field_pointers_malloced_struct.rs @@ -42,15 +42,19 @@ unsafe fn main_0() -> i32 { } assert!((((*s).a) == (5)) && (((*s).c) == (1))); let mut x: i32 = (((*s).a) - + ({ - (*s).b = 3; - (*s).b + + (match ({ 3 }, &mut ((*s).b)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } })); assert!(((x) == (8)) && (((*s).b) == (3))); let mut y: i32 = 0; - (*s).c = ({ - y = 99; - y + (*s).c = (match ({ 99 }, &mut (y)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } }); assert!((((*s).c) == (99)) && ((y) == (99))); (*s).a += (unsafe { bump_0(s) }); diff --git a/tests/unit/out/unsafe/fn_ptr.rs b/tests/unit/out/unsafe/fn_ptr.rs index 6a79f9b0e5..4072ecfdee 100644 --- a/tests/unit/out/unsafe/fn_ptr.rs +++ b/tests/unit/out/unsafe/fn_ptr.rs @@ -19,7 +19,11 @@ pub unsafe fn twice_2(mut x: u64) -> u64 { return (x).wrapping_mul(2_u64); } pub unsafe fn twice_in_place_3(x: *mut u64) -> u64 { - (*x) = (*x).wrapping_mul(2_u64); + match ({ 2_u64 }, &mut (*x)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as u64).wrapping_mul((__tmp_0 as u64))) as u64; + } + }; return (*x); } pub unsafe fn ret_size_4(mut v: i32) -> usize { @@ -86,11 +90,11 @@ unsafe fn main_0() -> i32 { assert!(((m) == (42_usize))); assert!(((unsafe { call_fn_5(Some(ret_size_4), 3,) }) == (8_usize))); let mut hh: HashHolder_unsigned_long__ptr__bool__ = { - let mut __tmp_0: Option u64> = std::mem::transmute::< + let mut __tmp_2: Option u64> = std::mem::transmute::< Option usize>, Option u64>, >(Some(identity_hash_6)); - HashHolder_unsigned_long__ptr__bool__::new({ &mut __tmp_0 }) + HashHolder_unsigned_long__ptr__bool__::new({ &mut __tmp_2 }) }; assert!(((unsafe { (hh.h).unwrap()(true,) }) == (1_u64))); let mut handler: Option = Some(add_to_total_8); diff --git a/tests/unit/out/unsafe/global_call_temporaries.rs b/tests/unit/out/unsafe/global_call_temporaries.rs index b466e55114..e9a02dcc11 100644 --- a/tests/unit/out/unsafe/global_call_temporaries.rs +++ b/tests/unit/out/unsafe/global_call_temporaries.rs @@ -30,49 +30,70 @@ pub static mut x_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsaf pub static mut y_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut assigned_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_2: i32; - let mut __tmp_3: i32; - ({ - (*std::cell::LazyCell::force_mut(&mut *&raw mut x_2)) = { - __tmp_2 = 5; - __tmp_3 = 6; - (*{ - let __a: *const _ = &mut __tmp_2; - let __b: *const _ = &mut __tmp_3; - if *__b < *__a { __b } else { __a } - }) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut x_2)) + let mut __tmp_4: i32; + let mut __tmp_5: i32; + (match ( + { + { + __tmp_4 = 5; + __tmp_5 = 6; + (*{ + let __a: *const _ = &mut __tmp_4; + let __b: *const _ = &mut __tmp_5; + if *__b < *__a { __b } else { __a } + }) + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut x_2)), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } }) } }); pub static mut accumulated_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_4: i32; - let mut __tmp_5: i32; - ({ - (*std::cell::LazyCell::force_mut(&mut *&raw mut y_3)) += { - __tmp_4 = 1; - __tmp_5 = 2; - (*{ - let __a: *const _ = &mut __tmp_4; - let __b: *const _ = &mut __tmp_5; - if *__a < *__b { __b } else { __a } - }) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut y_3)) + let mut __tmp_8: i32; + let mut __tmp_9: i32; + (match ( + { + { + __tmp_8 = 1; + __tmp_9 = 2; + (*{ + let __a: *const _ = &mut __tmp_8; + let __b: *const _ = &mut __tmp_9; + if *__a < *__b { __b } else { __a } + }) + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut y_3)), + ) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as i32) + (__tmp_6 as i32)) as i32; + (*__tmp_7).clone() + } }) } }); pub static mut call_assigned_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_6: i32; - ({ - (*std::cell::LazyCell::force_mut(&mut *&raw mut x_2)) = (unsafe { - __tmp_6 = 5; - read_0(&mut __tmp_6) - }); - (*std::cell::LazyCell::force_mut(&mut *&raw mut x_2)) + let mut __tmp_12: i32; + (match ( + { + (unsafe { + __tmp_12 = 5; + read_0(&mut __tmp_12) + }) + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut x_2)), + ) { + (__tmp_10, __tmp_11) => { + (*__tmp_11) = __tmp_10; + (*__tmp_11).clone() + } }) } }); @@ -90,36 +111,36 @@ pub unsafe fn read_record_8(value: *const Item) -> i32 { pub static mut aggregate_selected_9: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_8: i32; - let mut __tmp_9: i32; - let mut __tmp_7: [i32; 1]; - let mut __tmp_11: i32; - let mut __tmp_12: i32; - let mut __tmp_10: Item; + let mut __tmp_14: i32; + let mut __tmp_15: i32; + let mut __tmp_13: [i32; 1]; + let mut __tmp_17: i32; + let mut __tmp_18: i32; + let mut __tmp_16: Item; ((unsafe { - __tmp_7 = [{ - __tmp_8 = 3; - __tmp_9 = 4; + __tmp_13 = [{ + __tmp_14 = 3; + __tmp_15 = 4; (*{ - let __a: *const _ = &mut __tmp_8; - let __b: *const _ = &mut __tmp_9; + let __a: *const _ = &mut __tmp_14; + let __b: *const _ = &mut __tmp_15; if *__b < *__a { __b } else { __a } }) }]; - read_array_7(&mut __tmp_7) + read_array_7(&mut __tmp_13) }) + (unsafe { - __tmp_10 = Item { + __tmp_16 = Item { value: { - __tmp_11 = 5; - __tmp_12 = 6; + __tmp_17 = 5; + __tmp_18 = 6; (*{ - let __a: *const _ = &mut __tmp_11; - let __b: *const _ = &mut __tmp_12; + let __a: *const _ = &mut __tmp_17; + let __b: *const _ = &mut __tmp_18; if *__a < *__b { __b } else { __a } }) }, }; - read_record_8(&mut __tmp_10) + read_record_8(&mut __tmp_16) })) } }); @@ -129,13 +150,13 @@ pub static mut right_11: std::cell::LazyCell = pub static mut mapped_selected_12: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_13: u64; + let mut __tmp_19: u64; (({ - __tmp_13 = ((*std::cell::LazyCell::force_mut(&mut *&raw mut right_11)) as u64); + __tmp_19 = ((*std::cell::LazyCell::force_mut(&mut *&raw mut right_11)) as u64); (*{ let __a: *const _ = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut left_10)); - let __b: *const _ = &mut __tmp_13; + let __b: *const _ = &mut __tmp_19; if *__b < *__a { __b } else { __a } }) }) as usize) @@ -146,12 +167,12 @@ pub unsafe fn get_13() -> usize { } static mut value_14: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_14: u64; + let mut __tmp_20: u64; (({ - __tmp_14 = ((*std::cell::LazyCell::force_mut(&mut *&raw mut right_11)) as u64); + __tmp_20 = ((*std::cell::LazyCell::force_mut(&mut *&raw mut right_11)) as u64); (*{ let __a: *const _ = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut left_10)); - let __b: *const _ = &mut __tmp_14; + let __b: *const _ = &mut __tmp_20; if *__a < *__b { __b } else { __a } }) }) as usize) @@ -176,36 +197,36 @@ unsafe fn main_0() -> i32 { } static mut aggregate_static_15: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_16: i32; - let mut __tmp_17: i32; - let mut __tmp_15: [i32; 1]; - let mut __tmp_19: i32; - let mut __tmp_20: i32; - let mut __tmp_18: Item; + let mut __tmp_22: i32; + let mut __tmp_23: i32; + let mut __tmp_21: [i32; 1]; + let mut __tmp_25: i32; + let mut __tmp_26: i32; + let mut __tmp_24: Item; ((unsafe { - __tmp_15 = [{ - __tmp_16 = 7; - __tmp_17 = 8; + __tmp_21 = [{ + __tmp_22 = 7; + __tmp_23 = 8; (*{ - let __a: *const _ = &mut __tmp_16; - let __b: *const _ = &mut __tmp_17; + let __a: *const _ = &mut __tmp_22; + let __b: *const _ = &mut __tmp_23; if *__a < *__b { __b } else { __a } }) }]; - read_array_7(&mut __tmp_15) + read_array_7(&mut __tmp_21) }) + (unsafe { - __tmp_18 = Item { + __tmp_24 = Item { value: { - __tmp_19 = 9; - __tmp_20 = 10; + __tmp_25 = 9; + __tmp_26 = 10; (*{ - let __a: *const _ = &mut __tmp_19; - let __b: *const _ = &mut __tmp_20; + let __a: *const _ = &mut __tmp_25; + let __b: *const _ = &mut __tmp_26; if *__b < *__a { __b } else { __a } }) }, }; - read_record_8(&mut __tmp_18) + read_record_8(&mut __tmp_24) })) } }); diff --git a/tests/unit/out/unsafe/immutable_unsigned_arithmetic.rs b/tests/unit/out/unsafe/immutable_unsigned_arithmetic.rs index 483651b3e8..e44ca4509a 100644 --- a/tests/unit/out/unsafe/immutable_unsigned_arithmetic.rs +++ b/tests/unit/out/unsafe/immutable_unsigned_arithmetic.rs @@ -15,7 +15,11 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut a: u32 = 0_u32; let mut p: *mut u32 = (&mut a as *mut u32); - (*p) = (*p).wrapping_add((*p)); + match ({ (*p) }, &mut (*p)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; + } + }; return ((*p) as i32); } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/inet_pton_ntop.rs b/tests/unit/out/unsafe/inet_pton_ntop.rs index 04060d5353..ea12814d1f 100644 --- a/tests/unit/out/unsafe/inet_pton_ntop.rs +++ b/tests/unit/out/unsafe/inet_pton_ntop.rs @@ -50,8 +50,14 @@ pub unsafe fn test_s6_addr_access_0() { ((((*(&mut addr as *mut ::libc::in6_addr)).s6_addr[(0) as usize] as i32) == (32)) && (((*(ap as *mut ::libc::in6_addr)).s6_addr[(1) as usize] as i32) == (1))) ); - (*(&mut addr as *mut ::libc::in6_addr)).s6_addr[(15) as usize] = - (((*(&mut addr as *mut ::libc::in6_addr)).s6_addr[(15) as usize] as i32) + 4) as u8; + match ( + { 4 }, + &mut ((*(&mut addr as *mut ::libc::in6_addr)).s6_addr[(15) as usize]), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (((*__tmp_3) as i32) + (__tmp_2 as i32)) as u8; + } + }; (*(ap as *mut ::libc::in6_addr)).s6_addr[(15) as usize].postfix_inc(); assert!((((*(&mut addr as *mut ::libc::in6_addr)).s6_addr[(15) as usize] as i32) == (6))); let mut bytes: *mut u8 = (*(&mut addr as *mut ::libc::in6_addr)).s6_addr.as_mut_ptr(); @@ -62,13 +68,13 @@ pub unsafe fn test_s6_addr_access_0() { (*fourth) = 8_u8; assert!((((*(&mut addr as *mut ::libc::in6_addr)).s6_addr[(3) as usize] as i32) == (8))); { - let mut __tmp_2 = + let mut __tmp_4 = { ((*(ap as *mut ::libc::in6_addr)).s6_addr.as_mut_ptr() as *mut ::libc::c_void) }; - let mut __tmp_3 = { (loopback.as_ptr() as *const ::libc::c_void) }; + let mut __tmp_5 = { (loopback.as_ptr() as *const ::libc::c_void) }; if 16_usize != 0 { - ::std::ptr::copy_nonoverlapping(__tmp_3, __tmp_2, 16_usize) + ::std::ptr::copy_nonoverlapping(__tmp_5, __tmp_4, 16_usize) } - __tmp_2 + __tmp_4 }; assert!( (({ diff --git a/tests/unit/out/unsafe/inline_container_fields.rs b/tests/unit/out/unsafe/inline_container_fields.rs index 57a96262be..253d88b085 100644 --- a/tests/unit/out/unsafe/inline_container_fields.rs +++ b/tests/unit/out/unsafe/inline_container_fields.rs @@ -219,7 +219,11 @@ unsafe fn main_0() -> i32 { k.prefix_inc(); } } - (*c) = (((*c) as i32) + 5) as i16; + match ({ 5 }, &mut (*c)) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = (((*__tmp_5) as i32) + (__tmp_4 as i32)) as i16; + } + }; (*id) = 11; s.count = 3; assert!( diff --git a/tests/unit/out/unsafe/lambda_generic.rs b/tests/unit/out/unsafe/lambda_generic.rs index 5d2d06cf34..b74abfbd87 100644 --- a/tests/unit/out/unsafe/lambda_generic.rs +++ b/tests/unit/out/unsafe/lambda_generic.rs @@ -50,7 +50,11 @@ unsafe fn main_0() -> i32 { (*total) += ((x) * (y)); }, |mut x: u32, mut y: u32| { - (*total) = (((*total) as u32).wrapping_add((x).wrapping_mul(y))) as i32; + match ({ (x).wrapping_mul(y) }, &mut (*total)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as i32; + } + }; } ); (unsafe { accumulate.spec::(0).call(2, 3) }); diff --git a/tests/unit/out/unsafe/lambda_generic_explicit_args.rs b/tests/unit/out/unsafe/lambda_generic_explicit_args.rs index 43b63fcd28..69374b2b49 100644 --- a/tests/unit/out/unsafe/lambda_generic_explicit_args.rs +++ b/tests/unit/out/unsafe/lambda_generic_explicit_args.rs @@ -28,18 +28,30 @@ unsafe fn main_0() -> i32 { let total: *mut i32 = &mut total; }, || { - (*total) = (((*total) as usize).wrapping_add( - ((::std::mem::size_of::() as usize) - .wrapping_add((::std::mem::size_of::() as usize)) - as usize), - )) as i32; + match ( + { + (::std::mem::size_of::() as usize) + .wrapping_add((::std::mem::size_of::() as usize)) + }, + &mut (*total), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as usize).wrapping_add((__tmp_0 as usize))) as i32; + } + }; }, || { - (*total) = (((*total) as usize).wrapping_add( - ((::std::mem::size_of::() as usize) - .wrapping_add((::std::mem::size_of::() as usize)) - as usize), - )) as i32; + match ( + { + (::std::mem::size_of::() as usize) + .wrapping_add((::std::mem::size_of::() as usize)) + }, + &mut (*total), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (((*__tmp_3) as usize).wrapping_add((__tmp_2 as usize))) as i32; + } + }; } ); (unsafe { tally.spec::(0).call() }); diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 2aa3777fcd..97a26a65f0 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -83,22 +83,56 @@ unsafe fn main_0() -> i32 { let mut b: Key = Key::new({ 2 }); let mut c: Key = Key::new({ 3 }); (*m.subscript(&a, || 0_i32)) = 10; - ok = ((ok as i32) - & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1)) as i32)) - != 0; + match ( + { (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1)) as i32) }, + &mut (ok), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as i32) & (__tmp_0 as i32)) != 0; + } + }; (*m.subscript(&b, || 0_i32)) = 20; - ok = ((ok as i32) - & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32)) - != 0; + match ( + { (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32) }, + &mut (ok), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (((*__tmp_3) as i32) & (__tmp_2 as i32)) != 0; + } + }; (*m.subscript(&a, || 0_i32)) = 11; - ok = ((ok as i32) - & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32)) - != 0; - ok = ((ok as i32) & ((((*m.find(&a).iter_deref()).1) == (11)) as i32)) != 0; - ok = ((ok as i32) & ((((*m.get(&b).expect("out of range!")).1) == (20)) as i32)) != 0; - ok = ((ok as i32) - & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32)) - != 0; + match ( + { (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32) }, + &mut (ok), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) != 0; + } + }; + match ( + { ((((*m.find(&a).iter_deref()).1) == (11)) as i32) }, + &mut (ok), + ) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as i32) & (__tmp_6 as i32)) != 0; + } + }; + match ( + { ((((*m.get(&b).expect("out of range!")).1) == (20)) as i32) }, + &mut (ok), + ) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as i32) & (__tmp_8 as i32)) != 0; + } + }; + match ( + { (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32) }, + &mut (ok), + ) { + (__tmp_10, __tmp_11) => { + (*__tmp_11) = (((*__tmp_11) as i32) & (__tmp_10 as i32)) != 0; + } + }; (*m.subscript_move( &mut (unsafe { make_key_3(4) }), |__k| cpp_move_unsafe!(__k), @@ -109,59 +143,149 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || 0_i32, )) = 41; - ok = ((ok as i32) - & (((((*std::cell::LazyCell::force_mut(&mut *&raw mut made_2)) == (2)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (1))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2))) - as i32)) - != 0; + match ( + { + (((((*std::cell::LazyCell::force_mut(&mut *&raw mut made_2)) == (2)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (1))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2))) + as i32) + }, + &mut (ok), + ) { + (__tmp_12, __tmp_13) => { + (*__tmp_13) = (((*__tmp_13) as i32) & (__tmp_12 as i32)) != 0; + } + }; (*m.subscript_move(&mut c, |__k| cpp_move_unsafe!(__k), || 0_i32)) = 30; (*m.subscript_move(&mut c, |__k| cpp_move_unsafe!(__k), || 0_i32)) = 31; - ok = ((ok as i32) - & (((((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (2)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2))) - && ((c.k) == (3))) as i32)) - != 0; - ok = ((ok as i32) & (((m.len()) == (4_usize)) as i32)) != 0; + match ( + { + (((((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (2)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2))) + && ((c.k) == (3))) as i32) + }, + &mut (ok), + ) { + (__tmp_14, __tmp_15) => { + (*__tmp_15) = (((*__tmp_15) as i32) & (__tmp_14 as i32)) != 0; + } + }; + match ({ (((m.len()) == (4_usize)) as i32) }, &mut (ok)) { + (__tmp_16, __tmp_17) => { + (*__tmp_17) = (((*__tmp_17) as i32) & (__tmp_16 as i32)) != 0; + } + }; (*m.subscript(&(*m.begin().iter_deref()).0, || 0_i32)) += 1; - ok = ((ok as i32) - & ((((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) - && ((*m.subscript(&a, || 0_i32)) == (12))) as i32)) - != 0; + match ( + { + ((((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) + && ((*m.subscript(&a, || 0_i32)) == (12))) as i32) + }, + &mut (ok), + ) { + (__tmp_18, __tmp_19) => { + (*__tmp_19) = (((*__tmp_19) as i32) & (__tmp_18 as i32)) != 0; + } + }; let mut first: *const Key = (&(*m.begin().iter_deref()).0 as *const Key); (*m.subscript_move(&mut Key::new({ 0 }), |__k| cpp_move_unsafe!(__k), || 0_i32)) = 0; - ok = ((ok as i32) - & (((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (3)) as i32)) - != 0; - ok = ((ok as i32) & (((&(*m.find(&a).iter_deref()).0 as *const Key) == (first)) as i32)) != 0; + match ( + { (((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (3)) as i32) }, + &mut (ok), + ) { + (__tmp_20, __tmp_21) => { + (*__tmp_21) = (((*__tmp_21) as i32) & (__tmp_20 as i32)) != 0; + } + }; + match ( + { (((&(*m.find(&a).iter_deref()).0 as *const Key) == (first)) as i32) }, + &mut (ok), + ) { + (__tmp_22, __tmp_23) => { + (*__tmp_23) = (((*__tmp_23) as i32) & (__tmp_22 as i32)) != 0; + } + }; let mut n: UnsafeMap = m.clone(); - ok = ((ok as i32) - & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == ((2) + (5))) as i32)) - != 0; - ok = ((ok as i32) - & ((((n.len()) == (5_usize)) && ((*n.subscript(&a, || 0_i32)) == (12))) as i32)) - != 0; + match ( + { (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == ((2) + (5))) as i32) }, + &mut (ok), + ) { + (__tmp_24, __tmp_25) => { + (*__tmp_25) = (((*__tmp_25) as i32) & (__tmp_24 as i32)) != 0; + } + }; + match ( + { ((((n.len()) == (5_usize)) && ((*n.subscript(&a, || 0_i32)) == (12))) as i32) }, + &mut (ok), + ) { + (__tmp_26, __tmp_27) => { + (*__tmp_27) = (((*__tmp_27) as i32) & (__tmp_26 as i32)) != 0; + } + }; m.erase(&m.find(&a)); - ok = ((ok as i32) & (((m.erase_key(&b)) == (1_usize)) as i32)) != 0; - ok = ((ok as i32) & (((m.erase_key(&b)) == (0_usize)) as i32)) != 0; - ok = ((ok as i32) & (((m.erase_key(&(*m.begin().iter_deref()).0)) == (1_usize)) as i32)) != 0; - ok = ((ok as i32) - & ((((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (7)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (3))) - as i32)) - != 0; - ok = ((ok as i32) & ((((m.len()) == (2_usize)) && ((n.len()) == (5_usize))) as i32)) != 0; + match ({ (((m.erase_key(&b)) == (1_usize)) as i32) }, &mut (ok)) { + (__tmp_28, __tmp_29) => { + (*__tmp_29) = (((*__tmp_29) as i32) & (__tmp_28 as i32)) != 0; + } + }; + match ({ (((m.erase_key(&b)) == (0_usize)) as i32) }, &mut (ok)) { + (__tmp_30, __tmp_31) => { + (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; + } + }; + match ( + { (((m.erase_key(&(*m.begin().iter_deref()).0)) == (1_usize)) as i32) }, + &mut (ok), + ) { + (__tmp_32, __tmp_33) => { + (*__tmp_33) = (((*__tmp_33) as i32) & (__tmp_32 as i32)) != 0; + } + }; + match ( + { + ((((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (7)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (3))) + as i32) + }, + &mut (ok), + ) { + (__tmp_34, __tmp_35) => { + (*__tmp_35) = (((*__tmp_35) as i32) & (__tmp_34 as i32)) != 0; + } + }; + match ( + { ((((m.len()) == (2_usize)) && ((n.len()) == (5_usize))) as i32) }, + &mut (ok), + ) { + (__tmp_36, __tmp_37) => { + (*__tmp_37) = (((*__tmp_37) as i32) & (__tmp_36 as i32)) != 0; + } + }; let mut sum: i32 = 0; 'loop_: for entry in IterRange::new(m.begin(), m.end()) { let entry: *const (Key, i32) = &(*entry.iter_deref()); sum += (((*entry).0.k) * ((*entry).1)); } - ok = ((ok as i32) & (((sum) == (((3) * (31)) + ((4) * (41)))) as i32)) != 0; - ok = ((ok as i32) - & ((((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (7)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (3))) - as i32)) - != 0; + match ( + { (((sum) == (((3) * (31)) + ((4) * (41)))) as i32) }, + &mut (ok), + ) { + (__tmp_38, __tmp_39) => { + (*__tmp_39) = (((*__tmp_39) as i32) & (__tmp_38 as i32)) != 0; + } + }; + match ( + { + ((((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (7)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (3))) + as i32) + }, + &mut (ok), + ) { + (__tmp_40, __tmp_41) => { + (*__tmp_41) = (((*__tmp_41) as i32) & (__tmp_40 as i32)) != 0; + } + }; (unsafe { libc::printf( c"%d %d %d\n".as_ptr() as *const libc::c_char, diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index 3db4f6cd3e..9f47f4f24b 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -77,57 +77,140 @@ unsafe fn main_0() -> i32 { order: 2, identity: 7, }; - ok = ((ok as i32) - & ((unsafe { - let _a: *const Key = &distinct_a; - operator_eq_2(_a, &distinct_b) - }) as i32)) - != 0; + match ( + { + ((unsafe { + let _a: *const Key = &distinct_a; + operator_eq_2(_a, &distinct_b) + }) as i32) + }, + &mut (ok), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as i32) & (__tmp_0 as i32)) != 0; + } + }; let mut distinct: UnsafeMap = UnsafeMap::new(); let a: *mut Mapped = &mut (*distinct.subscript(&distinct_a, || ::default())); (*a).value = 11; let mut a_it: UnsafeBidirectionalIterator<(Key, Mapped)> = distinct.find(&distinct_a); let mut a_value: *mut Mapped = (&mut (*a_it.iter_deref()).1 as *mut Mapped); - ok = ((ok as i32) - & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == (1)) - as i32)) - != 0; + match ( + { + (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == (1)) + as i32) + }, + &mut (ok), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (((*__tmp_3) as i32) & (__tmp_2 as i32)) != 0; + } + }; let b: *mut Mapped = &mut (*distinct.subscript(&distinct_b, || ::default())); (*b).value = 22; let mut b_it: UnsafeBidirectionalIterator<(Key, Mapped)> = distinct.find(&distinct_b); - ok = ((ok as i32) - & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == (2)) - as i32)) - != 0; - ok = ((ok as i32) & (((distinct.len()) == (2_usize)) as i32)) != 0; - ok = ((ok as i32) & (((a) != (b)) as i32)) != 0; - ok = ((ok as i32) & (((((*a).value) == (11)) && (((*b).value) == (22))) as i32)) != 0; - ok = ((ok as i32) & ((a_it == distinct.find(&distinct_a)) as i32)) != 0; - ok = ((ok as i32) & ((b_it == distinct.find(&distinct_b)) as i32)) != 0; - ok = ((ok as i32) & ((b_it != distinct.end()) as i32)) != 0; - ok = ((ok as i32) & (((&mut (*a_it.iter_deref()).1 as *mut Mapped) == (a_value)) as i32)) != 0; - ok = ((ok as i32) & ((((*a_it.iter_deref()).1.value) == (11)) as i32)) != 0; - ok = ((ok as i32) - & ((unsafe { - let _a: *const Key = &distinct_a; - operator_eq_2(_a, &distinct_b) - }) as i32)) - != 0; + match ( + { + (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == (2)) + as i32) + }, + &mut (ok), + ) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) != 0; + } + }; + match ({ (((distinct.len()) == (2_usize)) as i32) }, &mut (ok)) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as i32) & (__tmp_6 as i32)) != 0; + } + }; + match ({ (((a) != (b)) as i32) }, &mut (ok)) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as i32) & (__tmp_8 as i32)) != 0; + } + }; + match ( + { (((((*a).value) == (11)) && (((*b).value) == (22))) as i32) }, + &mut (ok), + ) { + (__tmp_10, __tmp_11) => { + (*__tmp_11) = (((*__tmp_11) as i32) & (__tmp_10 as i32)) != 0; + } + }; + match ({ ((a_it == distinct.find(&distinct_a)) as i32) }, &mut (ok)) { + (__tmp_12, __tmp_13) => { + (*__tmp_13) = (((*__tmp_13) as i32) & (__tmp_12 as i32)) != 0; + } + }; + match ({ ((b_it == distinct.find(&distinct_b)) as i32) }, &mut (ok)) { + (__tmp_14, __tmp_15) => { + (*__tmp_15) = (((*__tmp_15) as i32) & (__tmp_14 as i32)) != 0; + } + }; + match ({ ((b_it != distinct.end()) as i32) }, &mut (ok)) { + (__tmp_16, __tmp_17) => { + (*__tmp_17) = (((*__tmp_17) as i32) & (__tmp_16 as i32)) != 0; + } + }; + match ( + { (((&mut (*a_it.iter_deref()).1 as *mut Mapped) == (a_value)) as i32) }, + &mut (ok), + ) { + (__tmp_18, __tmp_19) => { + (*__tmp_19) = (((*__tmp_19) as i32) & (__tmp_18 as i32)) != 0; + } + }; + match ( + { ((((*a_it.iter_deref()).1.value) == (11)) as i32) }, + &mut (ok), + ) { + (__tmp_20, __tmp_21) => { + (*__tmp_21) = (((*__tmp_21) as i32) & (__tmp_20 as i32)) != 0; + } + }; + match ( + { + ((unsafe { + let _a: *const Key = &distinct_a; + operator_eq_2(_a, &distinct_b) + }) as i32) + }, + &mut (ok), + ) { + (__tmp_22, __tmp_23) => { + (*__tmp_23) = (((*__tmp_23) as i32) & (__tmp_22 as i32)) != 0; + } + }; let mut distinct_count: usize = 0_usize; 'loop_: for entry in IterRange::new(distinct.begin(), distinct.end()) { let entry: *const (Key, Mapped) = &(*entry.iter_deref()); if ((distinct_count) == (0_usize)) { - ok = ((ok as i32) - & (((((*entry).0.order) == (1)) && (((*entry).1.value) == (11))) as i32)) - != 0; + match ( + { (((((*entry).0.order) == (1)) && (((*entry).1.value) == (11))) as i32) }, + &mut (ok), + ) { + (__tmp_24, __tmp_25) => { + (*__tmp_25) = (((*__tmp_25) as i32) & (__tmp_24 as i32)) != 0; + } + }; } else if ((distinct_count) == (1_usize)) { - ok = ((ok as i32) - & (((((*entry).0.order) == (2)) && (((*entry).1.value) == (22))) as i32)) - != 0; + match ( + { (((((*entry).0.order) == (2)) && (((*entry).1.value) == (22))) as i32) }, + &mut (ok), + ) { + (__tmp_26, __tmp_27) => { + (*__tmp_27) = (((*__tmp_27) as i32) & (__tmp_26 as i32)) != 0; + } + }; } distinct_count.prefix_inc(); } - ok = ((ok as i32) & (((distinct_count) == (2_usize)) as i32)) != 0; + match ({ (((distinct_count) == (2_usize)) as i32) }, &mut (ok)) { + (__tmp_28, __tmp_29) => { + (*__tmp_29) = (((*__tmp_29) as i32) & (__tmp_28 as i32)) != 0; + } + }; let equivalent_a: Key = Key { order: 3, identity: 8, @@ -136,12 +219,19 @@ unsafe fn main_0() -> i32 { order: 3, identity: 9, }; - ok = ((ok as i32) - & (!(unsafe { - let _a: *const Key = &equivalent_a; - operator_eq_2(_a, &equivalent_b) - }) as i32)) - != 0; + match ( + { + (!(unsafe { + let _a: *const Key = &equivalent_a; + operator_eq_2(_a, &equivalent_b) + }) as i32) + }, + &mut (ok), + ) { + (__tmp_30, __tmp_31) => { + (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; + } + }; let mut equivalent: UnsafeMap = UnsafeMap::new(); let before_equivalent: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)); @@ -149,60 +239,155 @@ unsafe fn main_0() -> i32 { (*first).value = 31; let mut first_it: UnsafeBidirectionalIterator<(Key, Mapped)> = equivalent.find(&equivalent_a); let mut first_value: *mut Mapped = (&mut (*first_it.iter_deref()).1 as *mut Mapped); - ok = ((ok as i32) - & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) - == ((before_equivalent) + (1))) as i32)) - != 0; + match ( + { + (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) + == ((before_equivalent) + (1))) as i32) + }, + &mut (ok), + ) { + (__tmp_32, __tmp_33) => { + (*__tmp_33) = (((*__tmp_33) as i32) & (__tmp_32 as i32)) != 0; + } + }; let second: *mut Mapped = &mut (*equivalent.subscript(&equivalent_b, || ::default())); let reused: bool = ((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == ((before_equivalent) + (1))); - ok = ((ok as i32) & (reused as i32)) != 0; - ok = ((ok as i32) & (((equivalent.len()) == (1_usize)) as i32)) != 0; + match ({ (reused as i32) }, &mut (ok)) { + (__tmp_34, __tmp_35) => { + (*__tmp_35) = (((*__tmp_35) as i32) & (__tmp_34 as i32)) != 0; + } + }; + match ({ (((equivalent.len()) == (1_usize)) as i32) }, &mut (ok)) { + (__tmp_36, __tmp_37) => { + (*__tmp_37) = (((*__tmp_37) as i32) & (__tmp_36 as i32)) != 0; + } + }; if reused { - ok = ((ok as i32) & ((first_it != equivalent.end()) as i32)) != 0; - ok = ((ok as i32) & (((first) == (second)) as i32)) != 0; - ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_a)) as i32)) != 0; - ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_b)) as i32)) != 0; - ok = ((ok as i32) - & (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32)) - != 0; - ok = ((ok as i32) - & (((((*first_it.iter_deref()).1.value) == (31)) && (((*second).value) == (31))) - as i32)) - != 0; + match ({ ((first_it != equivalent.end()) as i32) }, &mut (ok)) { + (__tmp_38, __tmp_39) => { + (*__tmp_39) = (((*__tmp_39) as i32) & (__tmp_38 as i32)) != 0; + } + }; + match ({ (((first) == (second)) as i32) }, &mut (ok)) { + (__tmp_40, __tmp_41) => { + (*__tmp_41) = (((*__tmp_41) as i32) & (__tmp_40 as i32)) != 0; + } + }; + match ( + { ((first_it == equivalent.find(&equivalent_a)) as i32) }, + &mut (ok), + ) { + (__tmp_42, __tmp_43) => { + (*__tmp_43) = (((*__tmp_43) as i32) & (__tmp_42 as i32)) != 0; + } + }; + match ( + { ((first_it == equivalent.find(&equivalent_b)) as i32) }, + &mut (ok), + ) { + (__tmp_44, __tmp_45) => { + (*__tmp_45) = (((*__tmp_45) as i32) & (__tmp_44 as i32)) != 0; + } + }; + match ( + { (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32) }, + &mut (ok), + ) { + (__tmp_46, __tmp_47) => { + (*__tmp_47) = (((*__tmp_47) as i32) & (__tmp_46 as i32)) != 0; + } + }; + match ( + { + (((((*first_it.iter_deref()).1.value) == (31)) && (((*second).value) == (31))) + as i32) + }, + &mut (ok), + ) { + (__tmp_48, __tmp_49) => { + (*__tmp_49) = (((*__tmp_49) as i32) & (__tmp_48 as i32)) != 0; + } + }; let mut equivalent_count: usize = 0_usize; 'loop_: for entry in IterRange::new(equivalent.begin(), equivalent.end()) { let entry: *const (Key, Mapped) = &(*entry.iter_deref()); - ok = ((ok as i32) - & (((((*entry).0.order) == (3)) && (((*entry).1.value) == (31))) as i32)) - != 0; + match ( + { (((((*entry).0.order) == (3)) && (((*entry).1.value) == (31))) as i32) }, + &mut (ok), + ) { + (__tmp_50, __tmp_51) => { + (*__tmp_51) = (((*__tmp_51) as i32) & (__tmp_50 as i32)) != 0; + } + }; equivalent_count.prefix_inc(); } - ok = ((ok as i32) & (((equivalent_count) == (1_usize)) as i32)) != 0; + match ({ (((equivalent_count) == (1_usize)) as i32) }, &mut (ok)) { + (__tmp_52, __tmp_53) => { + (*__tmp_53) = (((*__tmp_53) as i32) & (__tmp_52 as i32)) != 0; + } + }; } - ok = ((ok as i32) - & (!(unsafe { - let _a: *const Key = &equivalent_a; - operator_eq_2(_a, &equivalent_b) - }) as i32)) - != 0; + match ( + { + (!(unsafe { + let _a: *const Key = &equivalent_a; + operator_eq_2(_a, &equivalent_b) + }) as i32) + }, + &mut (ok), + ) { + (__tmp_54, __tmp_55) => { + (*__tmp_55) = (((*__tmp_55) as i32) & (__tmp_54 as i32)) != 0; + } + }; let later_key: Key = Key { order: 4, identity: 10, }; let later: *mut Mapped = &mut (*equivalent.subscript(&later_key, || ::default())); (*later).value = 41; - ok = ((ok as i32) - & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) - == ((before_equivalent) + (2))) as i32)) - != 0; - ok = ((ok as i32) & (((equivalent.len()) == (2_usize)) as i32)) != 0; + match ( + { + (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) + == ((before_equivalent) + (2))) as i32) + }, + &mut (ok), + ) { + (__tmp_56, __tmp_57) => { + (*__tmp_57) = (((*__tmp_57) as i32) & (__tmp_56 as i32)) != 0; + } + }; + match ({ (((equivalent.len()) == (2_usize)) as i32) }, &mut (ok)) { + (__tmp_58, __tmp_59) => { + (*__tmp_59) = (((*__tmp_59) as i32) & (__tmp_58 as i32)) != 0; + } + }; if reused { - ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_a)) as i32)) != 0; - ok = ((ok as i32) - & (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32)) - != 0; - ok = ((ok as i32) & ((((*first_it.iter_deref()).1.value) == (31)) as i32)) != 0; + match ( + { ((first_it == equivalent.find(&equivalent_a)) as i32) }, + &mut (ok), + ) { + (__tmp_60, __tmp_61) => { + (*__tmp_61) = (((*__tmp_61) as i32) & (__tmp_60 as i32)) != 0; + } + }; + match ( + { (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32) }, + &mut (ok), + ) { + (__tmp_62, __tmp_63) => { + (*__tmp_63) = (((*__tmp_63) as i32) & (__tmp_62 as i32)) != 0; + } + }; + match ( + { ((((*first_it.iter_deref()).1.value) == (31)) as i32) }, + &mut (ok), + ) { + (__tmp_64, __tmp_65) => { + (*__tmp_65) = (((*__tmp_65) as i32) & (__tmp_64 as i32)) != 0; + } + }; } let matching_a: Key = Key { order: 5, @@ -223,35 +408,106 @@ unsafe fn main_0() -> i32 { (*matched).value = 51; let mut matched_it: UnsafeBidirectionalIterator<(Key, Mapped)> = matching.find(&matching_a); let mut matched_value: *mut Mapped = (&mut (*matched_it.iter_deref()).1 as *mut Mapped); - ok = ((ok as i32) - & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) - == ((before_matching) + (1))) as i32)) - != 0; + match ( + { + (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) + == ((before_matching) + (1))) as i32) + }, + &mut (ok), + ) { + (__tmp_66, __tmp_67) => { + (*__tmp_67) = (((*__tmp_67) as i32) & (__tmp_66 as i32)) != 0; + } + }; let matched_again: *mut Mapped = &mut (*matching.subscript(&matching_b, || ::default())); - ok = ((ok as i32) - & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) - == ((before_matching) + (1))) as i32)) - != 0; - ok = ((ok as i32) & (((matching.len()) == (1_usize)) as i32)) != 0; - ok = ((ok as i32) & (((matched) == (matched_again)) as i32)) != 0; - ok = ((ok as i32) & ((matched_it == matching.find(&matching_b)) as i32)) != 0; - ok = ((ok as i32) - & (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32)) - != 0; - ok = ((ok as i32) & ((((*matched_it.iter_deref()).1.value) == (51)) as i32)) != 0; + match ( + { + (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) + == ((before_matching) + (1))) as i32) + }, + &mut (ok), + ) { + (__tmp_68, __tmp_69) => { + (*__tmp_69) = (((*__tmp_69) as i32) & (__tmp_68 as i32)) != 0; + } + }; + match ({ (((matching.len()) == (1_usize)) as i32) }, &mut (ok)) { + (__tmp_70, __tmp_71) => { + (*__tmp_71) = (((*__tmp_71) as i32) & (__tmp_70 as i32)) != 0; + } + }; + match ({ (((matched) == (matched_again)) as i32) }, &mut (ok)) { + (__tmp_72, __tmp_73) => { + (*__tmp_73) = (((*__tmp_73) as i32) & (__tmp_72 as i32)) != 0; + } + }; + match ( + { ((matched_it == matching.find(&matching_b)) as i32) }, + &mut (ok), + ) { + (__tmp_74, __tmp_75) => { + (*__tmp_75) = (((*__tmp_75) as i32) & (__tmp_74 as i32)) != 0; + } + }; + match ( + { (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32) }, + &mut (ok), + ) { + (__tmp_76, __tmp_77) => { + (*__tmp_77) = (((*__tmp_77) as i32) & (__tmp_76 as i32)) != 0; + } + }; + match ( + { ((((*matched_it.iter_deref()).1.value) == (51)) as i32) }, + &mut (ok), + ) { + (__tmp_78, __tmp_79) => { + (*__tmp_79) = (((*__tmp_79) as i32) & (__tmp_78 as i32)) != 0; + } + }; let other: *mut Mapped = &mut (*matching.subscript(&matching_c, || ::default())); (*other).value = 61; - ok = ((ok as i32) - & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) - == ((before_matching) + (2))) as i32)) - != 0; - ok = ((ok as i32) & (((matching.len()) == (2_usize)) as i32)) != 0; - ok = ((ok as i32) & ((matched_it == matching.find(&matching_a)) as i32)) != 0; - ok = ((ok as i32) - & (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32)) - != 0; - ok = ((ok as i32) & ((((*matched_it.iter_deref()).1.value) == (51)) as i32)) != 0; + match ( + { + (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) + == ((before_matching) + (2))) as i32) + }, + &mut (ok), + ) { + (__tmp_80, __tmp_81) => { + (*__tmp_81) = (((*__tmp_81) as i32) & (__tmp_80 as i32)) != 0; + } + }; + match ({ (((matching.len()) == (2_usize)) as i32) }, &mut (ok)) { + (__tmp_82, __tmp_83) => { + (*__tmp_83) = (((*__tmp_83) as i32) & (__tmp_82 as i32)) != 0; + } + }; + match ( + { ((matched_it == matching.find(&matching_a)) as i32) }, + &mut (ok), + ) { + (__tmp_84, __tmp_85) => { + (*__tmp_85) = (((*__tmp_85) as i32) & (__tmp_84 as i32)) != 0; + } + }; + match ( + { (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32) }, + &mut (ok), + ) { + (__tmp_86, __tmp_87) => { + (*__tmp_87) = (((*__tmp_87) as i32) & (__tmp_86 as i32)) != 0; + } + }; + match ( + { ((((*matched_it.iter_deref()).1.value) == (51)) as i32) }, + &mut (ok), + ) { + (__tmp_88, __tmp_89) => { + (*__tmp_89) = (((*__tmp_89) as i32) & (__tmp_88 as i32)) != 0; + } + }; return if ok { 0 } else { 1 }; } pub unsafe fn __cpp2rust_init_globals() { diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index e32a166f94..2a2c2edd99 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -68,9 +68,11 @@ impl RefItem { } pub unsafe fn new_2(counter: *mut i32, mut amount: i32) -> Self { let mut this = Self { - value: { - (*counter) += amount; - (*counter) + value: match ({ amount }, &mut (*counter)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as i32) + (__tmp_0 as i32)) as i32; + (*__tmp_1).clone() + } }, }; (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)).prefix_inc(); @@ -103,15 +105,15 @@ pub static mut seed_9: std::cell::LazyCell = std::cell::LazyCell::new(|| un pub static mut global_hit_10: std::cell::LazyCell<(UnsafeBidirectionalIterator<(i32, i32)>, bool)> = std::cell::LazyCell::new(|| unsafe { match (({ - let __tmp_1 = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_counter_8)); - (*__tmp_1).prefix_inc(); - __tmp_1 + let __tmp_3 = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_counter_8)); + (*__tmp_3).prefix_inc(); + __tmp_3 } as *mut i32),) { - (__tmp_0,) => (*std::cell::LazyCell::force_mut(&mut *&raw mut global_map_6)) + (__tmp_2,) => (*std::cell::LazyCell::force_mut(&mut *&raw mut global_map_6)) .try_emplace( (*std::cell::LazyCell::force_mut(&mut *&raw mut global_key_7)), - || (*__tmp_0), + || (*__tmp_2), ), } }); @@ -168,65 +170,118 @@ unsafe fn main_0() -> i32 { UnsafeBidirectionalIterator<(i32, i32)>, bool, ) = { - let mut __tmp_3: i32; + let mut __tmp_5: i32; if (post != 0) { match (({ - __tmp_3 = counter.postfix_inc(); - &mut __tmp_3 + __tmp_5 = counter.postfix_inc(); + &mut __tmp_5 } as *mut i32),) { - (__tmp_2,) => m + (__tmp_4,) => m .try_emplace(key, || { - (*__tmp_2) + (*__tmp_4) }), } } else { match (({ - let __tmp_5 = &mut counter; - (*__tmp_5).prefix_inc(); - __tmp_5 + let __tmp_7 = &mut counter; + (*__tmp_7).prefix_inc(); + __tmp_7 } as *mut i32),) { - (__tmp_4,) => m + (__tmp_6,) => m .try_emplace(key, || { - (*__tmp_4) + (*__tmp_6) }), } } }; let mut hit: bool = (((subset) & ((1) << (key))) != (0)); - ok = ((ok as i32) - & (((counter) == ((initial) + (1))) - as i32)) - != 0; - ok = ((ok as i32) - & ((((result.1) as i32) == (!(hit) as i32)) - as i32)) - != 0; + match ( + { + (((counter) == ((initial) + (1))) + as i32) + }, + &mut (ok), + ) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as i32) + & (__tmp_8 as i32)) + != 0; + } + }; + match ( + { + ((((result.1) as i32) + == (!(hit) as i32)) + as i32) + }, + &mut (ok), + ) { + (__tmp_10, __tmp_11) => { + (*__tmp_11) = (((*__tmp_11) as i32) + & (__tmp_10 as i32)) + != 0; + } + }; let mut found: bool = result.0 == m.find(&key); - ok = ((ok as i32) & (found as i32)) != 0; - ok = ((ok as i32) - & ((((*result.0.iter_deref()).0) == (key)) - as i32)) - != 0; - ok = ((ok as i32) - & ((((*result.0.iter_deref()).1) - == (if hit { - ((10) + (key)) - } else { - ((initial) + (!(post != 0) as i32)) - })) - as i32)) - != 0; - ok = ((ok as i32) - & (((m.len()) - == (((size) + (!(hit) as i32)) - as usize)) - as i32)) - != 0; + match ({ (found as i32) }, &mut (ok)) { + (__tmp_12, __tmp_13) => { + (*__tmp_13) = (((*__tmp_13) as i32) + & (__tmp_12 as i32)) + != 0; + } + }; + match ( + { + ((((*result.0.iter_deref()).0) == (key)) + as i32) + }, + &mut (ok), + ) { + (__tmp_14, __tmp_15) => { + (*__tmp_15) = (((*__tmp_15) as i32) + & (__tmp_14 as i32)) + != 0; + } + }; + match ( + { + ((((*result.0.iter_deref()).1) + == (if hit { + ((10) + (key)) + } else { + ((initial) + + (!(post != 0) as i32)) + })) + as i32) + }, + &mut (ok), + ) { + (__tmp_16, __tmp_17) => { + (*__tmp_17) = (((*__tmp_17) as i32) + & (__tmp_16 as i32)) + != 0; + } + }; + match ( + { + (((m.len()) + == (((size) + (!(hit) as i32)) + as usize)) + as i32) + }, + &mut (ok), + ) { + (__tmp_18, __tmp_19) => { + (*__tmp_19) = (((*__tmp_19) as i32) + & (__tmp_18 as i32)) + != 0; + } + }; rows.prefix_inc(); } post.prefix_inc(); @@ -248,66 +303,134 @@ unsafe fn main_0() -> i32 { let mut key: i32 = 0; items.try_emplace(key, || Item::new_1({ 10 })); let mut source: Item = Item::new_1({ 20 }); - (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = match ( + { + match ( + { 0 }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)), + ) { + (__tmp_22, __tmp_23) => { + (*__tmp_23) = __tmp_22; + (*__tmp_23).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)), + ) { + (__tmp_20, __tmp_21) => { + (*__tmp_21) = __tmp_20; + (*__tmp_21).clone() + } }; let mut hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { argument_4(&mut source) }) as *mut Item),) { - (__tmp_6,) => items.try_emplace(key, || Item::copy_from({ __tmp_6 })), + (__tmp_24,) => items.try_emplace(key, || Item::copy_from({ __tmp_24 })), }; - ok = ((ok as i32) - & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (1)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) - as i32)) - != 0; - ok = ((ok as i32) & (((!(hit.1)) && (((*hit.0.iter_deref()).1.value) == (10))) as i32)) != 0; + match ( + { + ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (1)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) + as i32) + }, + &mut (ok), + ) { + (__tmp_25, __tmp_26) => { + (*__tmp_26) = (((*__tmp_26) as i32) & (__tmp_25 as i32)) != 0; + } + }; + match ( + { (((!(hit.1)) && (((*hit.0.iter_deref()).1.value) == (10))) as i32) }, + &mut (ok), + ) { + (__tmp_27, __tmp_28) => { + (*__tmp_28) = (((*__tmp_28) as i32) & (__tmp_27 as i32)) != 0; + } + }; let mut move_hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { argument_4(&mut source) }) as *mut Item),) { - (__tmp_7,) => items.try_emplace(key, || Item::move_from({ __tmp_7 })), + (__tmp_29,) => items.try_emplace(key, || Item::move_from({ __tmp_29 })), }; - ok = ((ok as i32) - & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (2)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) - as i32)) - != 0; - ok = ((ok as i32) & (((!(move_hit.1)) && ((source.value) == (20))) as i32)) != 0; + match ( + { + ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (2)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) + as i32) + }, + &mut (ok), + ) { + (__tmp_30, __tmp_31) => { + (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; + } + }; + match ( + { (((!(move_hit.1)) && ((source.value) == (20))) as i32) }, + &mut (ok), + ) { + (__tmp_32, __tmp_33) => { + (*__tmp_33) = (((*__tmp_33) as i32) & (__tmp_32 as i32)) != 0; + } + }; key.prefix_inc(); let mut copied: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { argument_4(&mut source) }) as *mut Item),) { - (__tmp_8,) => items.try_emplace(key, || Item::copy_from({ __tmp_8 })), + (__tmp_34,) => items.try_emplace(key, || Item::copy_from({ __tmp_34 })), }; - ok = ((ok as i32) - & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (3)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (1))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) - as i32)) - != 0; - ok = ((ok as i32) & (((copied.1) && (((*copied.0.iter_deref()).1.value) == (20))) as i32)) != 0; + match ( + { + ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (3)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (1))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) + as i32) + }, + &mut (ok), + ) { + (__tmp_35, __tmp_36) => { + (*__tmp_36) = (((*__tmp_36) as i32) & (__tmp_35 as i32)) != 0; + } + }; + match ( + { (((copied.1) && (((*copied.0.iter_deref()).1.value) == (20))) as i32) }, + &mut (ok), + ) { + (__tmp_37, __tmp_38) => { + (*__tmp_38) = (((*__tmp_38) as i32) & (__tmp_37 as i32)) != 0; + } + }; key.prefix_inc(); let mut moved: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { argument_4(&mut source) }) as *mut Item),) { - (__tmp_9,) => items.try_emplace(key, || Item::move_from({ __tmp_9 })), + (__tmp_39,) => items.try_emplace(key, || Item::move_from({ __tmp_39 })), }; - ok = ((ok as i32) - & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (4)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (1))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (1))) - as i32)) - != 0; - ok = ((ok as i32) - & ((((moved.1) && (((*moved.0.iter_deref()).1.value) == (20))) - && ((source.value) == (-1_i32))) as i32)) - != 0; + match ( + { + ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (4)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (1))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (1))) + as i32) + }, + &mut (ok), + ) { + (__tmp_40, __tmp_41) => { + (*__tmp_41) = (((*__tmp_41) as i32) & (__tmp_40 as i32)) != 0; + } + }; + match ( + { + ((((moved.1) && (((*moved.0.iter_deref()).1.value) == (20))) + && ((source.value) == (-1_i32))) as i32) + }, + &mut (ok), + ) { + (__tmp_42, __tmp_43) => { + (*__tmp_43) = (((*__tmp_43) as i32) & (__tmp_42 as i32)) != 0; + } + }; let mut refs: UnsafeMap = UnsafeMap::new(); key = 0; let mut counter: i32 = 0; @@ -315,73 +438,127 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = 0; let mut ref_hit: (UnsafeBidirectionalIterator<(i32, RefItem)>, bool) = match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { - (__tmp_10,) => refs.try_emplace(key, || RefItem::new_2({ __tmp_10 }, { 2 })), + (__tmp_44,) => refs.try_emplace(key, || RefItem::new_2({ __tmp_44 }, { 2 })), }; - ok = ((ok as i32) - & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (5)) - && ((counter) == (5))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) - && (!(ref_hit.1))) as i32)) - != 0; + match ( + { + ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (5)) + && ((counter) == (5))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) + && (!(ref_hit.1))) as i32) + }, + &mut (ok), + ) { + (__tmp_45, __tmp_46) => { + (*__tmp_46) = (((*__tmp_46) as i32) & (__tmp_45 as i32)) != 0; + } + }; key.prefix_inc(); let mut ref_new: (UnsafeBidirectionalIterator<(i32, RefItem)>, bool) = match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { - (__tmp_11,) => refs.try_emplace(key, || RefItem::new_2({ __tmp_11 }, { 2 })), + (__tmp_47,) => refs.try_emplace(key, || RefItem::new_2({ __tmp_47 }, { 2 })), }; - ok = ((ok as i32) - & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (6)) - && ((counter) == (7))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (1))) - && (ref_new.1)) as i32)) - != 0; - ok = ((ok as i32) - & (((((*ref_hit.0.iter_deref()).1.value) == (5)) - && (((*ref_new.0.iter_deref()).1.value) == (7))) as i32)) - != 0; + match ( + { + ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (6)) + && ((counter) == (7))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (1))) + && (ref_new.1)) as i32) + }, + &mut (ok), + ) { + (__tmp_48, __tmp_49) => { + (*__tmp_49) = (((*__tmp_49) as i32) & (__tmp_48 as i32)) != 0; + } + }; + match ( + { + (((((*ref_hit.0.iter_deref()).1.value) == (5)) + && (((*ref_new.0.iter_deref()).1.value) == (7))) as i32) + }, + &mut (ok), + ) { + (__tmp_50, __tmp_51) => { + (*__tmp_51) = (((*__tmp_51) as i32) & (__tmp_50 as i32)) != 0; + } + }; key = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = match ( + { + match ( + { 0 }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)), + ) { + (__tmp_54, __tmp_55) => { + (*__tmp_55) = __tmp_54; + (*__tmp_55).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)), + ) { + (__tmp_52, __tmp_53) => { + (*__tmp_53) = __tmp_52; + (*__tmp_53).clone() + } }; let mut temporary_hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { - let mut __tmp_13: Item; + let mut __tmp_57: Item; match (({ - __tmp_13 = Item::new_1({ 30 }); - &mut __tmp_13 + __tmp_57 = Item::new_1({ 30 }); + &mut __tmp_57 } as *mut Item),) { - (__tmp_12,) => items.try_emplace(key, || Item::move_from({ __tmp_12 })), + (__tmp_56,) => items.try_emplace(key, || Item::move_from({ __tmp_56 })), + } + }; + match ( + { + ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (1)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) + && (!(temporary_hit.1))) as i32) + }, + &mut (ok), + ) { + (__tmp_58, __tmp_59) => { + (*__tmp_59) = (((*__tmp_59) as i32) & (__tmp_58 as i32)) != 0; } }; - ok = ((ok as i32) - & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (1)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) - && (!(temporary_hit.1))) as i32)) - != 0; key.prefix_inc(); key.prefix_inc(); key.prefix_inc(); let mut temporary_new: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { - let mut __tmp_15: Item; + let mut __tmp_61: Item; match (({ - __tmp_15 = Item::new_1({ 40 }); - &mut __tmp_15 + __tmp_61 = Item::new_1({ 40 }); + &mut __tmp_61 } as *mut Item),) { - (__tmp_14,) => items.try_emplace(key, || Item::move_from({ __tmp_14 })), + (__tmp_60,) => items.try_emplace(key, || Item::move_from({ __tmp_60 })), + } + }; + match ( + { + ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (2)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (1))) + && (temporary_new.1)) as i32) + }, + &mut (ok), + ) { + (__tmp_62, __tmp_63) => { + (*__tmp_63) = (((*__tmp_63) as i32) & (__tmp_62 as i32)) != 0; + } + }; + match ( + { ((((*temporary_new.0.iter_deref()).1.value) == (40)) as i32) }, + &mut (ok), + ) { + (__tmp_64, __tmp_65) => { + (*__tmp_65) = (((*__tmp_65) as i32) & (__tmp_64 as i32)) != 0; } }; - ok = ((ok as i32) - & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (2)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (1))) - && (temporary_new.1)) as i32)) - != 0; - ok = ((ok as i32) & ((((*temporary_new.0.iter_deref()).1.value) == (40)) as i32)) != 0; (unsafe { libc::printf( c"%d %d %d %d %d\n".as_ptr() as *const libc::c_char, diff --git a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs index 1613225695..99593155e6 100644 --- a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs +++ b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs @@ -20,9 +20,11 @@ impl Item { } pub unsafe fn new_2(counter: *mut i32, mut amount: i32) -> Self { let mut this = Self { - value: { - (*counter) += amount; - (*counter) + value: match ({ amount }, &mut (*counter)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as i32) + (__tmp_0 as i32)) as i32; + (*__tmp_1).clone() + } }, }; (*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)).prefix_inc(); @@ -161,17 +163,17 @@ pub static mut global_temporary_14: std::cell::LazyCell<( bool, )> = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_1: Temporary; + let mut __tmp_3: Temporary; match ((&mut (*{ - __tmp_1 = (unsafe { make_temporary_5() }); - &mut __tmp_1 + __tmp_3 = (unsafe { make_temporary_5() }); + &mut __tmp_3 }) .n as *mut i32),) { - (__tmp_0,) => (*std::cell::LazyCell::force_mut(&mut *&raw mut global_values_7)) + (__tmp_2,) => (*std::cell::LazyCell::force_mut(&mut *&raw mut global_values_7)) .try_emplace( (*std::cell::LazyCell::force_mut(&mut *&raw mut global_key_8)), - || (*__tmp_0), + || (*__tmp_2), ), } } @@ -183,22 +185,22 @@ pub static mut global_conditional_15: std::cell::LazyCell<( match ( (if (*std::cell::LazyCell::force_mut(&mut *&raw mut global_choose_13)) { ({ - let __tmp_3 = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_a_11)); - (*__tmp_3).prefix_inc(); - __tmp_3 + let __tmp_5 = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_a_11)); + (*__tmp_5).prefix_inc(); + __tmp_5 } as *mut i32) } else { ({ - let __tmp_4 = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_b_12)); - (*__tmp_4).prefix_inc(); - __tmp_4 + let __tmp_6 = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_b_12)); + (*__tmp_6).prefix_inc(); + __tmp_6 } as *mut i32) } as *mut i32), ) { - (__tmp_2,) => (*std::cell::LazyCell::force_mut(&mut *&raw mut global_values_7)) + (__tmp_4,) => (*std::cell::LazyCell::force_mut(&mut *&raw mut global_values_7)) .try_emplace( (*std::cell::LazyCell::force_mut(&mut *&raw mut conditional_key_9)), - || (*__tmp_2), + || (*__tmp_4), ), } }); @@ -207,10 +209,10 @@ pub static mut global_owned_16: std::cell::LazyCell<( bool, )> = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_6: Option>; + let mut __tmp_8: Option>; match ((&mut (*(*{ - __tmp_6 = Some(Box::new(Temporary::new())); - &mut __tmp_6 + __tmp_8 = Some(Box::new(Temporary::new())); + &mut __tmp_8 }) .as_deref() .map_or(::std::ptr::null_mut(), |v| { @@ -218,10 +220,10 @@ pub static mut global_owned_16: std::cell::LazyCell<( })) .n as *mut i32),) { - (__tmp_5,) => (*std::cell::LazyCell::force_mut(&mut *&raw mut global_values_7)) + (__tmp_7,) => (*std::cell::LazyCell::force_mut(&mut *&raw mut global_values_7)) .try_emplace( (*std::cell::LazyCell::force_mut(&mut *&raw mut owned_key_10)), - || (*__tmp_5), + || (*__tmp_7), ), } } @@ -264,12 +266,12 @@ unsafe fn main_0() -> i32 { let mut hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match ( ((unsafe { receiver_2(&mut m) }) as *mut UnsafeMap), ({ - let __tmp_9 = (unsafe { place_3(&mut counter) }); - (*__tmp_9).prefix_inc(); - __tmp_9 + let __tmp_11 = (unsafe { place_3(&mut counter) }); + (*__tmp_11).prefix_inc(); + __tmp_11 } as *mut i32), ) { - (__tmp_7, __tmp_8) => (*__tmp_7).try_emplace(key, || Item::new_2({ __tmp_8 }, { 2 })), + (__tmp_9, __tmp_10) => (*__tmp_9).try_emplace(key, || Item::new_2({ __tmp_10 }, { 2 })), }; assert!( ((((counter) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) == (0))) @@ -278,12 +280,12 @@ unsafe fn main_0() -> i32 { ); key.prefix_inc(); let mut inserted: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (({ - let __tmp_11 = &mut counter; - (*__tmp_11).prefix_inc(); - __tmp_11 + let __tmp_13 = &mut counter; + (*__tmp_13).prefix_inc(); + __tmp_13 } as *mut i32),) { - (__tmp_10,) => m.try_emplace(key, || Item::new_2({ __tmp_10 }, { 2 })), + (__tmp_12,) => m.try_emplace(key, || Item::new_2({ __tmp_12 }, { 2 })), }; assert!( (((counter) == (7)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) == (1))) @@ -291,13 +293,13 @@ unsafe fn main_0() -> i32 { ); let mut assigned: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match ((match ({ 9 }, (&mut counter as *mut i32)) { - (__tmp_14, __tmp_13) => { - __tmp_13.write(__tmp_14); - __tmp_13 + (__tmp_16, __tmp_15) => { + __tmp_15.write(__tmp_16); + __tmp_15 } } as *mut i32),) { - (__tmp_12,) => m.try_emplace(key, || Item::new_2({ __tmp_12 }, { 2 })), + (__tmp_14,) => m.try_emplace(key, || Item::new_2({ __tmp_14 }, { 2 })), }; assert!( (((counter) == (9)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) == (1))) @@ -306,13 +308,13 @@ unsafe fn main_0() -> i32 { key.prefix_inc(); let mut compound: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match ((match ({ 4 }, (&mut counter as *mut i32)) { - (__tmp_17, __tmp_16) => { - __tmp_16.write((((*__tmp_16) as i32) + (__tmp_17 as i32)) as i32); - __tmp_16 + (__tmp_19, __tmp_18) => { + __tmp_18.write((((*__tmp_18) as i32) + (__tmp_19 as i32)) as i32); + __tmp_18 } } as *mut i32),) { - (__tmp_15,) => m.try_emplace(key, || Item::new_2({ __tmp_15 }, { 2 })), + (__tmp_17,) => m.try_emplace(key, || Item::new_2({ __tmp_17 }, { 2 })), }; assert!( (((counter) == (15)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) == (2))) @@ -326,12 +328,12 @@ unsafe fn main_0() -> i32 { let mut index: i32 = 0; key.prefix_inc(); match (({ - let __tmp_19 = &mut array[(index.postfix_inc()) as usize]; - (*__tmp_19).prefix_inc(); - __tmp_19 + let __tmp_21 = &mut array[(index.postfix_inc()) as usize]; + (*__tmp_21).prefix_inc(); + __tmp_21 } as *mut i32),) { - (__tmp_18,) => m.try_emplace(key, || Item::new_2({ __tmp_18 }, { 3 })), + (__tmp_20,) => m.try_emplace(key, || Item::new_2({ __tmp_20 }, { 3 })), }; assert!( (((index) == (1)) && ((array[(0) as usize]) == (4))) @@ -342,26 +344,26 @@ unsafe fn main_0() -> i32 { { 5 }, (&mut array[(index.postfix_inc()) as usize] as *mut i32), ) { - (__tmp_22, __tmp_21) => { - __tmp_21.write(__tmp_22); - __tmp_21 + (__tmp_24, __tmp_23) => { + __tmp_23.write(__tmp_24); + __tmp_23 } } as *mut i32),) { - (__tmp_20,) => m.try_emplace(key, || Item::new_2({ __tmp_20 }, { 3 })), + (__tmp_22,) => m.try_emplace(key, || Item::new_2({ __tmp_22 }, { 3 })), }; assert!( (((index) == (2)) && ((array[(1) as usize]) == (8))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) == (4)) ); match ((match ({ ((counter) + (1)) }, (&mut counter as *mut i32)) { - (__tmp_25, __tmp_24) => { - __tmp_24.write(__tmp_25); - __tmp_24 + (__tmp_27, __tmp_26) => { + __tmp_26.write(__tmp_27); + __tmp_26 } } as *mut i32),) { - (__tmp_23,) => m.try_emplace(key, || Item::new_2({ __tmp_23 }, { 3 })), + (__tmp_25,) => m.try_emplace(key, || Item::new_2({ __tmp_25 }, { 3 })), }; assert!( ((counter) == (16)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) == (4)) @@ -371,19 +373,19 @@ unsafe fn main_0() -> i32 { let mut choose: bool = false; match ((if choose { ({ - let __tmp_27 = &mut a; - (*__tmp_27).prefix_inc(); - __tmp_27 + let __tmp_29 = &mut a; + (*__tmp_29).prefix_inc(); + __tmp_29 } as *mut i32) } else { ({ - let __tmp_28 = &mut b; - (*__tmp_28).prefix_inc(); - __tmp_28 + let __tmp_30 = &mut b; + (*__tmp_30).prefix_inc(); + __tmp_30 } as *mut i32) } as *mut i32),) { - (__tmp_26,) => m.try_emplace(key, || Item::new_2({ __tmp_26 }, { 3 })), + (__tmp_28,) => m.try_emplace(key, || Item::new_2({ __tmp_28 }, { 3 })), }; assert!( (((a) == (0)) && ((b) == (1))) @@ -392,19 +394,19 @@ unsafe fn main_0() -> i32 { choose = true; match ((if choose { ({ - let __tmp_30 = &mut a; - (*__tmp_30).prefix_inc(); - __tmp_30 + let __tmp_32 = &mut a; + (*__tmp_32).prefix_inc(); + __tmp_32 } as *mut i32) } else { ({ - let __tmp_31 = &mut b; - (*__tmp_31).prefix_inc(); - __tmp_31 + let __tmp_33 = &mut b; + (*__tmp_33).prefix_inc(); + __tmp_33 } as *mut i32) } as *mut i32),) { - (__tmp_29,) => m.try_emplace(key, || Item::new_2({ __tmp_29 }, { 3 })), + (__tmp_31,) => m.try_emplace(key, || Item::new_2({ __tmp_31 }, { 3 })), }; assert!( (((a) == (1)) && ((b) == (1))) @@ -415,7 +417,7 @@ unsafe fn main_0() -> i32 { &mut counter } as *mut i32),) { - (__tmp_32,) => m.try_emplace(key, || Item::new_2({ __tmp_32 }, { 3 })), + (__tmp_34,) => m.try_emplace(key, || Item::new_2({ __tmp_34 }, { 3 })), }; assert!( ((counter) == (17)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) == (4)) @@ -424,13 +426,13 @@ unsafe fn main_0() -> i32 { let mut n: u32 = !0_u32; let mut wrapped: (UnsafeBidirectionalIterator<(i32, u32)>, bool) = match ((match ({ 1_u32 }, (&mut n as *mut u32)) { - (__tmp_35, __tmp_34) => { - __tmp_34.write((((*__tmp_34) as u32).wrapping_add((__tmp_35 as u32))) as u32); - __tmp_34 + (__tmp_37, __tmp_36) => { + __tmp_36.write((((*__tmp_36) as u32).wrapping_add((__tmp_37 as u32))) as u32); + __tmp_36 } } as *mut u32),) { - (__tmp_33,) => unsigned_map.try_emplace(key, || (*__tmp_33)), + (__tmp_35,) => unsigned_map.try_emplace(key, || (*__tmp_35)), }; assert!(((n) == (0_u32)) && (((*wrapped.0.iter_deref()).1) == (0_u32))); let mut bytes: [u8; 2] = [255_u8, 0_u8]; @@ -440,13 +442,13 @@ unsafe fn main_0() -> i32 { { 2 }, (&mut bytes[(index.postfix_inc()) as usize] as *mut u8), ) { - (__tmp_38, __tmp_37) => { - __tmp_37.write((((*__tmp_37) as i32) + (__tmp_38 as i32)) as u8); - __tmp_37 + (__tmp_40, __tmp_39) => { + __tmp_39.write((((*__tmp_39) as i32) + (__tmp_40 as i32)) as u8); + __tmp_39 } } as *mut u8),) { - (__tmp_36,) => unsigned_map.try_emplace(key, || ((*__tmp_36) as u32)), + (__tmp_38,) => unsigned_map.try_emplace(key, || ((*__tmp_38) as u32)), }; assert!( (((index) == (1)) && ((bytes[(0) as usize] as i32) == (1))) @@ -458,38 +460,38 @@ unsafe fn main_0() -> i32 { let mut erased: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ changed.erase_key(&key); { - let __tmp_40 = &mut effects; - (*__tmp_40).prefix_inc(); - __tmp_40 + let __tmp_42 = &mut effects; + (*__tmp_42).prefix_inc(); + __tmp_42 } } as *mut i32),) { - (__tmp_39,) => changed.try_emplace(key, || (*__tmp_39)), + (__tmp_41,) => changed.try_emplace(key, || (*__tmp_41)), }; assert!((((effects) == (1)) && (erased.1)) && (((*erased.0.iter_deref()).1) == (1))); let mut updated: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ (*changed.subscript(&key, || 0_i32)).prefix_inc(); { - let __tmp_42 = &mut effects; - (*__tmp_42).prefix_inc(); - __tmp_42 + let __tmp_44 = &mut effects; + (*__tmp_44).prefix_inc(); + __tmp_44 } } as *mut i32),) { - (__tmp_41,) => changed.try_emplace(key, || (*__tmp_41)), + (__tmp_43,) => changed.try_emplace(key, || (*__tmp_43)), }; assert!((((effects) == (2)) && (!(updated.1))) && (((*updated.0.iter_deref()).1) == (2))); let mut pointers: UnsafeMap = UnsafeMap::new(); let mut p: *mut i32 = array.as_mut_ptr(); let mut pointer: (UnsafeBidirectionalIterator<(i32, *mut i32)>, bool) = match ((match ({ 1 }, (&mut p as *mut *mut i32)) { - (__tmp_45, __tmp_44) => { - __tmp_44.write((*__tmp_44).offset((__tmp_45 as isize))); - __tmp_44 + (__tmp_47, __tmp_46) => { + __tmp_46.write((*__tmp_46).offset((__tmp_47 as isize))); + __tmp_46 } } as *mut *mut i32),) { - (__tmp_43,) => pointers.try_emplace(key, || (*__tmp_43)), + (__tmp_45,) => pointers.try_emplace(key, || (*__tmp_45)), }; assert!( ((p) == (array.as_mut_ptr().offset((1) as isize))) @@ -516,60 +518,60 @@ unsafe fn main_0() -> i32 { let mut assigned: i32 = 0; let mut nested: i32 = 0; let mut r0: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ - let __tmp_47 = &mut moved; - (*__tmp_47).prefix_inc(); - __tmp_47 + let __tmp_49 = &mut moved; + (*__tmp_49).prefix_inc(); + __tmp_49 } as *mut i32),) { - (__tmp_46,) => values.try_emplace(keys[(0) as usize], || (*__tmp_46)), + (__tmp_48,) => values.try_emplace(keys[(0) as usize], || (*__tmp_48)), }; let mut r1: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ - let __tmp_49 = &mut forwarded; - (*__tmp_49).prefix_inc(); - __tmp_49 + let __tmp_51 = &mut forwarded; + (*__tmp_51).prefix_inc(); + __tmp_51 } as *mut i32),) { - (__tmp_48,) => values.try_emplace(keys[(1) as usize], || (*__tmp_48)), + (__tmp_50,) => values.try_emplace(keys[(1) as usize], || (*__tmp_50)), }; let mut r2: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ - let __tmp_51 = &mut xvalue; - (*__tmp_51).prefix_inc(); - __tmp_51 + let __tmp_53 = &mut xvalue; + (*__tmp_53).prefix_inc(); + __tmp_53 } as *mut i32),) { - (__tmp_50,) => values.try_emplace(keys[(2) as usize], || (*__tmp_50)), + (__tmp_52,) => values.try_emplace(keys[(2) as usize], || (*__tmp_52)), }; let mut r3: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ - let __tmp_53 = &mut lvalue; - (*__tmp_53).prefix_inc(); - __tmp_53 + let __tmp_55 = &mut lvalue; + (*__tmp_55).prefix_inc(); + __tmp_55 } as *mut i32),) { - (__tmp_52,) => values.try_emplace(keys[(3) as usize], || (*__tmp_52)), + (__tmp_54,) => values.try_emplace(keys[(3) as usize], || (*__tmp_54)), }; let mut r4: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match ((match ({ 5 }, (&mut assigned as *mut i32)) { - (__tmp_56, __tmp_55) => { - __tmp_55.write(__tmp_56); - __tmp_55 + (__tmp_58, __tmp_57) => { + __tmp_57.write(__tmp_58); + __tmp_57 } } as *mut i32),) { - (__tmp_54,) => values.try_emplace(keys[(4) as usize], || (*__tmp_54)), + (__tmp_56,) => values.try_emplace(keys[(4) as usize], || (*__tmp_56)), }; let mut r5: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match ((match ({ 1 }, (&mut nested as *mut i32)) { - (__tmp_59, __tmp_58) => { - __tmp_58.write((((*__tmp_58) as i32) + (__tmp_59 as i32)) as i32); - __tmp_58 + (__tmp_61, __tmp_60) => { + __tmp_60.write((((*__tmp_60) as i32) + (__tmp_61 as i32)) as i32); + __tmp_60 } } as *mut i32),) { - (__tmp_57,) => values.try_emplace(keys[(5) as usize], || (*__tmp_57)), + (__tmp_59,) => values.try_emplace(keys[(5) as usize], || (*__tmp_59)), }; assert!( ((((((moved) == (1)) && ((forwarded) == (1))) && ((xvalue) == (1))) @@ -630,66 +632,66 @@ unsafe fn main_0() -> i32 { let mut prefix: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match ((if (choose != 0) { ({ - let __tmp_61 = &mut a; - (*__tmp_61).prefix_inc(); - __tmp_61 + let __tmp_63 = &mut a; + (*__tmp_63).prefix_inc(); + __tmp_63 } as *mut i32) } else { ({ - let __tmp_62 = &mut b; - (*__tmp_62).prefix_inc(); - __tmp_62 + let __tmp_64 = &mut b; + (*__tmp_64).prefix_inc(); + __tmp_64 } as *mut i32) } as *mut i32),) { - (__tmp_60,) => selected.try_emplace(keys[(0) as usize], || { - Item::new_2({ __tmp_60 }, { 2 }) + (__tmp_62,) => selected.try_emplace(keys[(0) as usize], || { + Item::new_2({ __tmp_62 }, { 2 }) }), }; let mut assignment: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match ((if (choose != 0) { ((match ({ 5 }, (&mut c as *mut i32)) { - (__tmp_65, __tmp_64) => { - __tmp_64.write(__tmp_65); - __tmp_64 + (__tmp_67, __tmp_66) => { + __tmp_66.write(__tmp_67); + __tmp_66 } }) as *mut i32) } else { ((match ({ 6 }, (&mut d as *mut i32)) { - (__tmp_67, __tmp_66) => { - __tmp_66.write(__tmp_67); - __tmp_66 + (__tmp_69, __tmp_68) => { + __tmp_68.write(__tmp_69); + __tmp_68 } }) as *mut i32) } as *mut i32),) { - (__tmp_63,) => selected.try_emplace(keys[(1) as usize], || { - Item::new_2({ __tmp_63 }, { 2 }) + (__tmp_65,) => selected.try_emplace(keys[(1) as usize], || { + Item::new_2({ __tmp_65 }, { 2 }) }), }; let mut compound: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match ((if (choose != 0) { ((match ({ 1 }, (&mut e as *mut i32)) { - (__tmp_70, __tmp_69) => { - __tmp_69.write( - (((*__tmp_69) as i32) + (__tmp_70 as i32)) as i32, + (__tmp_72, __tmp_71) => { + __tmp_71.write( + (((*__tmp_71) as i32) + (__tmp_72 as i32)) as i32, ); - __tmp_69 + __tmp_71 } }) as *mut i32) } else { ((match ({ 2 }, (&mut f as *mut i32)) { - (__tmp_72, __tmp_71) => { - __tmp_71.write( - (((*__tmp_71) as i32) + (__tmp_72 as i32)) as i32, + (__tmp_74, __tmp_73) => { + __tmp_73.write( + (((*__tmp_73) as i32) + (__tmp_74 as i32)) as i32, ); - __tmp_71 + __tmp_73 } }) as *mut i32) } as *mut i32),) { - (__tmp_68,) => selected.try_emplace(keys[(2) as usize], || { - Item::new_2({ __tmp_68 }, { 2 }) + (__tmp_70,) => selected.try_emplace(keys[(2) as usize], || { + Item::new_2({ __tmp_70 }, { 2 }) }), }; assert!( @@ -771,37 +773,37 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); let mut index: i32 = 0; let mut member: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_74: Temporary; + let mut __tmp_76: Temporary; match ((&mut (*{ - __tmp_74 = (unsafe { make_temporary_5() }); - &mut __tmp_74 + __tmp_76 = (unsafe { make_temporary_5() }); + &mut __tmp_76 }) .n as *mut i32),) { - (__tmp_73,) => values.try_emplace(keys[(0) as usize], || (*__tmp_73)), + (__tmp_75,) => values.try_emplace(keys[(0) as usize], || (*__tmp_75)), } }; let mut nested: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_76: Nested; + let mut __tmp_78: Nested; match ((&mut (*&mut (*{ - __tmp_76 = (unsafe { make_nested_6() }); - &mut __tmp_76 + __tmp_78 = (unsafe { make_nested_6() }); + &mut __tmp_78 }) .inner) .n as *mut i32),) { - (__tmp_75,) => values.try_emplace(keys[(1) as usize], || (*__tmp_75)), + (__tmp_77,) => values.try_emplace(keys[(1) as usize], || (*__tmp_77)), } }; let mut element: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_78: Temporary; + let mut __tmp_80: Temporary; match ((&mut (*{ - __tmp_78 = (unsafe { make_temporary_5() }); - &mut __tmp_78 + __tmp_80 = (unsafe { make_temporary_5() }); + &mut __tmp_80 }) .data[(index.postfix_inc()) as usize] as *mut i32),) { - (__tmp_77,) => values.try_emplace(keys[(2) as usize], || (*__tmp_77)), + (__tmp_79,) => values.try_emplace(keys[(2) as usize], || (*__tmp_79)), } }; assert!( @@ -833,28 +835,28 @@ unsafe fn main_0() -> i32 { index = 0; let mut value: i32 = 0; { - let mut __tmp_80: Nested; - let mut __tmp_81: Temporary; + let mut __tmp_82: Nested; + let mut __tmp_83: Temporary; { match ((if (choose != 0) { (&mut (*&mut (*{ - __tmp_80 = (unsafe { make_nested_6() }); - &mut __tmp_80 + __tmp_82 = (unsafe { make_nested_6() }); + &mut __tmp_82 }) .inner) .n as *mut i32) } else { (&mut (*{ - __tmp_81 = (unsafe { make_temporary_5() }); - &mut __tmp_81 + __tmp_83 = (unsafe { make_temporary_5() }); + &mut __tmp_83 }) .data [(index.postfix_inc()) as usize] as *mut i32) } as *mut i32),) { - (__tmp_79,) => references - .try_emplace(key, || Held::new_1({ __tmp_79 })), + (__tmp_81,) => references + .try_emplace(key, || Held::new_1({ __tmp_81 })), }; value = (*(*references.subscript(&key, || ::default())).ptr) @@ -882,28 +884,28 @@ unsafe fn main_0() -> i32 { before = (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); { - let mut __tmp_83: Nested; - let mut __tmp_84: Temporary; + let mut __tmp_85: Nested; + let mut __tmp_86: Temporary; { match ((if (choose != 0) { (&mut (*&mut (*{ - __tmp_83 = (unsafe { make_nested_6() }); - &mut __tmp_83 + __tmp_85 = (unsafe { make_nested_6() }); + &mut __tmp_85 }) .inner) .data as *mut [i32; 2]) } else { (&mut (*{ - __tmp_84 = (unsafe { make_temporary_5() }); - &mut __tmp_84 + __tmp_86 = (unsafe { make_temporary_5() }); + &mut __tmp_86 }) .data as *mut [i32; 2]) } as *mut [i32; 2]),) { - (__tmp_82,) => arrays - .try_emplace(key, || Held::new_3({ __tmp_82 }, { 0 })), + (__tmp_84,) => arrays + .try_emplace(key, || Held::new_3({ __tmp_84 }, { 0 })), }; value = (*(*arrays.subscript(&key, || ::default())) .ptr @@ -942,10 +944,10 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); let mut index: i32 = 0; let mut arrow: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_86: Option>; + let mut __tmp_88: Option>; match ((&mut (*(*{ - __tmp_86 = Some(Box::new(Temporary::new())); - &mut __tmp_86 + __tmp_88 = Some(Box::new(Temporary::new())); + &mut __tmp_88 }) .as_deref() .map_or(::std::ptr::null_mut(), |v| { @@ -953,14 +955,14 @@ unsafe fn main_0() -> i32 { })) .n as *mut i32),) { - (__tmp_85,) => values.try_emplace(keys[(0) as usize], || (*__tmp_85)), + (__tmp_87,) => values.try_emplace(keys[(0) as usize], || (*__tmp_87)), } }; let mut nested: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_88: Option>; + let mut __tmp_90: Option>; match ((&mut (*&mut (*(*{ - __tmp_88 = Some(Box::new(::default())); - &mut __tmp_88 + __tmp_90 = Some(Box::new(::default())); + &mut __tmp_90 }) .as_deref() .map_or(::std::ptr::null_mut(), |v| { @@ -969,14 +971,14 @@ unsafe fn main_0() -> i32 { .inner) .n as *mut i32),) { - (__tmp_87,) => values.try_emplace(keys[(1) as usize], || (*__tmp_87)), + (__tmp_89,) => values.try_emplace(keys[(1) as usize], || (*__tmp_89)), } }; let mut element: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_90: Option>; + let mut __tmp_92: Option>; match ((&mut (*(*{ - __tmp_90 = Some(Box::new(Temporary::new())); - &mut __tmp_90 + __tmp_92 = Some(Box::new(Temporary::new())); + &mut __tmp_92 }) .as_deref() .map_or(::std::ptr::null_mut(), |v| { @@ -984,27 +986,27 @@ unsafe fn main_0() -> i32 { })) .data[(index.postfix_inc()) as usize] as *mut i32),) { - (__tmp_89,) => values.try_emplace(keys[(2) as usize], || (*__tmp_89)), + (__tmp_91,) => values.try_emplace(keys[(2) as usize], || (*__tmp_91)), } }; let mut get: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_92: Option>; + let mut __tmp_94: Option>; match ((&mut (*(*{ - __tmp_92 = Some(Box::new(Temporary::new())); - &mut __tmp_92 + __tmp_94 = Some(Box::new(Temporary::new())); + &mut __tmp_94 }) .as_deref_mut() .map_or(::std::ptr::null_mut(), |v| v as *mut Temporary)) .n as *mut i32),) { - (__tmp_91,) => values.try_emplace(keys[(3) as usize], || (*__tmp_91)), + (__tmp_93,) => values.try_emplace(keys[(3) as usize], || (*__tmp_93)), } }; let mut deref: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_94: Option>; + let mut __tmp_96: Option>; match ((&mut (*((*{ - __tmp_94 = Some(Box::new(Temporary::new())); - &mut __tmp_94 + __tmp_96 = Some(Box::new(Temporary::new())); + &mut __tmp_96 }) .as_deref() .map_or(::std::ptr::null_mut(), |v| { @@ -1012,14 +1014,14 @@ unsafe fn main_0() -> i32 { }))) .n as *mut i32),) { - (__tmp_93,) => values.try_emplace(keys[(4) as usize], || (*__tmp_93)), + (__tmp_95,) => values.try_emplace(keys[(4) as usize], || (*__tmp_95)), } }; let mut indirect: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_96: Option>>>; + let mut __tmp_98: Option>>>; match ((&mut (*((*(*{ - __tmp_96 = Some(Box::new(Some(Box::new(Temporary::new())))); - &mut __tmp_96 + __tmp_98 = Some(Box::new(Some(Box::new(Temporary::new())))); + &mut __tmp_98 }) .as_deref() .map_or(::std::ptr::null_mut(), |v| { @@ -1031,7 +1033,7 @@ unsafe fn main_0() -> i32 { }))) .n as *mut i32),) { - (__tmp_95,) => values.try_emplace(keys[(5) as usize], || (*__tmp_95)), + (__tmp_97,) => values.try_emplace(keys[(5) as usize], || (*__tmp_97)), } }; assert!( @@ -1074,13 +1076,13 @@ unsafe fn main_0() -> i32 { index = 0; let mut value: i32 = 0; { - let mut __tmp_98: Option>; - let mut __tmp_99: Option>; + let mut __tmp_100: Option>; + let mut __tmp_101: Option>; { match ((if (choose != 0) { (&mut (*(*{ - __tmp_98 = Some(Box::new(Temporary::new())); - &mut __tmp_98 + __tmp_100 = Some(Box::new(Temporary::new())); + &mut __tmp_100 }) .as_deref() .map_or(::std::ptr::null_mut(), |v| { @@ -1089,8 +1091,8 @@ unsafe fn main_0() -> i32 { .n as *mut i32) } else { (&mut (*(*{ - __tmp_99 = Some(Box::new(Temporary::new())); - &mut __tmp_99 + __tmp_101 = Some(Box::new(Temporary::new())); + &mut __tmp_101 }) .as_deref() .map_or(::std::ptr::null_mut(), |v| { @@ -1101,8 +1103,8 @@ unsafe fn main_0() -> i32 { as *mut i32) } as *mut i32),) { - (__tmp_97,) => references - .try_emplace(key, || Held::new_1({ __tmp_97 })), + (__tmp_99,) => references + .try_emplace(key, || Held::new_1({ __tmp_99 })), }; value = (*(*references.subscript(&key, || ::default())).ptr) @@ -1124,19 +1126,19 @@ unsafe fn main_0() -> i32 { ); let mut owners: UnsafeMap = UnsafeMap::new(); { - let mut __tmp_101: Owner; + let mut __tmp_103: Owner; { match (((unsafe { Owner::value( &mut (*{ - __tmp_101 = Owner::new(); - &mut __tmp_101 + __tmp_103 = Owner::new(); + &mut __tmp_103 }), ) }) as *const i32),) { - (__tmp_100,) => { - owners.try_emplace(key, || Held::new_1({ __tmp_100 })) + (__tmp_102,) => { + owners.try_emplace(key, || Held::new_1({ __tmp_102 })) } }; value = (*(*owners.subscript(&key, || ::default())).ptr) @@ -1156,26 +1158,26 @@ unsafe fn main_0() -> i32 { UnsafeBidirectionalIterator<(i32, (Option>, i32))>, bool, ) = { - let mut __tmp_103: Option>; + let mut __tmp_105: Option>; match (({ - __tmp_103 = Some(Box::new(::default())); - &mut __tmp_103 + __tmp_105 = Some(Box::new(::default())); + &mut __tmp_105 } as *mut Option>),) { - (__tmp_102,) => move_only.try_emplace(key, || ((*__tmp_102).take(), 7)), + (__tmp_104,) => move_only.try_emplace(key, || ((*__tmp_104).take(), 7)), } }; let mut move_hit: ( UnsafeBidirectionalIterator<(i32, (Option>, i32))>, bool, ) = { - let mut __tmp_105: Option>; + let mut __tmp_107: Option>; match (({ - __tmp_105 = Some(Box::new(::default())); - &mut __tmp_105 + __tmp_107 = Some(Box::new(::default())); + &mut __tmp_107 } as *mut Option>),) { - (__tmp_104,) => move_only.try_emplace(key, || ((*__tmp_104).take(), 9)), + (__tmp_106,) => move_only.try_emplace(key, || ((*__tmp_106).take(), 9)), } }; assert!((move_new.1) && (!(move_hit.1))); @@ -1214,7 +1216,7 @@ unsafe fn main_0() -> i32 { } as *mut Vec),) { - (__tmp_106,) => strings.try_emplace(key, || std::mem::replace(&mut (*__tmp_106), vec![0])), + (__tmp_108,) => strings.try_emplace(key, || std::mem::replace(&mut (*__tmp_108), vec![0])), }; assert!( (((*std::cell::LazyCell::force_mut(&mut *&raw mut visits_1)) == (3)) && (!(string_hit.1))) @@ -1236,7 +1238,7 @@ unsafe fn main_0() -> i32 { } as *mut Vec),) { - (__tmp_107,) => strings.try_emplace(key, || std::mem::replace(&mut (*__tmp_107), vec![0])), + (__tmp_109,) => strings.try_emplace(key, || std::mem::replace(&mut (*__tmp_109), vec![0])), }; assert!( (((*std::cell::LazyCell::force_mut(&mut *&raw mut visits_1)) == (4)) && (string_new.1)) diff --git a/tests/unit/out/unsafe/operator_compound_assignment_free.rs b/tests/unit/out/unsafe/operator_compound_assignment_free.rs index ca88305817..3a72b07ec5 100644 --- a/tests/unit/out/unsafe/operator_compound_assignment_free.rs +++ b/tests/unit/out/unsafe/operator_compound_assignment_free.rs @@ -12,23 +12,43 @@ pub struct S { pub v: u32, } pub unsafe fn operator_add_assign_0(a: *mut S, b: *const S) -> *mut S { - (*a).v = ((*a).v).wrapping_add((*b).v); + match ({ (*b).v }, &mut ((*a).v)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; + } + }; return a; } pub unsafe fn operator_sub_assign_1(a: *mut S, b: *const S) -> *mut S { - (*a).v = ((*a).v).wrapping_sub((*b).v); + match ({ (*b).v }, &mut ((*a).v)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (((*__tmp_3) as u32).wrapping_sub((__tmp_2 as u32))) as u32; + } + }; return a; } pub unsafe fn operator_mul_assign_2(a: *mut S, b: *const S) -> *mut S { - (*a).v = ((*a).v).wrapping_mul((*b).v); + match ({ (*b).v }, &mut ((*a).v)) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = (((*__tmp_5) as u32).wrapping_mul((__tmp_4 as u32))) as u32; + } + }; return a; } pub unsafe fn operator_div_assign_3(a: *mut S, b: *const S) -> *mut S { - (*a).v = ((*a).v).wrapping_div((*b).v); + match ({ (*b).v }, &mut ((*a).v)) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as u32).wrapping_div((__tmp_6 as u32))) as u32; + } + }; return a; } pub unsafe fn operator_rem_assign_4(a: *mut S, b: *const S) -> *mut S { - (*a).v = ((*a).v).wrapping_rem((*b).v); + match ({ (*b).v }, &mut ((*a).v)) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as u32).wrapping_rem((__tmp_8 as u32))) as u32; + } + }; return a; } pub unsafe fn operator_bitand_assign_5(a: *mut S, b: *const S) -> *mut S { diff --git a/tests/unit/out/unsafe/operator_compound_assignment_member.rs b/tests/unit/out/unsafe/operator_compound_assignment_member.rs index d619d005f4..4d313eff40 100644 --- a/tests/unit/out/unsafe/operator_compound_assignment_member.rs +++ b/tests/unit/out/unsafe/operator_compound_assignment_member.rs @@ -17,23 +17,43 @@ impl S { return &mut (*(self as *mut S)); } pub unsafe fn operator_add_assign(&mut self, o: *const S) -> *mut S { - self.v = (self.v).wrapping_add((*o).v); + match ({ (*o).v }, &mut (self.v)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; + } + }; return &mut (*(self as *mut S)); } pub unsafe fn operator_sub_assign(&mut self, o: *const S) -> *mut S { - self.v = (self.v).wrapping_sub((*o).v); + match ({ (*o).v }, &mut (self.v)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (((*__tmp_3) as u32).wrapping_sub((__tmp_2 as u32))) as u32; + } + }; return &mut (*(self as *mut S)); } pub unsafe fn operator_mul_assign(&mut self, o: *const S) -> *mut S { - self.v = (self.v).wrapping_mul((*o).v); + match ({ (*o).v }, &mut (self.v)) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = (((*__tmp_5) as u32).wrapping_mul((__tmp_4 as u32))) as u32; + } + }; return &mut (*(self as *mut S)); } pub unsafe fn operator_div_assign(&mut self, o: *const S) -> *mut S { - self.v = (self.v).wrapping_div((*o).v); + match ({ (*o).v }, &mut (self.v)) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as u32).wrapping_div((__tmp_6 as u32))) as u32; + } + }; return &mut (*(self as *mut S)); } pub unsafe fn operator_rem_assign(&mut self, o: *const S) -> *mut S { - self.v = (self.v).wrapping_rem((*o).v); + match ({ (*o).v }, &mut (self.v)) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as u32).wrapping_rem((__tmp_8 as u32))) as u32; + } + }; return &mut (*(self as *mut S)); } pub unsafe fn operator_bitand_assign(&mut self, o: *const S) -> *mut S { diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index 957fb85233..7b8ce83d52 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -39,9 +39,21 @@ unsafe fn main_0() -> i32 { .wrapping_add((::std::mem::size_of::() as usize)))) ); let mut acc: usize = 100_usize; - acc = ((acc as u64).wrapping_add((::std::mem::size_of::() as u64))) as usize; - acc = (acc).wrapping_mul(2_usize); - acc = ((acc as u64).wrapping_sub(ul)) as usize; + match ({ ::std::mem::size_of::() }, &mut (acc)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as u64).wrapping_add((__tmp_0 as u64))) as usize; + } + }; + match ({ 2_usize }, &mut (acc)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (((*__tmp_3) as usize).wrapping_mul((__tmp_2 as usize))) as usize; + } + }; + match ({ ul }, &mut (acc)) { + (__tmp_4, __tmp_5) => { + (*__tmp_5) = (((*__tmp_5) as u64).wrapping_sub((__tmp_4 as u64))) as usize; + } + }; assert!( ((acc) == (((((100_usize).wrapping_add((::std::mem::size_of::() as usize))) as usize) @@ -64,18 +76,18 @@ unsafe fn main_0() -> i32 { let mut fr2: u64 = (unsafe { take_ulong_1((sz as u64)) }); assert!(((fr2) == (21_u64))); let mut lo: usize = (({ - let mut __tmp_0: u64 = (sz as u64); - let mut __tmp_1: u64 = (::std::mem::size_of::() as u64).wrapping_add(ul); + let mut __tmp_6: u64 = (sz as u64); + let mut __tmp_7: u64 = (::std::mem::size_of::() as u64).wrapping_add(ul); (*{ - let __a: *const _ = &mut __tmp_0; - let __b: *const _ = &mut __tmp_1; + let __a: *const _ = &mut __tmp_6; + let __b: *const _ = &mut __tmp_7; if *__b < *__a { __b } else { __a } }) }) as usize); let mut hi: usize = (({ - let mut __tmp_2: u64 = (::std::mem::size_of::() as u64).wrapping_add((sz as u64)); + let mut __tmp_8: u64 = (::std::mem::size_of::() as u64).wrapping_add((sz as u64)); (*{ - let __a: *const _ = &mut __tmp_2; + let __a: *const _ = &mut __tmp_8; let __b: *const _ = &mut ul; if *__a < *__b { __b } else { __a } }) @@ -83,11 +95,11 @@ unsafe fn main_0() -> i32 { assert!(((lo) == ((::std::mem::size_of::() as usize).wrapping_add(10_usize)))); assert!(((hi) == ((::std::mem::size_of::() as usize).wrapping_add(21_usize)))); let mut bound: usize = (({ - let mut __tmp_3: u64 = (sz as u64); - let mut __tmp_4: u64 = (4_usize as u64); + let mut __tmp_9: u64 = (sz as u64); + let mut __tmp_10: u64 = (4_usize as u64); (*{ - let __a: *const _ = &mut __tmp_3; - let __b: *const _ = &mut __tmp_4; + let __a: *const _ = &mut __tmp_9; + let __b: *const _ = &mut __tmp_10; if *__b < *__a { __b } else { __a } }) }) as usize); @@ -109,7 +121,12 @@ unsafe fn main_0() -> i32 { let mut i: usize = 0_usize; 'loop_: while ((i) < (count)) { 'for_body: { - total = (total).wrapping_add((data[(i)] as usize)); + match ({ (data[(i)] as usize) }, &mut (total)) { + (__tmp_11, __tmp_12) => { + (*__tmp_12) = + (((*__tmp_12) as usize).wrapping_add((__tmp_11 as usize))) as usize; + } + }; } i.postfix_inc(); } @@ -138,20 +155,20 @@ unsafe fn main_0() -> i32 { assert!(((sm) == (15_isize))); assert!(((sm) > (l as isize))); let mut smin: isize = (({ - let mut __tmp_5: i64 = (sd as i64); - let mut __tmp_6: i64 = (sm as i64); + let mut __tmp_13: i64 = (sd as i64); + let mut __tmp_14: i64 = (sm as i64); (*{ - let __a: *const _ = &mut __tmp_5; - let __b: *const _ = &mut __tmp_6; + let __a: *const _ = &mut __tmp_13; + let __b: *const _ = &mut __tmp_14; if *__b < *__a { __b } else { __a } }) }) as isize); let mut smax: isize = (({ - let mut __tmp_7: i64 = (sd as i64); - let mut __tmp_8: i64 = (sm as i64); + let mut __tmp_15: i64 = (sd as i64); + let mut __tmp_16: i64 = (sm as i64); (*{ - let __a: *const _ = &mut __tmp_7; - let __b: *const _ = &mut __tmp_8; + let __a: *const _ = &mut __tmp_15; + let __b: *const _ = &mut __tmp_16; if *__a < *__b { __b } else { __a } }) }) as isize); @@ -173,20 +190,20 @@ unsafe fn main_0() -> i32 { let mut mins: [usize; 4] = [ 0_usize, (({ - let mut __tmp_9: u64 = 1_u64; - let mut __tmp_10: u64 = (mx as u64); + let mut __tmp_17: u64 = 1_u64; + let mut __tmp_18: u64 = (mx as u64); (*{ - let __a: *const _ = &mut __tmp_9; - let __b: *const _ = &mut __tmp_10; + let __a: *const _ = &mut __tmp_17; + let __b: *const _ = &mut __tmp_18; if *__b < *__a { __b } else { __a } }) }) as usize), (({ - let mut __tmp_11: u64 = (mx as u64); - let mut __tmp_12: u64 = ((mx).wrapping_sub(3_usize) as u64); + let mut __tmp_19: u64 = (mx as u64); + let mut __tmp_20: u64 = ((mx).wrapping_sub(3_usize) as u64); (*{ - let __a: *const _ = &mut __tmp_11; - let __b: *const _ = &mut __tmp_12; + let __a: *const _ = &mut __tmp_19; + let __b: *const _ = &mut __tmp_20; if *__b < *__a { __b } else { __a } }) }) as usize), diff --git a/tests/unit/out/unsafe/size_t_template_param.rs b/tests/unit/out/unsafe/size_t_template_param.rs index f23e80672e..4d71c23736 100644 --- a/tests/unit/out/unsafe/size_t_template_param.rs +++ b/tests/unit/out/unsafe/size_t_template_param.rs @@ -7,7 +7,11 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn array_ref_0(a: *mut [u64; 3]) -> u64 { - (*a)[(0) as usize] = ((*a)[(0) as usize]).wrapping_add(1_u64); + match ({ 1_u64 }, &mut ((*a)[(0) as usize])) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as u64).wrapping_add((__tmp_0 as u64))) as u64; + } + }; return (*a)[((3_u64 as u64).wrapping_sub(1_u64)) as usize]; } #[repr(C)] diff --git a/tests/unit/out/unsafe/swap_map_no_copy.rs b/tests/unit/out/unsafe/swap_map_no_copy.rs index 11750e8377..4460eb7873 100644 --- a/tests/unit/out/unsafe/swap_map_no_copy.rs +++ b/tests/unit/out/unsafe/swap_map_no_copy.rs @@ -330,12 +330,24 @@ pub unsafe fn swapped_once_6() -> bool { let mut ok: bool = (((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (1)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_4)) == (2))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moved_dtors_5)) == (1)); - (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_4)) = { - (*std::cell::LazyCell::force_mut(&mut *&raw mut moved_dtors_5)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut moved_dtors_5)) - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_4)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) = match ( + { + match ( + { 0 }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut moved_dtors_5)), + ) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_4)), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } }; return ok; } diff --git a/tests/unit/out/unsafe/switch_on_assignment.rs b/tests/unit/out/unsafe/switch_on_assignment.rs index 9aaca88206..8f5d59b888 100644 --- a/tests/unit/out/unsafe/switch_on_assignment.rs +++ b/tests/unit/out/unsafe/switch_on_assignment.rs @@ -11,9 +11,11 @@ pub unsafe fn switch_on_assignment_0(mut x: i32) -> i32 { let mut r: i32 = 0; 'switch: { match { - { - y = ((x) + (1)); - y + match ({ ((x) + (1)) }, &mut (y)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } } } { __v if __v == 1 => { diff --git a/tests/unit/out/unsafe/va_arg_concat.rs b/tests/unit/out/unsafe/va_arg_concat.rs index dc98f83d09..3d5ba99299 100644 --- a/tests/unit/out/unsafe/va_arg_concat.rs +++ b/tests/unit/out/unsafe/va_arg_concat.rs @@ -11,9 +11,11 @@ pub unsafe fn sum_ints_0(mut first: i32, __args: Box<[VaArg]>) -> i32 { let mut total: i32 = first; args = __args.as_ptr(); let mut val: i32 = 0_i32; - 'loop_: while (({ - val = args.arg::(); - val + 'loop_: while ((match ({ args.arg::() }, &mut (val)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } }) != (0)) { total += val; diff --git a/tests/unit/out/unsafe/va_arg_two_passes.rs b/tests/unit/out/unsafe/va_arg_two_passes.rs index 67ae4375b1..29feeb5f95 100644 --- a/tests/unit/out/unsafe/va_arg_two_passes.rs +++ b/tests/unit/out/unsafe/va_arg_two_passes.rs @@ -12,17 +12,21 @@ pub unsafe fn sum_then_product_0(mut first: i32, __args: Box<[VaArg]>) -> i32 { let mut product: i32 = first; ap = __args.as_ptr(); let mut val: i32 = 0_i32; - 'loop_: while (({ - val = ap.arg::(); - val + 'loop_: while ((match ({ ap.arg::() }, &mut (val)) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = __tmp_0; + (*__tmp_1).clone() + } }) != (0)) { sum += val; } ap = __args.as_ptr(); - 'loop_: while (({ - val = ap.arg::(); - val + 'loop_: while ((match ({ ap.arg::() }, &mut (val)) { + (__tmp_2, __tmp_3) => { + (*__tmp_3) = __tmp_2; + (*__tmp_3).clone() + } }) != (0)) { product *= val; diff --git a/tests/unit/out/unsafe/vector_subscript_borrow.rs b/tests/unit/out/unsafe/vector_subscript_borrow.rs index 34ffb4636b..2642c116a0 100644 --- a/tests/unit/out/unsafe/vector_subscript_borrow.rs +++ b/tests/unit/out/unsafe/vector_subscript_borrow.rs @@ -29,7 +29,11 @@ unsafe fn main_0() -> i32 { i.prefix_inc(); } } - items[(1_usize)] = (items[(1_usize)]).wrapping_add(5_u32); + match ({ 5_u32 }, &mut (items[(1_usize)])) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; + } + }; items[(2_usize)].postfix_inc(); assert!( (((items[(0_usize)]) == (0_u32)) && ((items[(1_usize)]) == (7_u32))) From a45b8de2848ff93cfc01837772ca445cbf76368b Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Wed, 25 Nov 2026 20:25:05 +0000 Subject: [PATCH 02/25] Keep compact lowering for stable assignments Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 60 +- cpp2rust/converter/converter.h | 8 +- .../converter/models/converter_refcount.cpp | 47 +- .../converter/models/converter_refcount.h | 2 + .../out/refcount/p14-class-in-two-files.rs | 11 +- .../out/unsafe/p14-class-in-two-files.rs | 11 +- .../p15-class-template-static-member.rs | 11 +- .../p15-class-template-static-member.rs | 11 +- .../out/refcount/p15-function-template.rs | 11 +- .../out/unsafe/p15-function-template.rs | 11 +- .../out/refcount/p15-inline-function.rs | 11 +- .../out/unsafe/p15-inline-function.rs | 11 +- .../out/refcount/p15-inline-variable.rs | 11 +- .../out/unsafe/p15-inline-variable.rs | 11 +- .../p16-default-argument-lambda-in-class.rs | 11 +- .../p16-default-argument-lambda-in-class.rs | 11 +- .../refcount/p16-lambda-in-inline-function.rs | 11 +- .../unsafe/p16-lambda-in-inline-function.rs | 11 +- .../out/refcount/basic.scope.block.rs | 11 +- .../out/unsafe/basic.scope.block.rs | 11 +- tests/std/basic/out/refcount/basic.def.odr.rs | 11 +- tests/std/basic/out/unsafe/basic.def.odr.rs | 11 +- .../stmt.select/out/refcount/stmt.if.rs | 11 +- .../stmt.select/out/refcount/stmt.switch.rs | 11 +- .../stmt.select/out/unsafe/stmt.if.rs | 11 +- .../stmt.select/out/unsafe/stmt.switch.rs | 11 +- tests/unit/assign_as_value.c | 6 + tests/unit/assignment_single_eval.cpp | 40 ++ tests/unit/out/refcount/assign_as_value.rs | 42 +- tests/unit/out/refcount/assign_rhs_first.rs | 8 +- .../out/refcount/assignment_single_eval.rs | 364 +++++++++--- .../out/refcount/compound_assign_paren.rs | 58 +- .../unit/out/refcount/copy_move_defaulted.rs | 12 +- tests/unit/out/refcount/destructor.rs | 28 +- tests/unit/out/refcount/expr_as_bool_c.rs | 40 +- tests/unit/out/refcount/expr_as_bool_cpp.rs | 40 +- .../field_pointers_malloced_struct.rs | 8 +- tests/unit/out/refcount/fn_ptr.rs | 12 +- .../refcount/immutable_unsigned_arithmetic.rs | 8 +- tests/unit/out/refcount/inet_pton_ntop.rs | 87 ++- .../out/refcount/inline_container_fields.rs | 8 +- tests/unit/out/refcount/lambda_generic.rs | 8 +- .../refcount/lambda_generic_explicit_args.rs | 42 +- tests/unit/out/refcount/map_key_copy_ctor.rs | 213 ++----- tests/unit/out/refcount/map_key_identity.rs | 325 ++++------- tests/unit/out/refcount/map_try_emplace.rs | 386 +++++-------- .../out/refcount/map_try_emplace_lvalues.rs | 530 +++++++++--------- .../operator_compound_assignment_free.rs | 40 +- .../operator_compound_assignment_member.rs | 40 +- tests/unit/out/refcount/size_t_ssize_t.rs | 99 ++-- .../out/refcount/size_t_template_param.rs | 8 +- tests/unit/out/refcount/swap_map_no_copy.rs | 84 ++- .../unit/out/refcount/switch_on_assignment.rs | 8 +- tests/unit/out/unsafe/assign_as_value.rs | 36 +- tests/unit/out/unsafe/assign_rhs_first.rs | 6 +- .../unit/out/unsafe/assignment_single_eval.rs | 389 ++++++++++--- .../unit/out/unsafe/compound_assign_paren.rs | 44 +- tests/unit/out/unsafe/copy_move_defaulted.rs | 12 +- tests/unit/out/unsafe/destructor.rs | 22 +- tests/unit/out/unsafe/expr_as_bool_c.rs | 40 +- tests/unit/out/unsafe/expr_as_bool_cpp.rs | 40 +- .../unsafe/field_pointers_malloced_struct.rs | 8 +- tests/unit/out/unsafe/fn_ptr.rs | 10 +- .../unsafe/immutable_unsigned_arithmetic.rs | 6 +- tests/unit/out/unsafe/inet_pton_ntop.rs | 18 +- .../out/unsafe/inline_container_fields.rs | 6 +- tests/unit/out/unsafe/lambda_generic.rs | 6 +- .../unsafe/lambda_generic_explicit_args.rs | 32 +- tests/unit/out/unsafe/map_key_copy_ctor.rs | 185 ++---- tests/unit/out/unsafe/map_key_identity.rs | 287 ++++------ tests/unit/out/unsafe/map_try_emplace.rs | 350 +++++------- .../out/unsafe/map_try_emplace_lvalues.rs | 420 +++++++------- .../operator_compound_assignment_free.rs | 30 +- .../operator_compound_assignment_member.rs | 30 +- tests/unit/out/unsafe/size_t_ssize_t.rs | 77 +-- .../unit/out/unsafe/size_t_template_param.rs | 6 +- tests/unit/out/unsafe/swap_map_no_copy.rs | 11 +- tests/unit/out/unsafe/switch_on_assignment.rs | 8 +- 78 files changed, 2195 insertions(+), 2787 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index d6cb5f0c6d..48a3938909 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -3069,13 +3069,21 @@ void Converter::ConvertBinaryOperator(clang::BinaryOperator *expr) { std::string_view opcode_as_string = expr->getOpcodeStr(); auto *compound = clang::dyn_cast(expr); - if (expr->isAssignmentOp() && - (isRValue() || - (compound && - (IsUnsignedArithOp(expr) || - GetUnsafeTypeAsString(lhs_type) != - GetUnsafeTypeAsString(compound->getComputationResultType()))))) { + if (compound && + (isRValue() || IsUnsignedArithOp(expr) || + GetUnsafeTypeAsString(lhs_type) != + GetUnsafeTypeAsString(compound->getComputationResultType())) && + NeedsAssignmentBinding(lhs, rhs)) { ConvertAssignment(lhs, rhs, opcode_as_string, compound); + } else if (compound && + GetUnsafeTypeAsString(lhs_type) != + GetUnsafeTypeAsString(compound->getComputationResultType())) { + PushBrace brace(*this, isRValue()); + StrCat(ConvertLValue(lhs), token::kAssign, + ConvertCompoundAssignValue(compound)); + if (isRValue()) { + StrCat(token::kSemiColon, ConvertFreshRValue(lhs)); + } } else if (expr->isCommaOp()) { PushBrace brace(*this); { @@ -3092,12 +3100,21 @@ void Converter::ConvertBinaryOperator(clang::BinaryOperator *expr) { Convert(rhs); } } else if (IsUnsignedArithOp(expr)) { + PushBrace brace(*this, compound && isRValue()); + if (compound) { + Convert(lhs); + StrCat(token::kAssign); + } { PushParen paren(*this); ConvertUnsignedArithOperand(lhs, type); } ConvertUnsignedArithBinaryOperator(expr, rhs); - MarkFresh(); + if (!compound) { + MarkFresh(); + } else if (isRValue()) { + StrCat(token::kSemiColon, ConvertFreshRValue(lhs)); + } } else if (expr->isAssignmentOp()) { if (expr->isCompoundAssignmentOp() && lhs_type->isPointerType() && rhs_type->isIntegralOrEnumerationType()) { @@ -3188,7 +3205,7 @@ Converter::ConvertCompoundAssignValue(clang::CompoundAssignOperator *expr, PushParen outer(*this); { PushParen inner(*this); - StrCat(lhs_value); + StrCat(lhs_value.empty() ? ConvertRValue(lhs) : lhs_value); ConvertCast(computation_result_type); } if (IsUnsignedArithOp(expr)) { @@ -3197,8 +3214,12 @@ Converter::ConvertCompoundAssignValue(clang::CompoundAssignOperator *expr, std::string_view op = expr->getOpcodeStr(); op.remove_suffix(1); // remove '=' from operator StrCat(op); - StrCat( - ConvertScalarCast(std::string(rhs_value), computation_result_type)); + if (rhs_value.empty()) { + Convert(expr->getRHS(), computation_result_type); + } else { + StrCat( + ConvertScalarCast(std::string(rhs_value), computation_result_type)); + } } } if (lhs->getType()->isBooleanType()) { @@ -4943,10 +4964,27 @@ void Converter::ConvertArraySubscript(clang::Expr *base, clang::Expr *idx, } } +bool Converter::NeedsAssignmentBinding(const clang::Expr *lhs, + const clang::Expr *rhs) const { + if (lhs->HasSideEffects(ctx_) || rhs->HasSideEffects(ctx_)) { + return true; + } + if (!isRValue()) { + return false; + } + // A store can change which element a composite target selects. Implicit + // variables and structured bindings can expand to such targets too. + const auto *ref = + clang::dyn_cast(lhs->IgnoreParenImpCasts()); + const auto *var = + ref ? clang::dyn_cast(ref->getDecl()) : nullptr; + return !var || var->isImplicit(); +} + void Converter::ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, std::string_view assign_operator, clang::CompoundAssignOperator *compound) { - if (compound || isRValue()) { + if (compound || (isRValue() && NeedsAssignmentBinding(lhs, rhs))) { auto right = NewTempName(); auto left = NewTempName(); auto rhs_value = ConvertFreshRValue( diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 526130a8fc..4762d9001a 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -538,10 +538,10 @@ class Converter : public clang::RecursiveASTVisitor { virtual void ConvertBinaryOperator(clang::BinaryOperator *expr); // The value that the compound assignment expr assigns to its left operand. - // Operand strings refer to values that have already been evaluated. + // Optional operand strings refer to values that have already been evaluated. std::string ConvertCompoundAssignValue(clang::CompoundAssignOperator *expr, - std::string_view lhs_value, - std::string_view rhs_value); + std::string_view lhs_value = {}, + std::string_view rhs_value = {}); virtual bool ConvertIncAndDec(clang::UnaryOperator *expr); @@ -794,6 +794,8 @@ class Converter : public clang::RecursiveASTVisitor { void EmitFlexibleArrayElementPtr(clang::Expr *array, clang::Expr *idx, bool is_mut); + bool NeedsAssignmentBinding(const clang::Expr *lhs, + const clang::Expr *rhs) const; virtual void ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, std::string_view assign_operator, diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 1d5bdadb39..54f3fd0d17 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -1592,23 +1592,43 @@ void ConverterRefCount::ConvertBinaryOperator(clang::BinaryOperator *expr) { std::string_view opcode_as_string = expr->getOpcodeStr(); auto *compound = clang::dyn_cast(expr); - if (expr->isAssignmentOp() && - (isRValue() || - (compound && - (IsUnsignedArithOp(expr) || - GetSafeTypeAsString(lhs_type) != - GetSafeTypeAsString(compound->getComputationResultType()))))) { + if (compound && + (isRValue() || IsUnsignedArithOp(expr) || + GetSafeTypeAsString(lhs_type) != + GetSafeTypeAsString(compound->getComputationResultType())) && + NeedsAssignmentBinding(lhs, rhs)) { ConvertAssignment(lhs, rhs, opcode_as_string, compound); return; } + if (compound && + GetSafeTypeAsString(lhs_type) != + GetSafeTypeAsString(compound->getComputationResultType())) { + EmitCompoundSetOrAssign(lhs, ConvertCompoundAssignValue(compound)); + return; + } + if (IsUnsignedArithOp(expr)) { + std::optional buf; + if (compound) { + buf.emplace(*this); + } { PushParen paren(*this); - ConvertUnsignedArithOperand(lhs, expr->getType()); + if (compound && lhs->isLValue()) { + StrCat(ConvertRValue(lhs)); + } else { + ConvertUnsignedArithOperand(lhs, expr->getType()); + } } ConvertUnsignedArithBinaryOperator(expr, rhs); - MarkFresh(); + if (compound) { + auto value = std::move(*buf).str(); + buf.reset(); + EmitCompoundSetOrAssign(lhs, value); + } else { + MarkFresh(); + } return; } @@ -2422,10 +2442,19 @@ bool ConverterRefCount::CanBraceAssignedValue( !lhs->HasSideEffects(ctx_) && !rhs->HasSideEffects(ctx_); } +void ConverterRefCount::EmitCompoundSetOrAssign(clang::Expr *lhs, + std::string_view value) { + PushBrace brace(*this, isRValue()); + EmitSetOrAssign(lhs, std::format("{{ {} }}", value)); + if (isRValue()) { + StrCat(token::kSemiColon, ConvertFreshRValue(lhs)); + } +} + void ConverterRefCount::ConvertAssignment( clang::Expr *lhs, clang::Expr *rhs, std::string_view assign_operator, clang::CompoundAssignOperator *compound) { - if (compound || isRValue()) { + if (compound || (isRValue() && NeedsAssignmentBinding(lhs, rhs))) { // End target borrows before an enclosing expression consumes the result. PushBrace brace(*this); auto right = NewTempName(); diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index d0ddc470df..6473eafdf0 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -458,6 +458,8 @@ class ConverterRefCount final : public Converter { bool CanBraceAssignedValue(clang::Expr *lhs, clang::Expr *rhs, std::string_view assign_operator); + void EmitCompoundSetOrAssign(clang::Expr *lhs, std::string_view value); + // If lhs is a direct reference to a global/static value (not a reference // type), emits `var.with(|rc| *rc.borrow_mut() )` and returns // true. This avoids cloning the Rc just to assign through it. Returns diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs index 581ecad0e2..7d2ff02f09 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs @@ -34,15 +34,8 @@ impl LifetimeTracked { match ( { { - match ( - { 0 }, - &mut (*useCount_3.with(Value::clone).borrow_mut()), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } - } + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } }, &mut (*dtorCount_2.with(Value::clone).borrow_mut()), diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs index afbe301d39..7ee1db2acd 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs @@ -21,14 +21,9 @@ impl LifetimeTracked { { match ( { - match ( - { 0 }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) } }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs index 922fef0561..90dae667a2 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs @@ -34,15 +34,8 @@ impl LifetimeTracked { match ( { { - match ( - { 0 }, - &mut (*useCount_3.with(Value::clone).borrow_mut()), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } - } + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } }, &mut (*dtorCount_2.with(Value::clone).borrow_mut()), diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs index 202058b1eb..c91a55f672 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs @@ -21,14 +21,9 @@ impl LifetimeTracked { { match ( { - match ( - { 0 }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) } }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs index 69bef28033..96d2a68301 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs @@ -34,15 +34,8 @@ impl LifetimeTracked { match ( { { - match ( - { 0 }, - &mut (*useCount_3.with(Value::clone).borrow_mut()), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } - } + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } }, &mut (*dtorCount_2.with(Value::clone).borrow_mut()), diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs index 3282fd145e..620fba257b 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs @@ -21,14 +21,9 @@ impl LifetimeTracked { { match ( { - match ( - { 0 }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) } }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs index 36b3168d3d..d02a04e315 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs @@ -34,15 +34,8 @@ impl LifetimeTracked { match ( { { - match ( - { 0 }, - &mut (*useCount_3.with(Value::clone).borrow_mut()), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } - } + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } }, &mut (*dtorCount_2.with(Value::clone).borrow_mut()), diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs index f02502bd6a..f4bc9820bf 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs @@ -21,14 +21,9 @@ impl LifetimeTracked { { match ( { - match ( - { 0 }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) } }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs index 0d2dc5255d..d3152789e0 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs @@ -34,15 +34,8 @@ impl LifetimeTracked { match ( { { - match ( - { 0 }, - &mut (*useCount_3.with(Value::clone).borrow_mut()), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } - } + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } }, &mut (*dtorCount_2.with(Value::clone).borrow_mut()), diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs index 85b4ee567d..f0ed2b87b3 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs @@ -21,14 +21,9 @@ impl LifetimeTracked { { match ( { - match ( - { 0 }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) } }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs index baaab94999..4b807369d7 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs @@ -34,15 +34,8 @@ impl LifetimeTracked { match ( { { - match ( - { 0 }, - &mut (*useCount_3.with(Value::clone).borrow_mut()), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } - } + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } }, &mut (*dtorCount_2.with(Value::clone).borrow_mut()), diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs index dd7d405c0b..56185caae2 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs @@ -21,14 +21,9 @@ impl LifetimeTracked { { match ( { - match ( - { 0 }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) } }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs index ae10fc7e27..47f49092e6 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs @@ -34,15 +34,8 @@ impl LifetimeTracked { match ( { { - match ( - { 0 }, - &mut (*useCount_3.with(Value::clone).borrow_mut()), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } - } + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } }, &mut (*dtorCount_2.with(Value::clone).borrow_mut()), diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs index fb3187d45a..bb26c62ce3 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs @@ -21,14 +21,9 @@ impl LifetimeTracked { { match ( { - match ( - { 0 }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) } }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs index 9dc9012e58..224d0acbbd 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs @@ -34,15 +34,8 @@ impl LifetimeTracked { match ( { { - match ( - { 0 }, - &mut (*useCount_3.with(Value::clone).borrow_mut()), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } - } + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } }, &mut (*dtorCount_2.with(Value::clone).borrow_mut()), diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs index 21af739147..cdd526036f 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs @@ -21,14 +21,9 @@ impl LifetimeTracked { { match ( { - match ( - { 0 }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) } }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index bc9aeb1aab..dd2f665a12 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -66,15 +66,8 @@ impl LifetimeTracked { match ( { { - match ( - { 0 }, - &mut (*useCount_4.with(Value::clone).borrow_mut()), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } - } + useCount_4.with(|rc| *rc.borrow_mut() = 0); + useCount_4.with(|rc| *rc.borrow()) } }, &mut (*dtorCount_3.with(Value::clone).borrow_mut()), diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index 67d0712b88..ebfdb3e81f 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -51,14 +51,9 @@ impl LifetimeTracked { { match ( { - match ( - { 0 }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) } }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)), diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs index 5cc4ae59e1..cb3b51776c 100644 --- a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs @@ -34,15 +34,8 @@ impl LifetimeTracked { match ( { { - match ( - { 0 }, - &mut (*useCount_3.with(Value::clone).borrow_mut()), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } - } + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } }, &mut (*dtorCount_2.with(Value::clone).borrow_mut()), diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs index 19a9d002b1..a04576aa31 100644 --- a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs @@ -34,15 +34,8 @@ impl LifetimeTracked { match ( { { - match ( - { 0 }, - &mut (*useCount_3.with(Value::clone).borrow_mut()), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } - } + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } }, &mut (*dtorCount_2.with(Value::clone).borrow_mut()), diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs index 770dc0dc1d..3afc1310e7 100644 --- a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs @@ -21,14 +21,9 @@ impl LifetimeTracked { { match ( { - match ( - { 0 }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) } }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs index 8acdb4be39..94d41e22f4 100644 --- a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs @@ -21,14 +21,9 @@ impl LifetimeTracked { { match ( { - match ( - { 0 }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) } }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), diff --git a/tests/unit/assign_as_value.c b/tests/unit/assign_as_value.c index e148ed64ff..1d313281ae 100644 --- a/tests/unit/assign_as_value.c +++ b/tests/unit/assign_as_value.c @@ -8,6 +8,12 @@ int main(void) { q = p -= 1; assert(p == buf); assert(q == buf); + p += 1; + int i = 0; + q = *(&p + i++) -= 1; + assert(i == 1); + assert(p == buf); + assert(q == buf); char out; switch (out = 'x') { diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index 470496600b..c8925da7f1 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -1,5 +1,6 @@ // ADDITIONAL_COMPILE_FLAGS: -std=c++17 #include +#include #include template void test() { @@ -15,6 +16,22 @@ template void test() { i = 0; T assigned = (a[i++] = 99); std::printf("simple %d %d %d %d\n", i, int(assigned), int(a[0]), int(a[1])); + + T plain = 10; + plain += 5; + T plain_result = (plain += 2); + std::printf("plain %d %d\n", int(plain_result), int(plain)); + + i = 0; + a[i] += (i = 1, T(5)); + std::printf("rhs target %d %d %d\n", i, int(a[0]), int(a[1])); + + a[0] = 0; + T selected = (a[a[0]] += 1); + std::printf("self compound %d %d %d\n", int(selected), int(a[0]), int(a[1])); + a[0] = 0; + selected = (a[a[0]] = 1); + std::printf("self simple %d %d %d\n", int(selected), int(a[0]), int(a[1])); } template void test_comma() { @@ -60,6 +77,28 @@ void test_borrows() { std::printf("%d\n", observe(values[0] += 5, &values[0])); } +unsigned selected_values[3] = {0, 20, 30}; +struct IndexedBinding { + template __attribute__((pure)) unsigned &get() { + return selected_values[selected_values[0]]; + } +}; +namespace std { +template <> struct tuple_size { + static constexpr unsigned value = 1; +}; +template <> struct tuple_element<0, IndexedBinding> { + using type = unsigned; +}; +} // namespace std + +void test_binding() { + IndexedBinding owner; + auto &[value] = owner; + unsigned result = (value += 1); + std::printf("binding compound %u %u\n", result, selected_values[0]); +} + int main() { test(); test(); @@ -72,5 +111,6 @@ int main() { unsigned result = ((++i, ref)[0] += 5); std::printf("array reference %d %u %u\n", i, result, values[0]); test_borrows(); + test_binding(); return 0; } diff --git a/tests/unit/out/refcount/assign_as_value.rs b/tests/unit/out/refcount/assign_as_value.rs index 4d3ec07a03..fc16954184 100644 --- a/tests/unit/out/refcount/assign_as_value.rs +++ b/tests/unit/out/refcount/assign_as_value.rs @@ -12,37 +12,41 @@ pub fn main() { } fn main_0() -> i32 { let buf: Value> = Rc::new(RefCell::new((0..2).map(|_| 0_i8).collect::>())); - let mut p: Ptr = buf.decay(); + let p: Value> = Rc::new(RefCell::new(buf.decay())); let mut q: Ptr = Ptr::::null(); q = { - match ({ 1 }, &mut (p)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (*__tmp_1).offset((__tmp_0 as isize)); - (*__tmp_1).clone() - } - } + (*p.borrow_mut()) += 1; + (*p.borrow()).clone() }; assert!(({ (q).clone() } == { buf.decay().offset((1) as isize) })); q = { - match ({ 1 }, &mut (p)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = (*__tmp_3).offset(-(__tmp_2 as isize)); - (*__tmp_3).clone() - } + (*p.borrow_mut()) -= 1; + (*p.borrow()).clone() + }; + assert!(({ ({ (*p.borrow()).clone() } == { buf.decay() }) })); + assert!(({ (q).clone() } == { buf.decay() })); + (*p.borrow_mut()) += 1; + let mut i: i32 = 0; + q = { + match ( + { 1 }, + &((p.as_pointer()).offset((i.postfix_inc()) as isize)), + ) { + (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { + (*__tmp_1) = (*__tmp_1).offset(-(__tmp_0 as isize)); + (*__tmp_1).clone() + }), } }; - assert!(({ (p).clone() } == { buf.decay() })); + assert!((i == 1)); + assert!(({ ({ (*p.borrow()).clone() } == { buf.decay() }) })); assert!(({ (q).clone() } == { buf.decay() })); let mut out: i8 = 0_i8; 'switch: { match { (({ - match ({ (('x' as i32) as i8) }, &mut (out)) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } - } + out = (('x' as i32) as i8); + out }) as i32) } { __v if __v == ('x' as i32) => { diff --git a/tests/unit/out/refcount/assign_rhs_first.rs b/tests/unit/out/refcount/assign_rhs_first.rs index 5153a31aac..44e750a1f5 100644 --- a/tests/unit/out/refcount/assign_rhs_first.rs +++ b/tests/unit/out/refcount/assign_rhs_first.rs @@ -105,13 +105,7 @@ fn main_0() -> i32 { ); let mut b: Ptr = a.decay().reinterpret_cast::(); elem!(b, 0).write(7_u8); - { - match ({ 1 }, &(elem!(b, 4))) { - (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { - (*__tmp_1) = (((*__tmp_1) as i32) + (__tmp_0 as i32)) as u8; - }), - } - }; + elem!(b, 4).write({ (((elem!(b, 4).read()) as i32) + 1) as u8 }); assert!(({ ((*a.borrow())[(0) as usize] == 7) && ((*a.borrow())[(1) as usize] == 3) })); return 0; } diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 1d133b8633..9e7a69cfde 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -54,14 +54,73 @@ pub fn test_0() { (a[(0) as usize] as i32), (a[(1) as usize] as i32) ); + let mut plain: u32 = 10_u32; + plain = { (plain).wrapping_add(5_u32) }; + let mut plain_result: u32 = ({ + plain = { (plain).wrapping_add(2_u32) }; + plain + }); + printf!(b"plain %d %d\n", (plain_result as i32), (plain as i32)); + i = 0; + { + match ( + { + { + i = 1; + 5_u32 + } + }, + &mut (a[(i) as usize]), + ) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as u32).wrapping_add((__tmp_6 as u32))) as u32; + } + } + }; + printf!( + b"rhs target %d %d %d\n", + i, + (a[(0) as usize] as i32), + (a[(1) as usize] as i32) + ); + a[(0) as usize] = 0_u32; + let mut selected: u32 = ({ + match ({ 1_u32 }, &mut (a[(a[(0) as usize]) as usize])) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as u32).wrapping_add((__tmp_8 as u32))) as u32; + (*__tmp_9).clone() + } + } + }); + printf!( + b"self compound %d %d %d\n", + (selected as i32), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32) + ); + a[(0) as usize] = 0_u32; + selected = ({ + match ({ 1_u32 }, &mut (a[(a[(0) as usize]) as usize])) { + (__tmp_10, __tmp_11) => { + (*__tmp_11) = __tmp_10; + (*__tmp_11).clone() + } + } + }); + printf!( + b"self simple %d %d %d\n", + (selected as i32), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32) + ); } pub fn test_1() { let mut a: [i16; 3] = [10_i16, 20_i16, 30_i16]; let mut i: i32 = 0; { match ({ 5 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as i32) + (__tmp_6 as i32)) as i16; + (__tmp_12, __tmp_13) => { + (*__tmp_13) = (((*__tmp_13) as i32) + (__tmp_12 as i32)) as i16; } } }; @@ -74,9 +133,9 @@ pub fn test_1() { i = 0; let mut sum: i16 = ({ match ({ 2 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as i32) + (__tmp_8 as i32)) as i16; - (*__tmp_9).clone() + (__tmp_14, __tmp_15) => { + (*__tmp_15) = (((*__tmp_15) as i32) + (__tmp_14 as i32)) as i16; + (*__tmp_15).clone() } } }); @@ -90,9 +149,9 @@ pub fn test_1() { i = 0; let mut assigned: i16 = ({ match ({ 99_i16 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_10, __tmp_11) => { - (*__tmp_11) = __tmp_10; - (*__tmp_11).clone() + (__tmp_16, __tmp_17) => { + (*__tmp_17) = __tmp_16; + (*__tmp_17).clone() } } }); @@ -103,6 +162,65 @@ pub fn test_1() { (a[(0) as usize] as i32), (a[(1) as usize] as i32) ); + let mut plain: i16 = 10_i16; + plain = { ((plain as i32) + 5) as i16 }; + let mut plain_result: i16 = ({ + plain = { ((plain as i32) + 2) as i16 }; + plain + }); + printf!(b"plain %d %d\n", (plain_result as i32), (plain as i32)); + i = 0; + { + match ( + { + ({ + i = 1; + 5_i16 + } as i32) + }, + &mut (a[(i) as usize]), + ) { + (__tmp_18, __tmp_19) => { + (*__tmp_19) = (((*__tmp_19) as i32) + (__tmp_18 as i32)) as i16; + } + } + }; + printf!( + b"rhs target %d %d %d\n", + i, + (a[(0) as usize] as i32), + (a[(1) as usize] as i32) + ); + a[(0) as usize] = 0_i16; + let mut selected: i16 = ({ + match ({ 1 }, &mut (a[(a[(0) as usize]) as usize])) { + (__tmp_20, __tmp_21) => { + (*__tmp_21) = (((*__tmp_21) as i32) + (__tmp_20 as i32)) as i16; + (*__tmp_21).clone() + } + } + }); + printf!( + b"self compound %d %d %d\n", + (selected as i32), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32) + ); + a[(0) as usize] = 0_i16; + selected = ({ + match ({ 1_i16 }, &mut (a[(a[(0) as usize]) as usize])) { + (__tmp_22, __tmp_23) => { + (*__tmp_23) = __tmp_22; + (*__tmp_23).clone() + } + } + }); + printf!( + b"self simple %d %d %d\n", + (selected as i32), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32) + ); } pub fn test_2() { let mut a: [i32; 3] = [10, 20, 30]; @@ -112,9 +230,9 @@ pub fn test_2() { i = 0; let mut sum: i32 = ({ match ({ 2 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = (((*__tmp_13) as i32) + (__tmp_12 as i32)) as i32; - (*__tmp_13).clone() + (__tmp_24, __tmp_25) => { + (*__tmp_25) = (((*__tmp_25) as i32) + (__tmp_24 as i32)) as i32; + (*__tmp_25).clone() } } }); @@ -128,9 +246,9 @@ pub fn test_2() { i = 0; let mut assigned: i32 = ({ match ({ 99 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_14, __tmp_15) => { - (*__tmp_15) = __tmp_14; - (*__tmp_15).clone() + (__tmp_26, __tmp_27) => { + (*__tmp_27) = __tmp_26; + (*__tmp_27).clone() } } }); @@ -141,6 +259,55 @@ pub fn test_2() { a[(0) as usize], a[(1) as usize] ); + let mut plain: i32 = 10; + plain += 5; + let mut plain_result: i32 = ({ + plain += 2; + plain + }); + printf!(b"plain %d %d\n", plain_result, plain); + i = 0; + let __rhs = { + i = 1; + 5 + }; + a[(i) as usize] += __rhs; + printf!( + b"rhs target %d %d %d\n", + i, + a[(0) as usize], + a[(1) as usize] + ); + a[(0) as usize] = 0; + let mut selected: i32 = ({ + match ({ 1 }, &mut (a[(a[(0) as usize]) as usize])) { + (__tmp_28, __tmp_29) => { + (*__tmp_29) = (((*__tmp_29) as i32) + (__tmp_28 as i32)) as i32; + (*__tmp_29).clone() + } + } + }); + printf!( + b"self compound %d %d %d\n", + selected, + a[(0) as usize], + a[(1) as usize] + ); + a[(0) as usize] = 0; + selected = ({ + match ({ 1 }, &mut (a[(a[(0) as usize]) as usize])) { + (__tmp_30, __tmp_31) => { + (*__tmp_31) = __tmp_30; + (*__tmp_31).clone() + } + } + }); + printf!( + b"self simple %d %d %d\n", + selected, + a[(0) as usize], + a[(1) as usize] + ); } pub fn test_comma_3() { let x: Value = Rc::new(RefCell::new(10_u32)); @@ -153,8 +320,8 @@ pub fn test_comma_3() { x.as_pointer() }), ) { - (__tmp_16, __tmp_17) => __tmp_17.with_mut(|__tmp_17| { - (*__tmp_17) = (((*__tmp_17) as u32).wrapping_add((__tmp_16 as u32))) as u32; + (__tmp_32, __tmp_33) => __tmp_33.with_mut(|__tmp_33| { + (*__tmp_33) = (((*__tmp_33) as u32).wrapping_add((__tmp_32 as u32))) as u32; }), } }; @@ -167,9 +334,9 @@ pub fn test_comma_3() { x.as_pointer() }), ) { - (__tmp_18, __tmp_19) => __tmp_19.with_mut(|__tmp_19| { - (*__tmp_19) = (((*__tmp_19) as u32).wrapping_add((__tmp_18 as u32))) as u32; - (*__tmp_19).clone() + (__tmp_34, __tmp_35) => __tmp_35.with_mut(|__tmp_35| { + (*__tmp_35) = (((*__tmp_35) as u32).wrapping_add((__tmp_34 as u32))) as u32; + (*__tmp_35).clone() }), } }); @@ -187,9 +354,9 @@ pub fn test_comma_3() { x.as_pointer() }), ) { - (__tmp_20, __tmp_21) => __tmp_21.with_mut(|__tmp_21| { - (*__tmp_21) = __tmp_20; - (*__tmp_21).clone() + (__tmp_36, __tmp_37) => __tmp_37.with_mut(|__tmp_37| { + (*__tmp_37) = __tmp_36; + (*__tmp_37).clone() }), } }); @@ -208,8 +375,8 @@ pub fn test_comma_3() { (p).clone() }), ) { - (__tmp_22, __tmp_23) => __tmp_23.with_mut(|__tmp_23| { - (*__tmp_23) = (((*__tmp_23) as u32).wrapping_add((__tmp_22 as u32))) as u32; + (__tmp_38, __tmp_39) => __tmp_39.with_mut(|__tmp_39| { + (*__tmp_39) = (((*__tmp_39) as u32).wrapping_add((__tmp_38 as u32))) as u32; }), } }; @@ -222,9 +389,9 @@ pub fn test_comma_3() { (p).clone() }), ) { - (__tmp_24, __tmp_25) => __tmp_25.with_mut(|__tmp_25| { - (*__tmp_25) = (((*__tmp_25) as u32).wrapping_add((__tmp_24 as u32))) as u32; - (*__tmp_25).clone() + (__tmp_40, __tmp_41) => __tmp_41.with_mut(|__tmp_41| { + (*__tmp_41) = (((*__tmp_41) as u32).wrapping_add((__tmp_40 as u32))) as u32; + (*__tmp_41).clone() }), } }); @@ -243,9 +410,9 @@ pub fn test_comma_3() { (p).clone() }), ) { - (__tmp_26, __tmp_27) => __tmp_27.with_mut(|__tmp_27| { - (*__tmp_27) = __tmp_26; - (*__tmp_27).clone() + (__tmp_42, __tmp_43) => __tmp_43.with_mut(|__tmp_43| { + (*__tmp_43) = __tmp_42; + (*__tmp_43).clone() }), } }); @@ -268,8 +435,8 @@ pub fn test_comma_4() { x.as_pointer() }), ) { - (__tmp_28, __tmp_29) => __tmp_29.with_mut(|__tmp_29| { - (*__tmp_29) = (((*__tmp_29) as i32) + (__tmp_28 as i32)) as i16; + (__tmp_44, __tmp_45) => __tmp_45.with_mut(|__tmp_45| { + (*__tmp_45) = (((*__tmp_45) as i32) + (__tmp_44 as i32)) as i16; }), } }; @@ -282,9 +449,9 @@ pub fn test_comma_4() { x.as_pointer() }), ) { - (__tmp_30, __tmp_31) => __tmp_31.with_mut(|__tmp_31| { - (*__tmp_31) = (((*__tmp_31) as i32) + (__tmp_30 as i32)) as i16; - (*__tmp_31).clone() + (__tmp_46, __tmp_47) => __tmp_47.with_mut(|__tmp_47| { + (*__tmp_47) = (((*__tmp_47) as i32) + (__tmp_46 as i32)) as i16; + (*__tmp_47).clone() }), } }); @@ -302,9 +469,9 @@ pub fn test_comma_4() { x.as_pointer() }), ) { - (__tmp_32, __tmp_33) => __tmp_33.with_mut(|__tmp_33| { - (*__tmp_33) = __tmp_32; - (*__tmp_33).clone() + (__tmp_48, __tmp_49) => __tmp_49.with_mut(|__tmp_49| { + (*__tmp_49) = __tmp_48; + (*__tmp_49).clone() }), } }); @@ -323,8 +490,8 @@ pub fn test_comma_4() { (p).clone() }), ) { - (__tmp_34, __tmp_35) => __tmp_35.with_mut(|__tmp_35| { - (*__tmp_35) = (((*__tmp_35) as i32) + (__tmp_34 as i32)) as i16; + (__tmp_50, __tmp_51) => __tmp_51.with_mut(|__tmp_51| { + (*__tmp_51) = (((*__tmp_51) as i32) + (__tmp_50 as i32)) as i16; }), } }; @@ -337,9 +504,9 @@ pub fn test_comma_4() { (p).clone() }), ) { - (__tmp_36, __tmp_37) => __tmp_37.with_mut(|__tmp_37| { - (*__tmp_37) = (((*__tmp_37) as i32) + (__tmp_36 as i32)) as i16; - (*__tmp_37).clone() + (__tmp_52, __tmp_53) => __tmp_53.with_mut(|__tmp_53| { + (*__tmp_53) = (((*__tmp_53) as i32) + (__tmp_52 as i32)) as i16; + (*__tmp_53).clone() }), } }); @@ -358,9 +525,9 @@ pub fn test_comma_4() { (p).clone() }), ) { - (__tmp_38, __tmp_39) => __tmp_39.with_mut(|__tmp_39| { - (*__tmp_39) = __tmp_38; - (*__tmp_39).clone() + (__tmp_54, __tmp_55) => __tmp_55.with_mut(|__tmp_55| { + (*__tmp_55) = __tmp_54; + (*__tmp_55).clone() }), } }); @@ -386,12 +553,8 @@ pub fn test_borrows_8() { b"%d\n", ({ observe_global_6({ - match ({ 99 }, &mut (*global_5.with(Value::clone).borrow_mut())) { - (__tmp_40, __tmp_41) => { - (*__tmp_41) = __tmp_40; - (*__tmp_41).clone() - } - } + global_5.with(|rc| *rc.borrow_mut() = 99); + global_5.with(|rc| *rc.borrow()) }) }) ); @@ -399,12 +562,8 @@ pub fn test_borrows_8() { b"%d\n", ({ observe_global_6({ - match ({ 5 }, &mut (*global_5.with(Value::clone).borrow_mut())) { - (__tmp_42, __tmp_43) => { - (*__tmp_43) = (((*__tmp_43) as i32) + (__tmp_42 as i32)) as i32; - (*__tmp_43).clone() - } - } + global_5.with(|rc| *rc.borrow_mut() += 5); + global_5.with(|rc| *rc.borrow()) }) }) ); @@ -413,12 +572,8 @@ pub fn test_borrows_8() { b"%d\n", ({ let _assigned: i32 = { - match ({ 99 }, &mut (*local.borrow_mut())) { - (__tmp_44, __tmp_45) => { - (*__tmp_45) = __tmp_44; - (*__tmp_45).clone() - } - } + (*local.borrow_mut()) = 99; + (*local.borrow()) }; let _stored: Ptr = (local.as_pointer()); observe_7(_assigned, _stored) @@ -428,12 +583,8 @@ pub fn test_borrows_8() { b"%d\n", ({ let _assigned: i32 = { - match ({ 5 }, &mut (*local.borrow_mut())) { - (__tmp_46, __tmp_47) => { - (*__tmp_47) = (((*__tmp_47) as i32) + (__tmp_46 as i32)) as i32; - (*__tmp_47).clone() - } - } + (*local.borrow_mut()) += 5; + (*local.borrow()) }; let _stored: Ptr = (local.as_pointer()); observe_7(_assigned, _stored) @@ -445,9 +596,9 @@ pub fn test_borrows_8() { ({ let _assigned: i32 = { match ({ 99 }, &mut ((*record.borrow_mut()).value)) { - (__tmp_48, __tmp_49) => { - (*__tmp_49) = __tmp_48; - (*__tmp_49).clone() + (__tmp_56, __tmp_57) => { + (*__tmp_57) = __tmp_56; + (*__tmp_57).clone() } } }; @@ -460,9 +611,9 @@ pub fn test_borrows_8() { ({ let _assigned: i32 = { match ({ 5 }, &mut ((*record.borrow_mut()).value)) { - (__tmp_50, __tmp_51) => { - (*__tmp_51) = (((*__tmp_51) as i32) + (__tmp_50 as i32)) as i32; - (*__tmp_51).clone() + (__tmp_58, __tmp_59) => { + (*__tmp_59) = (((*__tmp_59) as i32) + (__tmp_58 as i32)) as i32; + (*__tmp_59).clone() } } }; @@ -476,9 +627,9 @@ pub fn test_borrows_8() { ({ let _assigned: i32 = { match ({ 99 }, &mut ((*values.borrow_mut())[0_usize])) { - (__tmp_52, __tmp_53) => { - (*__tmp_53) = __tmp_52; - (*__tmp_53).clone() + (__tmp_60, __tmp_61) => { + (*__tmp_61) = __tmp_60; + (*__tmp_61).clone() } } }; @@ -491,9 +642,9 @@ pub fn test_borrows_8() { ({ let _assigned: i32 = { match ({ 5 }, &mut ((*values.borrow_mut())[0_usize])) { - (__tmp_54, __tmp_55) => { - (*__tmp_55) = (((*__tmp_55) as i32) + (__tmp_54 as i32)) as i32; - (*__tmp_55).clone() + (__tmp_62, __tmp_63) => { + (*__tmp_63) = (((*__tmp_63) as i32) + (__tmp_62 as i32)) as i32; + (*__tmp_63).clone() } } }; @@ -508,6 +659,34 @@ pub struct Record_9 { #[offset(0)] pub value: i32, } +thread_local!( + pub static selected_values_10: Value> = + Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); +); +#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(1)] +pub struct IndexedBinding {} +pub fn test_binding_11() { + let owner: Value = Rc::new(RefCell::new(::default())); + let __decomp_12: Ptr = owner.as_pointer(); + let value: Ptr = ({ IndexedBindingImpl::get_1_0(&__decomp_12) }); + let mut result: u32 = ({ + match ({ 1_u32 }, &({ IndexedBindingImpl::get_1_0(&__decomp_12) })) { + (__tmp_64, __tmp_65) => __tmp_65.with_mut(|__tmp_65| { + (*__tmp_65) = (((*__tmp_65) as u32).wrapping_add((__tmp_64 as u32))) as u32; + (*__tmp_65).clone() + }), + } + }); + printf!( + b"binding compound %u %u\n", + result, + ({ + let __idx0 = (0) as usize; + selected_values_10.with(|rc| rc.borrow()[__idx0]) + }) + ); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -532,9 +711,9 @@ fn main_0() -> i32 { 0 )), ) { - (__tmp_56, __tmp_57) => __tmp_57.with_mut(|__tmp_57| { - (*__tmp_57) = (((*__tmp_57) as u32).wrapping_add((__tmp_56 as u32))) as u32; - (*__tmp_57).clone() + (__tmp_66, __tmp_67) => __tmp_67.with_mut(|__tmp_67| { + (*__tmp_67) = (((*__tmp_67) as u32).wrapping_add((__tmp_66 as u32))) as u32; + (*__tmp_67).clone() }), } }); @@ -545,8 +724,23 @@ fn main_0() -> i32 { (*values.borrow())[(0) as usize] ); ({ test_borrows_8() }); + ({ test_binding_11() }); return 0; } +pub trait IndexedBindingImpl { + fn get_1_0(&self) -> Ptr; +} +impl IndexedBindingImpl for Ptr { + fn get_1_0(&self) -> Ptr { + return selected_values_10.with(|v| v.decay()).offset( + ({ + let __idx0 = (0) as usize; + selected_values_10.with(|rc| rc.borrow()[__idx0]) + }), + ); + } +} pub fn __cpp2rust_init_globals() { let _ = global_5.with(|_| ()); + let _ = selected_values_10.with(|_| ()); } diff --git a/tests/unit/out/refcount/compound_assign_paren.rs b/tests/unit/out/refcount/compound_assign_paren.rs index 7b311ac7df..eba87b7b6c 100644 --- a/tests/unit/out/refcount/compound_assign_paren.rs +++ b/tests/unit/out/refcount/compound_assign_paren.rs @@ -19,61 +19,23 @@ pub fn main() { fn main_0() -> i32 { let item: Value = Rc::new(RefCell::new(Item { flags: 0_u8 })); let mut ptr: Ptr = (item.as_pointer()); - { - match ({ (1 << 0) }, &(field!((ptr), flags))) { - (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { - (*__tmp_1) = (((*__tmp_1) as i32) | (__tmp_0 as i32)) as u8; - }), - } - }; - { - match ({ (1 << 1) }, &(field!((ptr), flags))) { - (__tmp_2, __tmp_3) => __tmp_3.with_mut(|__tmp_3| { - (*__tmp_3) = (((*__tmp_3) as i32) | (__tmp_2 as i32)) as u8; - }), - } - }; + field!((ptr), flags).write({ (((ptr).with(|__s| __s.flags) as i32) | (1 << 0)) as u8 }); + field!((ptr), flags).write({ (((ptr).with(|__s| __s.flags) as i32) | (1 << 1)) as u8 }); assert!(((ptr.with(|__s| __s.flags) as i32) == 3)); - { - match ({ ((!(1 << 0) as u8) as i32) }, &(field!((ptr), flags))) { - (__tmp_4, __tmp_5) => __tmp_5.with_mut(|__tmp_5| { - (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) as u8; - }), - } - }; + field!((ptr), flags) + .write({ (((ptr).with(|__s| __s.flags) as i32) & ((!(1 << 0) as u8) as i32)) as u8 }); assert!(((ptr.with(|__s| __s.flags) as i32) == 2)); let mut bits: [u8; 4] = [0_u8; 4]; - { - match ( - { (((1 << ((5) & 7)) as u8) as i32) }, - &mut ((bits)[((5) / 8) as usize]), - ) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as i32) | (__tmp_6 as i32)) as u8; - } - } - }; - { - match ( - { (((1 << ((13) & 7)) as u8) as i32) }, - &mut ((bits)[((13) / 8) as usize]), - ) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as i32) | (__tmp_8 as i32)) as u8; - } - } - }; + (bits)[((5) / 8) as usize] = + { (((bits)[((5) / 8) as usize] as i32) | (((1 << ((5) & 7)) as u8) as i32)) as u8 }; + (bits)[((13) / 8) as usize] = + { (((bits)[((13) / 8) as usize] as i32) | (((1 << ((13) & 7)) as u8) as i32)) as u8 }; assert!(((bits[(0) as usize] as i32) == 32)); assert!(((bits[(1) as usize] as i32) == 32)); assert!(((bits[(2) as usize] as i32) == 0)); if ((ptr.with(|__s| __s.flags) as i32) != 0) { - { - match ({ ((!(1 << 1) as u8) as i32) }, &(field!((ptr), flags))) { - (__tmp_10, __tmp_11) => __tmp_11.with_mut(|__tmp_11| { - (*__tmp_11) = (((*__tmp_11) as i32) & (__tmp_10 as i32)) as u8; - }), - } - }; + field!((ptr), flags) + .write({ (((ptr).with(|__s| __s.flags) as i32) & ((!(1 << 1) as u8) as i32)) as u8 }); } assert!(((ptr.with(|__s| __s.flags) as i32) == 0)); return 0; diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index c94d6eb46a..fc5ac5d32c 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -292,12 +292,8 @@ fn main_0() -> i32 { let g: Value = Rc::new(RefCell::new(Explicit::new({ 4 }))); let _dtor_g = std::mem::DropGuard::new(g.clone(), |__p| __p.as_pointer().destructor()); (*g.borrow_mut()) = { - match ({ (*f.borrow()).clone() }, &mut (*e.borrow_mut())) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } + (*e.borrow_mut()) = (*f.borrow()).clone(); + (*e.borrow()).clone() }; assert!( ({ same_0(g.as_pointer(), f.as_pointer(),) }) @@ -386,8 +382,8 @@ fn main_0() -> i32 { (*bufs.borrow_mut()).push(__a1) }; { - let mut __tmp_4 = { Buffer::move_from({ bufs.decay().offset(0_usize) }) }; - (*bufs.borrow_mut()).push(__tmp_4); + let mut __tmp_2 = { Buffer::move_from({ bufs.decay().offset(0_usize) }) }; + (*bufs.borrow_mut()).push(__tmp_2); }; assert!( ({ diff --git a/tests/unit/out/refcount/destructor.rs b/tests/unit/out/refcount/destructor.rs index 1cf63cee9a..034b8813ec 100644 --- a/tests/unit/out/refcount/destructor.rs +++ b/tests/unit/out/refcount/destructor.rs @@ -277,16 +277,12 @@ pub trait Templated_char_Impl { } impl Templated_char_Impl for Ptr { fn destructor(&self) { - { - match ( - { ::std::mem::size_of::() }, - &mut (*global_0.with(Value::clone).borrow_mut()), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as usize).wrapping_add((__tmp_0 as usize))) as i32; - } + global_0.with(|rc| { + *rc.borrow_mut() = { + ((global_0.with(|rc| *rc.borrow()) as usize) + .wrapping_add((::std::mem::size_of::() as usize))) as i32 } - }; + }); } } pub trait Templated_int_Impl { @@ -294,16 +290,12 @@ pub trait Templated_int_Impl { } impl Templated_int_Impl for Ptr { fn destructor(&self) { - { - match ( - { ::std::mem::size_of::() }, - &mut (*global_0.with(Value::clone).borrow_mut()), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = (((*__tmp_3) as usize).wrapping_add((__tmp_2 as usize))) as i32; - } + global_0.with(|rc| { + *rc.borrow_mut() = { + ((global_0.with(|rc| *rc.borrow()) as usize) + .wrapping_add((::std::mem::size_of::() as usize))) as i32 } - }; + }); } } pub fn __cpp2rust_init_globals() { diff --git a/tests/unit/out/refcount/expr_as_bool_c.rs b/tests/unit/out/refcount/expr_as_bool_c.rs index 2ee65e00d9..2a413f6ae9 100644 --- a/tests/unit/out/refcount/expr_as_bool_c.rs +++ b/tests/unit/out/refcount/expr_as_bool_c.rs @@ -23,21 +23,13 @@ fn main_0() -> i32 { let mut a: i32 = 0; let mut b: i32 = 0_i32; if ({ - match ({ a }, &mut (b)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } - } + b = a; + b } != 0) {} 'loop_: while (({ - match ({ a }, &mut (b)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } + b = a; + b }) != 0) {} if (a != 0) {} @@ -46,30 +38,18 @@ fn main_0() -> i32 { assert!((a == b)); assert!( !(({ - match ({ b }, &mut (a)) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } - } + a = b; + a }) != 0) ); let mut c: bool = false; c = ({ - match ({ b }, &mut (a)) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = __tmp_6; - (*__tmp_7).clone() - } - } + a = b; + a } != 0); c = (({ - match ({ a }, &mut (b)) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = __tmp_8; - (*__tmp_9).clone() - } - } + b = a; + b }) != 0); c = (a != 0); c = (a == b); diff --git a/tests/unit/out/refcount/expr_as_bool_cpp.rs b/tests/unit/out/refcount/expr_as_bool_cpp.rs index 1acb1dd5df..54e2aebc73 100644 --- a/tests/unit/out/refcount/expr_as_bool_cpp.rs +++ b/tests/unit/out/refcount/expr_as_bool_cpp.rs @@ -23,21 +23,13 @@ fn main_0() -> i32 { let mut a: i32 = 0; let mut b: i32 = 0_i32; if ({ - match ({ a }, &mut (b)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } - } + b = a; + b } != 0) {} 'loop_: while (({ - match ({ a }, &mut (b)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } + b = a; + b }) != 0) {} if (a != 0) {} @@ -46,30 +38,18 @@ fn main_0() -> i32 { assert!((a == b)); assert!( !(({ - match ({ b }, &mut (a)) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } - } + a = b; + a }) != 0) ); let mut c: bool = false; c = ({ - match ({ b }, &mut (a)) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = __tmp_6; - (*__tmp_7).clone() - } - } + a = b; + a } != 0); c = (({ - match ({ a }, &mut (b)) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = __tmp_8; - (*__tmp_9).clone() - } - } + b = a; + b }) != 0); c = (a != 0); c = (a == b); diff --git a/tests/unit/out/refcount/field_pointers_malloced_struct.rs b/tests/unit/out/refcount/field_pointers_malloced_struct.rs index e654ce2f19..cbb5987840 100644 --- a/tests/unit/out/refcount/field_pointers_malloced_struct.rs +++ b/tests/unit/out/refcount/field_pointers_malloced_struct.rs @@ -62,12 +62,8 @@ fn main_0() -> i32 { assert!((x == 8) && (s.with(|__s| __s.b) == 3)); let mut y: i32 = 0; let __rhs = ({ - match ({ 99 }, &mut (y)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } + y = 99; + y }); field!(s, c).write(__rhs); assert!((s.with(|__s| __s.c) == 99) && (y == 99)); diff --git a/tests/unit/out/refcount/fn_ptr.rs b/tests/unit/out/refcount/fn_ptr.rs index e1f5031064..6d2d59afd4 100644 --- a/tests/unit/out/refcount/fn_ptr.rs +++ b/tests/unit/out/refcount/fn_ptr.rs @@ -16,13 +16,7 @@ pub fn twice_2(mut x: u64) -> u64 { return (x).wrapping_mul(2_u64); } pub fn twice_in_place_3(x: Ptr) -> u64 { - { - match ({ 2_u64 }, &(x)) { - (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { - (*__tmp_1) = (((*__tmp_1) as u64).wrapping_mul((__tmp_0 as u64))) as u64; - }), - } - }; + x.write({ (x.read()).wrapping_mul(2_u64) }); return (x.read()); } pub fn ret_size_4(mut v: i32) -> usize { @@ -92,10 +86,10 @@ fn main_0() -> i32 { assert!(({ ((*m.borrow()) == 42_usize) })); assert!((({ call_fn_5(FnPtr:: usize>::new(ret_size_4), 3,) }) == 8_usize)); let mut hh: HashHolder_unsigned_long__ptr__bool__ = { - let __tmp_2: Value u64>> = Rc::new(RefCell::new( + let __tmp_0: Value u64>> = Rc::new(RefCell::new( (FnPtr:: usize>::new(identity_hash_6)).cast:: u64>(), )); - HashHolder_unsigned_long__ptr__bool__::new({ __tmp_2.as_pointer() }) + HashHolder_unsigned_long__ptr__bool__::new({ __tmp_0.as_pointer() }) }; assert!((({ hh.h.call(true,) }) == 1_u64)); let mut handler: FnPtr = FnPtr::::new(add_to_total_8); diff --git a/tests/unit/out/refcount/immutable_unsigned_arithmetic.rs b/tests/unit/out/refcount/immutable_unsigned_arithmetic.rs index ed54398411..43533e43c9 100644 --- a/tests/unit/out/refcount/immutable_unsigned_arithmetic.rs +++ b/tests/unit/out/refcount/immutable_unsigned_arithmetic.rs @@ -13,13 +13,7 @@ pub fn main() { fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(0_u32)); let mut p: Ptr = (a.as_pointer()); - { - match ({ (p.read()) }, &(p)) { - (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { - (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; - }), - } - }; + p.write({ (p.read()).wrapping_add((p.read())) }); return ((p.read()) as i32); } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/inet_pton_ntop.rs b/tests/unit/out/refcount/inet_pton_ntop.rs index 2d455589c9..b855b288c8 100644 --- a/tests/unit/out/refcount/inet_pton_ntop.rs +++ b/tests/unit/out/refcount/inet_pton_ntop.rs @@ -30,13 +30,8 @@ pub fn test_s6_addr_access_0() { ((((elem!(In6Addr::s6_addr(addr.as_pointer()), 0).read()) as i32) == 32) && (((elem!(In6Addr::s6_addr((ap).clone()), 1).read()) as i32) == 1)) ); - { - match ({ 4 }, &(elem!(In6Addr::s6_addr(addr.as_pointer()), 15))) { - (__tmp_1, __tmp_2) => __tmp_2.with_mut(|__tmp_2| { - (*__tmp_2) = (((*__tmp_2) as i32) + (__tmp_1 as i32)) as u8; - }), - } - }; + elem!(In6Addr::s6_addr(addr.as_pointer()), 15) + .write({ (((elem!(In6Addr::s6_addr(addr.as_pointer()), 15).read()) as i32) + 4) as u8 }); elem!(In6Addr::s6_addr((ap).clone()), 15).with_mut(|__v| __v.postfix_inc()); assert!((((elem!(In6Addr::s6_addr(addr.as_pointer()), 15).read()) as i32) == 6)); let mut bytes: Ptr = In6Addr::s6_addr(addr.as_pointer()); @@ -46,9 +41,9 @@ pub fn test_s6_addr_access_0() { fourth.write(8_u8); assert!((((elem!(In6Addr::s6_addr(addr.as_pointer()), 3).read()) as i32) == 8)); { - let mut __tmp_3 = { (In6Addr::s6_addr((ap).clone())).to_any() }; - __tmp_3.memcpy(&(loopback.decay()).to_any(), 16_usize); - (__tmp_3).clone() + let mut __tmp_1 = { (In6Addr::s6_addr((ap).clone())).to_any() }; + __tmp_1.memcpy(&(loopback.decay()).to_any(), 16_usize); + (__tmp_1).clone() }; assert!( ((In6Addr::s6_addr(addr.as_pointer())) @@ -66,14 +61,14 @@ fn main_0() -> i32 { let buf: Value> = Rc::new(RefCell::new((0..16).map(|_| 0_u8).collect::>())); assert!( ({ - let mut __tmp_4 = { (buf.decay()).to_any() }; + let mut __tmp_2 = { (buf.decay()).to_any() }; if libc::AF_INET == libc::AF_INET { // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"1.2.3.4").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_4 + __tmp_2 .reinterpret_cast::() .with_slice_mut(4, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -85,7 +80,7 @@ fn main_0() -> i32 { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_4 + __tmp_2 .reinterpret_cast::() .with_slice_mut(16, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -108,14 +103,14 @@ fn main_0() -> i32 { ); assert!( ({ - let mut __tmp_5 = { (buf.decay()).to_any() }; + let mut __tmp_3 = { (buf.decay()).to_any() }; if libc::AF_INET == libc::AF_INET { // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"999.1.1.1").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_5 + __tmp_3 .reinterpret_cast::() .with_slice_mut(4, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -127,7 +122,7 @@ fn main_0() -> i32 { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_5 + __tmp_3 .reinterpret_cast::() .with_slice_mut(16, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -142,14 +137,14 @@ fn main_0() -> i32 { ); assert!( ({ - let mut __tmp_6 = { (buf.decay()).to_any() }; + let mut __tmp_4 = { (buf.decay()).to_any() }; if libc::AF_INET == libc::AF_INET { // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"not an ip").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_6 + __tmp_4 .reinterpret_cast::() .with_slice_mut(4, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -161,7 +156,7 @@ fn main_0() -> i32 { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_6 + __tmp_4 .reinterpret_cast::() .with_slice_mut(16, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -176,14 +171,14 @@ fn main_0() -> i32 { ); assert!( ({ - let mut __tmp_7 = { (buf.decay()).to_any() }; + let mut __tmp_5 = { (buf.decay()).to_any() }; if libc::AF_INET6 == libc::AF_INET { // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"::1").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_7 + __tmp_5 .reinterpret_cast::() .with_slice_mut(4, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -195,7 +190,7 @@ fn main_0() -> i32 { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_7 + __tmp_5 .reinterpret_cast::() .with_slice_mut(16, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -216,14 +211,14 @@ fn main_0() -> i32 { ); assert!( ({ - let mut __tmp_8 = { (buf.decay()).to_any() }; + let mut __tmp_6 = { (buf.decay()).to_any() }; if libc::AF_INET6 == libc::AF_INET { // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"2001:db8::5").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_8 + __tmp_6 .reinterpret_cast::() .with_slice_mut(4, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -235,7 +230,7 @@ fn main_0() -> i32 { str::from_utf8(__s).ok()?.parse::().ok() }) { Some(__ip) => { - __tmp_8 + __tmp_6 .reinterpret_cast::() .with_slice_mut(16, |__s| __s.copy_from_slice(&__ip.octets())); 1 @@ -261,15 +256,15 @@ fn main_0() -> i32 { assert!( ({ let mut __it1 = { - let mut __tmp_9 = { (four.decay()).to_any() }; - let mut __tmp_10 = { text.decay() }; + let mut __tmp_7 = { (four.decay()).to_any() }; + let mut __tmp_8 = { text.decay() }; let __text = if libc::AF_INET == libc::AF_INET { - let __b: [u8; 4] = __tmp_9 + let __b: [u8; 4] = __tmp_7 .reinterpret_cast::() .with_slice(4, |__s| __s.try_into().unwrap()); Some(std::net::Ipv4Addr::from(__b).to_string()) } else if libc::AF_INET == libc::AF_INET6 { - let __b: [u8; 16] = __tmp_9 + let __b: [u8; 16] = __tmp_7 .reinterpret_cast::() .with_slice(16, |__s| __s.try_into().unwrap()); Some(std::net::Ipv6Addr::from(__b).to_string()) @@ -282,9 +277,9 @@ fn main_0() -> i32 { < (::std::mem::size_of::<[i8; 64]>() as libc::socklen_t) => { let __n = __s.len(); - __tmp_10.write_c_bytes(__s.as_bytes()); - elem!(__tmp_10, __n).write(0); - (__tmp_10).clone() + __tmp_8.write_c_bytes(__s.as_bytes()); + elem!(__tmp_8, __n).write(0); + (__tmp_8).clone() } Some(_) => { libcc2rs::cpp2rust_errno().write(::libc::ENOSPC); @@ -315,15 +310,15 @@ fn main_0() -> i32 { assert!( ({ let mut __it1 = { - let mut __tmp_11 = { (sixteen.decay()).to_any() }; - let mut __tmp_12 = { text.decay() }; + let mut __tmp_9 = { (sixteen.decay()).to_any() }; + let mut __tmp_10 = { text.decay() }; let __text = if libc::AF_INET6 == libc::AF_INET { - let __b: [u8; 4] = __tmp_11 + let __b: [u8; 4] = __tmp_9 .reinterpret_cast::() .with_slice(4, |__s| __s.try_into().unwrap()); Some(std::net::Ipv4Addr::from(__b).to_string()) } else if libc::AF_INET6 == libc::AF_INET6 { - let __b: [u8; 16] = __tmp_11 + let __b: [u8; 16] = __tmp_9 .reinterpret_cast::() .with_slice(16, |__s| __s.try_into().unwrap()); Some(std::net::Ipv6Addr::from(__b).to_string()) @@ -336,9 +331,9 @@ fn main_0() -> i32 { < (::std::mem::size_of::<[i8; 64]>() as libc::socklen_t) => { let __n = __s.len(); - __tmp_12.write_c_bytes(__s.as_bytes()); - elem!(__tmp_12, __n).write(0); - (__tmp_12).clone() + __tmp_10.write_c_bytes(__s.as_bytes()); + elem!(__tmp_10, __n).write(0); + (__tmp_10).clone() } Some(_) => { libcc2rs::cpp2rust_errno().write(::libc::ENOSPC); @@ -366,15 +361,15 @@ fn main_0() -> i32 { ); assert!( (({ - let mut __tmp_13 = { (four.decay()).to_any() }; - let mut __tmp_14 = { text.decay() }; + let mut __tmp_11 = { (four.decay()).to_any() }; + let mut __tmp_12 = { text.decay() }; let __text = if libc::AF_INET == libc::AF_INET { - let __b: [u8; 4] = __tmp_13 + let __b: [u8; 4] = __tmp_11 .reinterpret_cast::() .with_slice(4, |__s| __s.try_into().unwrap()); Some(std::net::Ipv4Addr::from(__b).to_string()) } else if libc::AF_INET == libc::AF_INET6 { - let __b: [u8; 16] = __tmp_13 + let __b: [u8; 16] = __tmp_11 .reinterpret_cast::() .with_slice(16, |__s| __s.try_into().unwrap()); Some(std::net::Ipv6Addr::from(__b).to_string()) @@ -384,9 +379,9 @@ fn main_0() -> i32 { match __text { Some(__s) if (__s.len() as u32) < (4 as libc::socklen_t) => { let __n = __s.len(); - __tmp_14.write_c_bytes(__s.as_bytes()); - elem!(__tmp_14, __n).write(0); - (__tmp_14).clone() + __tmp_12.write_c_bytes(__s.as_bytes()); + elem!(__tmp_12, __n).write(0); + (__tmp_12).clone() } Some(_) => { libcc2rs::cpp2rust_errno().write(::libc::ENOSPC); diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index 6cd9cf4d02..6f97f26588 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -221,13 +221,7 @@ fn main_0() -> i32 { k.prefix_inc(); } } - { - match ({ 5 }, &(c)) { - (__tmp_2, __tmp_3) => __tmp_3.with_mut(|__tmp_3| { - (*__tmp_3) = (((*__tmp_3) as i32) + (__tmp_2 as i32)) as i16; - }), - } - }; + c.write({ (((c.read()) as i32) + 5) as i16 }); id.write(11); (*s.borrow_mut()).count = 3; assert!( diff --git a/tests/unit/out/refcount/lambda_generic.rs b/tests/unit/out/refcount/lambda_generic.rs index 55edb96118..dd8ba5dac1 100644 --- a/tests/unit/out/refcount/lambda_generic.rs +++ b/tests/unit/out/refcount/lambda_generic.rs @@ -55,13 +55,7 @@ fn main_0() -> i32 { }; }, |mut x: u32, mut y: u32| { - { - match ({ (x).wrapping_mul(y) }, &(total)) { - (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { - (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as i32; - }), - } - }; + total.write({ (((total.read()) as u32).wrapping_add((x).wrapping_mul(y))) as i32 }); } ))); ({ (*accumulate.borrow()).spec::(0).call(2, 3) }); diff --git a/tests/unit/out/refcount/lambda_generic_explicit_args.rs b/tests/unit/out/refcount/lambda_generic_explicit_args.rs index a80638a898..0933e93300 100644 --- a/tests/unit/out/refcount/lambda_generic_explicit_args.rs +++ b/tests/unit/out/refcount/lambda_generic_explicit_args.rs @@ -27,36 +27,22 @@ fn main_0() -> i32 { let total: Ptr = total.as_pointer(); }, || { - { - match ( - { - (::std::mem::size_of::() as usize) - .wrapping_add((::std::mem::size_of::() as usize)) - }, - &(total), - ) { - (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { - (*__tmp_1) = - (((*__tmp_1) as usize).wrapping_add((__tmp_0 as usize))) as i32; - }), - } - }; + total.write({ + (((total.read()) as usize).wrapping_add( + ((::std::mem::size_of::() as usize) + .wrapping_add((::std::mem::size_of::() as usize)) + as usize), + )) as i32 + }); }, || { - { - match ( - { - (::std::mem::size_of::() as usize) - .wrapping_add((::std::mem::size_of::() as usize)) - }, - &(total), - ) { - (__tmp_2, __tmp_3) => __tmp_3.with_mut(|__tmp_3| { - (*__tmp_3) = - (((*__tmp_3) as usize).wrapping_add((__tmp_2 as usize))) as i32; - }), - } - }; + total.write({ + (((total.read()) as usize).wrapping_add( + ((::std::mem::size_of::() as usize) + .wrapping_add((::std::mem::size_of::() as usize)) + as usize), + )) as i32 + }); } ))); ({ (*tally.borrow()).spec::(0).call() }); diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index 4a7631ba90..6942bd5626 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -76,44 +76,17 @@ fn main_0() -> i32 { (__tmp_0,) => ({ (*m.borrow_mut()).subscript(__tmp_0, || 0_i32) }), } .write(10); - { - match ( - { ((copies_0.with(|rc| *rc.borrow()) == 1) as i32) }, - &mut (ok), - ) { - (__tmp_1, __tmp_2) => { - (*__tmp_2) = (((*__tmp_2) as i32) & (__tmp_1 as i32)) != 0; - } - } - }; + ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == 1) as i32)) != 0 }; match (b.as_pointer(),) { - (__tmp_3,) => ({ (*m.borrow_mut()).subscript(__tmp_3, || 0_i32) }), + (__tmp_1,) => ({ (*m.borrow_mut()).subscript(__tmp_1, || 0_i32) }), } .write(20); - { - match ( - { ((copies_0.with(|rc| *rc.borrow()) == 2) as i32) }, - &mut (ok), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) != 0; - } - } - }; + ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; match (a.as_pointer(),) { - (__tmp_6,) => ({ (*m.borrow_mut()).subscript(__tmp_6, || 0_i32) }), + (__tmp_2,) => ({ (*m.borrow_mut()).subscript(__tmp_2, || 0_i32) }), } .write(11); - { - match ( - { ((copies_0.with(|rc| *rc.borrow()) == 2) as i32) }, - &mut (ok), - ) { - (__tmp_7, __tmp_8) => { - (*__tmp_8) = (((*__tmp_8) as i32) & (__tmp_7 as i32)) != 0; - } - } - }; + ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; { match ( { @@ -129,8 +102,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_9, __tmp_10) => { - (*__tmp_10) = (((*__tmp_10) as i32) & (__tmp_9 as i32)) != 0; + (__tmp_3, __tmp_4) => { + (*__tmp_4) = (((*__tmp_4) as i32) & (__tmp_3 as i32)) != 0; } } }; @@ -150,76 +123,52 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_11, __tmp_12) => { - (*__tmp_12) = (((*__tmp_12) as i32) & (__tmp_11 as i32)) != 0; - } - } - }; - { - match ( - { ((copies_0.with(|rc| *rc.borrow()) == 2) as i32) }, - &mut (ok), - ) { - (__tmp_13, __tmp_14) => { - (*__tmp_14) = (((*__tmp_14) as i32) & (__tmp_13 as i32)) != 0; + (__tmp_5, __tmp_6) => { + (*__tmp_6) = (((*__tmp_6) as i32) & (__tmp_5 as i32)) != 0; } } }; + ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; match (Rc::new(RefCell::new(({ make_key_3(4) }))).as_pointer(),) { - (__tmp_15,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_15, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_7,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_7, |__k| cpp_move!(__k), || 0_i32) }) } } .write(40); match (Rc::new(RefCell::new(({ make_key_3(4) }))).as_pointer(),) { - (__tmp_16,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_16, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_8,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_8, |__k| cpp_move!(__k), || 0_i32) }) } } .write(41); - { - match ( - { - ((((made_2.with(|rc| *rc.borrow()) == 2) && (moves_1.with(|rc| *rc.borrow()) == 1)) - && (copies_0.with(|rc| *rc.borrow()) == 2)) as i32) - }, - &mut (ok), - ) { - (__tmp_17, __tmp_18) => { - (*__tmp_18) = (((*__tmp_18) as i32) & (__tmp_17 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & ((((made_2.with(|rc| *rc.borrow()) == 2) && (moves_1.with(|rc| *rc.borrow()) == 1)) + && (copies_0.with(|rc| *rc.borrow()) == 2)) as i32)) + != 0 }; match (c.as_pointer(),) { - (__tmp_19,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_19, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_9,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_9, |__k| cpp_move!(__k), || 0_i32) }) } } .write(30); match (c.as_pointer(),) { - (__tmp_20,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_20, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_10,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_10, |__k| cpp_move!(__k), || 0_i32) }) } } .write(31); - { - match ( - { - ((((moves_1.with(|rc| *rc.borrow()) == 2) - && (copies_0.with(|rc| *rc.borrow()) == 2)) - && ({ (*c.borrow()).k } == 3)) as i32) - }, - &mut (ok), - ) { - (__tmp_21, __tmp_22) => { - (*__tmp_22) = (((*__tmp_22) as i32) & (__tmp_21 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & ((((moves_1.with(|rc| *rc.borrow()) == 2) && (copies_0.with(|rc| *rc.borrow()) == 2)) + && ({ (*c.borrow()).k } == 3)) as i32)) + != 0 }; { match ({ (((*m.borrow()).len() == 4_usize) as i32) }, &mut (ok)) { - (__tmp_23, __tmp_24) => { - (*__tmp_24) = (((*__tmp_24) as i32) & (__tmp_23 as i32)) != 0; + (__tmp_11, __tmp_12) => { + (*__tmp_12) = (((*__tmp_12) as i32) & (__tmp_11 as i32)) != 0; } } }; @@ -233,7 +182,7 @@ fn main_0() -> i32 { .0 .as_pointer(),) { - (__tmp_25,) => ({ (*m.borrow_mut()).subscript(__tmp_25, || 0_i32) }), + (__tmp_13,) => ({ (*m.borrow_mut()).subscript(__tmp_13, || 0_i32) }), } .with_mut(|__v| *__v = *__v + 1) }; @@ -242,15 +191,15 @@ fn main_0() -> i32 { { (((copies_0.with(|rc| *rc.borrow()) == 2) && ((match (a.as_pointer(),) { - (__tmp_28,) => ({ (*m.borrow_mut()).subscript(__tmp_28, || 0_i32) }), + (__tmp_16,) => ({ (*m.borrow_mut()).subscript(__tmp_16, || 0_i32) }), } .read()) == 12)) as i32) }, &mut (ok), ) { - (__tmp_26, __tmp_27) => { - (*__tmp_27) = (((*__tmp_27) as i32) & (__tmp_26 as i32)) != 0; + (__tmp_14, __tmp_15) => { + (*__tmp_15) = (((*__tmp_15) as i32) & (__tmp_14 as i32)) != 0; } } }; @@ -263,21 +212,12 @@ fn main_0() -> i32 { .0 .as_pointer()); match (Rc::new(RefCell::new(Key::new({ 0 }))).as_pointer(),) { - (__tmp_29,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_29, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_17,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_17, |__k| cpp_move!(__k), || 0_i32) }) } } .write(0); - { - match ( - { ((moves_1.with(|rc| *rc.borrow()) == 3) as i32) }, - &mut (ok), - ) { - (__tmp_30, __tmp_31) => { - (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; - } - } - }; + ok = { ((ok as i32) & ((moves_1.with(|rc| *rc.borrow()) == 3) as i32)) != 0 }; { match ( { @@ -293,36 +233,27 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_32, __tmp_33) => { - (*__tmp_33) = (((*__tmp_33) as i32) & (__tmp_32 as i32)) != 0; + (__tmp_18, __tmp_19) => { + (*__tmp_19) = (((*__tmp_19) as i32) & (__tmp_18 as i32)) != 0; } } }; let n: Value, Value)>> = Rc::new(RefCell::new((*m.borrow()).clone())); - { - match ( - { ((copies_0.with(|rc| *rc.borrow()) == (2 + 5)) as i32) }, - &mut (ok), - ) { - (__tmp_34, __tmp_35) => { - (*__tmp_35) = (((*__tmp_35) as i32) & (__tmp_34 as i32)) != 0; - } - } - }; + ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == (2 + 5)) as i32)) != 0 }; { match ( { ((((*n.borrow()).len() == 5_usize) && ((match (a.as_pointer(),) { - (__tmp_38,) => ({ (*n.borrow_mut()).subscript(__tmp_38, || 0_i32) }), + (__tmp_22,) => ({ (*n.borrow_mut()).subscript(__tmp_22, || 0_i32) }), } .read()) == 12)) as i32) }, &mut (ok), ) { - (__tmp_36, __tmp_37) => { - (*__tmp_37) = (((*__tmp_37) as i32) & (__tmp_36 as i32)) != 0; + (__tmp_20, __tmp_21) => { + (*__tmp_21) = (((*__tmp_21) as i32) & (__tmp_20 as i32)) != 0; } } }; @@ -336,8 +267,8 @@ fn main_0() -> i32 { { ((Map::erase_key(m.as_pointer(), &b.as_pointer()) == 1_usize) as i32) }, &mut (ok), ) { - (__tmp_39, __tmp_40) => { - (*__tmp_40) = (((*__tmp_40) as i32) & (__tmp_39 as i32)) != 0; + (__tmp_23, __tmp_24) => { + (*__tmp_24) = (((*__tmp_24) as i32) & (__tmp_23 as i32)) != 0; } } }; @@ -346,8 +277,8 @@ fn main_0() -> i32 { { ((Map::erase_key(m.as_pointer(), &b.as_pointer()) == 0_usize) as i32) }, &mut (ok), ) { - (__tmp_41, __tmp_42) => { - (*__tmp_42) = (((*__tmp_42) as i32) & (__tmp_41 as i32)) != 0; + (__tmp_25, __tmp_26) => { + (*__tmp_26) = (((*__tmp_26) as i32) & (__tmp_25 as i32)) != 0; } } }; @@ -367,31 +298,24 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_43, __tmp_44) => { - (*__tmp_44) = (((*__tmp_44) as i32) & (__tmp_43 as i32)) != 0; + (__tmp_27, __tmp_28) => { + (*__tmp_28) = (((*__tmp_28) as i32) & (__tmp_27 as i32)) != 0; } } }; - { - match ( - { - (((copies_0.with(|rc| *rc.borrow()) == 7) && (moves_1.with(|rc| *rc.borrow()) == 3)) - as i32) - }, - &mut (ok), - ) { - (__tmp_45, __tmp_46) => { - (*__tmp_46) = (((*__tmp_46) as i32) & (__tmp_45 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & (((copies_0.with(|rc| *rc.borrow()) == 7) && (moves_1.with(|rc| *rc.borrow()) == 3)) + as i32)) + != 0 }; { match ( { ((((*m.borrow()).len() == 2_usize) && ((*n.borrow()).len() == 5_usize)) as i32) }, &mut (ok), ) { - (__tmp_47, __tmp_48) => { - (*__tmp_48) = (((*__tmp_48) as i32) & (__tmp_47 as i32)) != 0; + (__tmp_29, __tmp_30) => { + (*__tmp_30) = (((*__tmp_30) as i32) & (__tmp_29 as i32)) != 0; } } }; @@ -407,25 +331,12 @@ fn main_0() -> i32 { (*(*entry.upgrade().deref()).1.borrow()) }); } - { - match ({ ((sum == ((3 * 31) + (4 * 41))) as i32) }, &mut (ok)) { - (__tmp_49, __tmp_50) => { - (*__tmp_50) = (((*__tmp_50) as i32) & (__tmp_49 as i32)) != 0; - } - } - }; - { - match ( - { - (((copies_0.with(|rc| *rc.borrow()) == 7) && (moves_1.with(|rc| *rc.borrow()) == 3)) - as i32) - }, - &mut (ok), - ) { - (__tmp_51, __tmp_52) => { - (*__tmp_52) = (((*__tmp_52) as i32) & (__tmp_51 as i32)) != 0; - } - } + ok = { ((ok as i32) & ((sum == ((3 * 31) + (4 * 41))) as i32)) != 0 }; + ok = { + ((ok as i32) + & (((copies_0.with(|rc| *rc.borrow()) == 7) && (moves_1.with(|rc| *rc.borrow()) == 3)) + as i32)) + != 0 }; printf!( b"%d %d %d\n", diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index 8368d10990..5cd38120b9 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -91,16 +91,7 @@ fn main_0() -> i32 { let mut a_value: Ptr = ((*({ (*a_it.borrow()).iter_deref() }).upgrade().deref()) .1 .as_pointer()); - { - match ( - { ((default_constructions_0.with(|rc| *rc.borrow()) == 1) as i32) }, - &mut (ok), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = (((*__tmp_3) as i32) & (__tmp_2 as i32)) != 0; - } - } - }; + ok = { ((ok as i32) & ((default_constructions_0.with(|rc| *rc.borrow()) == 1) as i32)) != 0 }; let b: Ptr = ({ (*distinct.borrow_mut()).subscript(distinct_b.as_pointer(), || ::default()) }); field!(b, value).write(22); @@ -108,42 +99,22 @@ fn main_0() -> i32 { Rc::new(RefCell::new(distinct.as_pointer().with( |__m: &Map, Value)>| __m.find(&distinct_b.as_pointer()), ))); - { - match ( - { ((default_constructions_0.with(|rc| *rc.borrow()) == 2) as i32) }, - &mut (ok), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) != 0; - } - } - }; + ok = { ((ok as i32) & ((default_constructions_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; { match ( { (((*distinct.borrow()).len() == 2_usize) as i32) }, &mut (ok), ) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as i32) & (__tmp_6 as i32)) != 0; - } - } - }; - { - match ({ (({ (a).clone() } != { (b).clone() }) as i32) }, &mut (ok)) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as i32) & (__tmp_8 as i32)) != 0; + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (((*__tmp_3) as i32) & (__tmp_2 as i32)) != 0; } } }; - { - match ( - { (((a.with(|__s| __s.value) == 11) && (b.with(|__s| __s.value) == 22)) as i32) }, - &mut (ok), - ) { - (__tmp_10, __tmp_11) => { - (*__tmp_11) = (((*__tmp_11) as i32) & (__tmp_10 as i32)) != 0; - } - } + ok = { ((ok as i32) & (({ (a).clone() } != { (b).clone() }) as i32)) != 0 }; + ok = { + ((ok as i32) + & (((a.with(|__s| __s.value) == 11) && (b.with(|__s| __s.value) == 22)) as i32)) + != 0 }; { match ( @@ -157,8 +128,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = (((*__tmp_13) as i32) & (__tmp_12 as i32)) != 0; + (__tmp_4, __tmp_5) => { + (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) != 0; } } }; @@ -174,8 +145,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_14, __tmp_15) => { - (*__tmp_15) = (((*__tmp_15) as i32) & (__tmp_14 as i32)) != 0; + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as i32) & (__tmp_6 as i32)) != 0; } } }; @@ -190,8 +161,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_16, __tmp_17) => { - (*__tmp_17) = (((*__tmp_17) as i32) & (__tmp_16 as i32)) != 0; + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as i32) & (__tmp_8 as i32)) != 0; } } }; @@ -206,8 +177,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_18, __tmp_19) => { - (*__tmp_19) = (((*__tmp_19) as i32) & (__tmp_18 as i32)) != 0; + (__tmp_10, __tmp_11) => { + (*__tmp_11) = (((*__tmp_11) as i32) & (__tmp_10 as i32)) != 0; } } }; @@ -219,8 +190,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = (((*__tmp_21) as i32) & (__tmp_20 as i32)) != 0; + (__tmp_12, __tmp_13) => { + (*__tmp_13) = (((*__tmp_13) as i32) & (__tmp_12 as i32)) != 0; } } }; @@ -234,8 +205,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_22, __tmp_23) => { - (*__tmp_23) = (((*__tmp_23) as i32) & (__tmp_22 as i32)) != 0; + (__tmp_14, __tmp_15) => { + (*__tmp_15) = (((*__tmp_15) as i32) & (__tmp_14 as i32)) != 0; } } }; @@ -250,45 +221,25 @@ fn main_0() -> i32 { ) { let entry: Ptr<(Value, Value)> = entry.iter_deref(); if (distinct_count == 0_usize) { - { - match ( - { - ((({ (*(*entry.upgrade().deref()).0.borrow()).order } == 1) - && ({ (*(*entry.upgrade().deref()).1.borrow()).value } == 11)) - as i32) - }, - &mut (ok), - ) { - (__tmp_24, __tmp_25) => { - (*__tmp_25) = (((*__tmp_25) as i32) & (__tmp_24 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & ((({ (*(*entry.upgrade().deref()).0.borrow()).order } == 1) + && ({ (*(*entry.upgrade().deref()).1.borrow()).value } == 11)) + as i32)) + != 0 }; } else if (distinct_count == 1_usize) { - { - match ( - { - ((({ (*(*entry.upgrade().deref()).0.borrow()).order } == 2) - && ({ (*(*entry.upgrade().deref()).1.borrow()).value } == 22)) - as i32) - }, - &mut (ok), - ) { - (__tmp_26, __tmp_27) => { - (*__tmp_27) = (((*__tmp_27) as i32) & (__tmp_26 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & ((({ (*(*entry.upgrade().deref()).0.borrow()).order } == 2) + && ({ (*(*entry.upgrade().deref()).1.borrow()).value } == 22)) + as i32)) + != 0 }; } distinct_count.prefix_inc(); } - { - match ({ ((distinct_count == 2_usize) as i32) }, &mut (ok)) { - (__tmp_28, __tmp_29) => { - (*__tmp_29) = (((*__tmp_29) as i32) & (__tmp_28 as i32)) != 0; - } - } - }; + ok = { ((ok as i32) & ((distinct_count == 2_usize) as i32)) != 0 }; let equivalent_a: Value = Rc::new(RefCell::new(Key { order: 3, identity: 8, @@ -307,8 +258,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_30, __tmp_31) => { - (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; + (__tmp_16, __tmp_17) => { + (*__tmp_17) = (((*__tmp_17) as i32) & (__tmp_16 as i32)) != 0; } } }; @@ -327,38 +278,24 @@ fn main_0() -> i32 { ((*({ (*first_it.borrow()).iter_deref() }).upgrade().deref()) .1 .as_pointer()); - { - match ( - { - ((default_constructions_0.with(|rc| *rc.borrow()) == (before_equivalent + 1)) - as i32) - }, - &mut (ok), - ) { - (__tmp_32, __tmp_33) => { - (*__tmp_33) = (((*__tmp_33) as i32) & (__tmp_32 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_equivalent + 1)) as i32)) + != 0 }; let second: Ptr = ({ (*equivalent.borrow_mut()).subscript(equivalent_b.as_pointer(), || ::default()) }); let mut reused: bool = (default_constructions_0.with(|rc| *rc.borrow()) == (before_equivalent + 1)); - { - match ({ (reused as i32) }, &mut (ok)) { - (__tmp_34, __tmp_35) => { - (*__tmp_35) = (((*__tmp_35) as i32) & (__tmp_34 as i32)) != 0; - } - } - }; + ok = { ((ok as i32) & (reused as i32)) != 0 }; { match ( { (((*equivalent.borrow()).len() == 1_usize) as i32) }, &mut (ok), ) { - (__tmp_36, __tmp_37) => { - (*__tmp_37) = (((*__tmp_37) as i32) & (__tmp_36 as i32)) != 0; + (__tmp_18, __tmp_19) => { + (*__tmp_19) = (((*__tmp_19) as i32) & (__tmp_18 as i32)) != 0; } } }; @@ -374,21 +311,12 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_38, __tmp_39) => { - (*__tmp_39) = (((*__tmp_39) as i32) & (__tmp_38 as i32)) != 0; - } - } - }; - { - match ( - { (({ (first).clone() } == { (second).clone() }) as i32) }, - &mut (ok), - ) { - (__tmp_40, __tmp_41) => { - (*__tmp_41) = (((*__tmp_41) as i32) & (__tmp_40 as i32)) != 0; + (__tmp_20, __tmp_21) => { + (*__tmp_21) = (((*__tmp_21) as i32) & (__tmp_20 as i32)) != 0; } } }; + ok = { ((ok as i32) & (({ (first).clone() } == { (second).clone() }) as i32)) != 0 }; { match ( { @@ -401,8 +329,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_42, __tmp_43) => { - (*__tmp_43) = (((*__tmp_43) as i32) & (__tmp_42 as i32)) != 0; + (__tmp_22, __tmp_23) => { + (*__tmp_23) = (((*__tmp_23) as i32) & (__tmp_22 as i32)) != 0; } } }; @@ -418,8 +346,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_44, __tmp_45) => { - (*__tmp_45) = (((*__tmp_45) as i32) & (__tmp_44 as i32)) != 0; + (__tmp_24, __tmp_25) => { + (*__tmp_25) = (((*__tmp_25) as i32) & (__tmp_24 as i32)) != 0; } } }; @@ -434,8 +362,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_46, __tmp_47) => { - (*__tmp_47) = (((*__tmp_47) as i32) & (__tmp_46 as i32)) != 0; + (__tmp_26, __tmp_27) => { + (*__tmp_27) = (((*__tmp_27) as i32) & (__tmp_26 as i32)) != 0; } } }; @@ -448,8 +376,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_48, __tmp_49) => { - (*__tmp_49) = (((*__tmp_49) as i32) & (__tmp_48 as i32)) != 0; + (__tmp_28, __tmp_29) => { + (*__tmp_29) = (((*__tmp_29) as i32) & (__tmp_28 as i32)) != 0; } } }; @@ -463,29 +391,16 @@ fn main_0() -> i32 { .with(|__m: &Map, Value)>| __m.end()), ) { let entry: Ptr<(Value, Value)> = entry.iter_deref(); - { - match ( - { - ((({ (*(*entry.upgrade().deref()).0.borrow()).order } == 3) - && ({ (*(*entry.upgrade().deref()).1.borrow()).value } == 31)) - as i32) - }, - &mut (ok), - ) { - (__tmp_50, __tmp_51) => { - (*__tmp_51) = (((*__tmp_51) as i32) & (__tmp_50 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & ((({ (*(*entry.upgrade().deref()).0.borrow()).order } == 3) + && ({ (*(*entry.upgrade().deref()).1.borrow()).value } == 31)) + as i32)) + != 0 }; equivalent_count.prefix_inc(); } - { - match ({ ((equivalent_count == 1_usize) as i32) }, &mut (ok)) { - (__tmp_52, __tmp_53) => { - (*__tmp_53) = (((*__tmp_53) as i32) & (__tmp_52 as i32)) != 0; - } - } - }; + ok = { ((ok as i32) & ((equivalent_count == 1_usize) as i32)) != 0 }; } { match ( @@ -497,8 +412,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_54, __tmp_55) => { - (*__tmp_55) = (((*__tmp_55) as i32) & (__tmp_54 as i32)) != 0; + (__tmp_30, __tmp_31) => { + (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; } } }; @@ -509,26 +424,18 @@ fn main_0() -> i32 { let later: Ptr = ({ (*equivalent.borrow_mut()).subscript(later_key.as_pointer(), || ::default()) }); field!(later, value).write(41); - { - match ( - { - ((default_constructions_0.with(|rc| *rc.borrow()) == (before_equivalent + 2)) - as i32) - }, - &mut (ok), - ) { - (__tmp_56, __tmp_57) => { - (*__tmp_57) = (((*__tmp_57) as i32) & (__tmp_56 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_equivalent + 2)) as i32)) + != 0 }; { match ( { (((*equivalent.borrow()).len() == 2_usize) as i32) }, &mut (ok), ) { - (__tmp_58, __tmp_59) => { - (*__tmp_59) = (((*__tmp_59) as i32) & (__tmp_58 as i32)) != 0; + (__tmp_32, __tmp_33) => { + (*__tmp_33) = (((*__tmp_33) as i32) & (__tmp_32 as i32)) != 0; } } }; @@ -545,8 +452,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_60, __tmp_61) => { - (*__tmp_61) = (((*__tmp_61) as i32) & (__tmp_60 as i32)) != 0; + (__tmp_34, __tmp_35) => { + (*__tmp_35) = (((*__tmp_35) as i32) & (__tmp_34 as i32)) != 0; } } }; @@ -561,8 +468,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_62, __tmp_63) => { - (*__tmp_63) = (((*__tmp_63) as i32) & (__tmp_62 as i32)) != 0; + (__tmp_36, __tmp_37) => { + (*__tmp_37) = (((*__tmp_37) as i32) & (__tmp_36 as i32)) != 0; } } }; @@ -574,8 +481,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_64, __tmp_65) => { - (*__tmp_65) = (((*__tmp_65) as i32) & (__tmp_64 as i32)) != 0; + (__tmp_38, __tmp_39) => { + (*__tmp_39) = (((*__tmp_39) as i32) & (__tmp_38 as i32)) != 0; } } }; @@ -605,48 +512,29 @@ fn main_0() -> i32 { ((*({ (*matched_it.borrow()).iter_deref() }).upgrade().deref()) .1 .as_pointer()); - { - match ( - { ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 1)) as i32) }, - &mut (ok), - ) { - (__tmp_66, __tmp_67) => { - (*__tmp_67) = (((*__tmp_67) as i32) & (__tmp_66 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 1)) as i32)) + != 0 }; let matched_again: Ptr = ({ (*matching.borrow_mut()).subscript(matching_b.as_pointer(), || ::default()) }); - { - match ( - { ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 1)) as i32) }, - &mut (ok), - ) { - (__tmp_68, __tmp_69) => { - (*__tmp_69) = (((*__tmp_69) as i32) & (__tmp_68 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 1)) as i32)) + != 0 }; { match ( { (((*matching.borrow()).len() == 1_usize) as i32) }, &mut (ok), ) { - (__tmp_70, __tmp_71) => { - (*__tmp_71) = (((*__tmp_71) as i32) & (__tmp_70 as i32)) != 0; - } - } - }; - { - match ( - { (({ (matched).clone() } == { (matched_again).clone() }) as i32) }, - &mut (ok), - ) { - (__tmp_72, __tmp_73) => { - (*__tmp_73) = (((*__tmp_73) as i32) & (__tmp_72 as i32)) != 0; + (__tmp_40, __tmp_41) => { + (*__tmp_41) = (((*__tmp_41) as i32) & (__tmp_40 as i32)) != 0; } } }; + ok = { ((ok as i32) & (({ (matched).clone() } == { (matched_again).clone() }) as i32)) != 0 }; { match ( { @@ -659,8 +547,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_74, __tmp_75) => { - (*__tmp_75) = (((*__tmp_75) as i32) & (__tmp_74 as i32)) != 0; + (__tmp_42, __tmp_43) => { + (*__tmp_43) = (((*__tmp_43) as i32) & (__tmp_42 as i32)) != 0; } } }; @@ -675,8 +563,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_76, __tmp_77) => { - (*__tmp_77) = (((*__tmp_77) as i32) & (__tmp_76 as i32)) != 0; + (__tmp_44, __tmp_45) => { + (*__tmp_45) = (((*__tmp_45) as i32) & (__tmp_44 as i32)) != 0; } } }; @@ -688,31 +576,26 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_78, __tmp_79) => { - (*__tmp_79) = (((*__tmp_79) as i32) & (__tmp_78 as i32)) != 0; + (__tmp_46, __tmp_47) => { + (*__tmp_47) = (((*__tmp_47) as i32) & (__tmp_46 as i32)) != 0; } } }; let other: Ptr = ({ (*matching.borrow_mut()).subscript(matching_c.as_pointer(), || ::default()) }); field!(other, value).write(61); - { - match ( - { ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 2)) as i32) }, - &mut (ok), - ) { - (__tmp_80, __tmp_81) => { - (*__tmp_81) = (((*__tmp_81) as i32) & (__tmp_80 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 2)) as i32)) + != 0 }; { match ( { (((*matching.borrow()).len() == 2_usize) as i32) }, &mut (ok), ) { - (__tmp_82, __tmp_83) => { - (*__tmp_83) = (((*__tmp_83) as i32) & (__tmp_82 as i32)) != 0; + (__tmp_48, __tmp_49) => { + (*__tmp_49) = (((*__tmp_49) as i32) & (__tmp_48 as i32)) != 0; } } }; @@ -728,8 +611,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_84, __tmp_85) => { - (*__tmp_85) = (((*__tmp_85) as i32) & (__tmp_84 as i32)) != 0; + (__tmp_50, __tmp_51) => { + (*__tmp_51) = (((*__tmp_51) as i32) & (__tmp_50 as i32)) != 0; } } }; @@ -744,8 +627,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_86, __tmp_87) => { - (*__tmp_87) = (((*__tmp_87) as i32) & (__tmp_86 as i32)) != 0; + (__tmp_52, __tmp_53) => { + (*__tmp_53) = (((*__tmp_53) as i32) & (__tmp_52 as i32)) != 0; } } }; @@ -757,8 +640,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_88, __tmp_89) => { - (*__tmp_89) = (((*__tmp_89) as i32) & (__tmp_88 as i32)) != 0; + (__tmp_54, __tmp_55) => { + (*__tmp_55) = (((*__tmp_55) as i32) & (__tmp_54 as i32)) != 0; } } }; diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index ea33c79036..951c394e87 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -80,12 +80,11 @@ impl RefItem { pub fn new_2(counter: Ptr, mut amount: i32) -> Self { let __this: RefItem = Self { value: { - match ({ amount }, &(counter)) { - (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { - (*__tmp_1) = (((*__tmp_1) as i32) + (__tmp_0 as i32)) as i32; - (*__tmp_1).clone() - }), - } + { + let __rhs = { amount }; + counter.with_mut(|__v| *__v = *__v + __rhs) + }; + (counter.read()) }, }; (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); @@ -127,21 +126,21 @@ thread_local!( Value, )> = Rc::new(RefCell::new( match ({ - let __tmp_3 = global_counter_8.with(|v| v.as_pointer()); - __tmp_3.with_mut(|__v| { + let __tmp_1 = global_counter_8.with(|v| v.as_pointer()); + __tmp_1.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_3 + __tmp_1 },) { - (__tmp_2,) => { + (__tmp_0,) => { let (__it, __inserted) = Map::emplace( global_map_6.with(|v| v.as_pointer()), &global_key_7.with(|v| v.as_pointer()), || { ( Rc::new(RefCell::new(global_key_7.with(|v| v.as_pointer()).read())), - Rc::new(RefCell::new((__tmp_2.read()))), + Rc::new(RefCell::new((__tmp_0.read()))), ) }, ); @@ -221,23 +220,23 @@ fn main_0() -> i32 { >, Value, )> = Rc::new(RefCell::new({ - let __tmp_5: Value; + let __tmp_3: Value; if (post != 0) { match ({ - __tmp_5 = Rc::new(RefCell::new( + __tmp_3 = Rc::new(RefCell::new( (*counter.borrow_mut()) .postfix_inc(), )); - __tmp_5.as_pointer() + __tmp_3.as_pointer() },) { - (__tmp_4,) => { + (__tmp_2,) => { let (__it, __inserted) = Map::emplace( m.as_pointer(), &key.as_pointer(), || { - (Rc::new(RefCell::new(key .as_pointer() .read())), Rc::new(RefCell::new((__tmp_4.read()) ))) + (Rc::new(RefCell::new(key .as_pointer() .read())), Rc::new(RefCell::new((__tmp_2.read()) ))) }, ); ( @@ -250,20 +249,20 @@ fn main_0() -> i32 { } } else { match ({ - let __tmp_7 = counter.as_pointer(); - __tmp_7.with_mut(|__v| { + let __tmp_5 = counter.as_pointer(); + __tmp_5.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_7 + __tmp_5 },) { - (__tmp_6,) => { + (__tmp_4,) => { let (__it, __inserted) = Map::emplace( m.as_pointer(), &key.as_pointer(), || { - (Rc::new(RefCell::new(key .as_pointer() .read())), Rc::new(RefCell::new((__tmp_6.read()) ))) + (Rc::new(RefCell::new(key .as_pointer() .read())), Rc::new(RefCell::new((__tmp_4.read()) ))) }, ); ( @@ -278,51 +277,23 @@ fn main_0() -> i32 { })); let mut hit: bool = ((subset & (1 << (*key.borrow()))) != 0); - { - match ( - { - (((*counter.borrow()) - == (initial + 1)) - as i32) - }, - &mut (ok), - ) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as i32) - & (__tmp_8 as i32)) - != 0; - } - } + ok = { + ((ok as i32) + & (((*counter.borrow()) + == (initial + 1)) + as i32)) + != 0 }; - { - match ( - { - ((((*(*result.borrow()).1.borrow()) - as i32) - == (!(hit) as i32)) - as i32) - }, - &mut (ok), - ) { - (__tmp_10, __tmp_11) => { - (*__tmp_11) = (((*__tmp_11) - as i32) - & (__tmp_10 as i32)) - != 0; - } - } + ok = { + ((ok as i32) + & ((((*(*result.borrow()).1.borrow()) + as i32) + == (!(hit) as i32)) + as i32)) + != 0 }; let mut found : bool = (*(*result.borrow()) .0.borrow()) == m .as_pointer() .with(|__m: &Map, Value)>| __m.find(&key .as_pointer() )) ; - { - match ({ (found as i32) }, &mut (ok)) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = (((*__tmp_13) - as i32) - & (__tmp_12 as i32)) - != 0; - } - } - }; + ok = { ((ok as i32) & (found as i32)) != 0 }; { match ( { @@ -339,10 +310,9 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_14, __tmp_15) => { - (*__tmp_15) = (((*__tmp_15) - as i32) - & (__tmp_14 as i32)) + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as i32) + & (__tmp_6 as i32)) != 0; } } @@ -368,10 +338,9 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_16, __tmp_17) => { - (*__tmp_17) = (((*__tmp_17) - as i32) - & (__tmp_16 as i32)) + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as i32) + & (__tmp_8 as i32)) != 0; } } @@ -386,10 +355,10 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_18, __tmp_19) => { - (*__tmp_19) = (((*__tmp_19) + (__tmp_10, __tmp_11) => { + (*__tmp_11) = (((*__tmp_11) as i32) - & (__tmp_18 as i32)) + & (__tmp_10 as i32)) != 0; } } @@ -431,19 +400,15 @@ fn main_0() -> i32 { match ( { { - match ({ 0 }, &mut (*moves_3.with(Value::clone).borrow_mut())) { - (__tmp_22, __tmp_23) => { - (*__tmp_23) = __tmp_22; - (*__tmp_23).clone() - } - } + moves_3.with(|rc| *rc.borrow_mut() = 0); + moves_3.with(|rc| *rc.borrow()) } }, &mut (*copies_2.with(Value::clone).borrow_mut()), ) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = __tmp_20; - (*__tmp_21).clone() + (__tmp_12, __tmp_13) => { + (*__tmp_13) = __tmp_12; + (*__tmp_13).clone() } } } @@ -453,12 +418,12 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_24,) => { + (__tmp_14,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::copy_from({ (__tmp_24).clone() }))), + Rc::new(RefCell::new(Item::copy_from({ (__tmp_14).clone() }))), ) }); ( @@ -468,20 +433,12 @@ fn main_0() -> i32 { } }, )); - { - match ( - { - (((((calls_0.with(|rc| *rc.borrow()) == 1) - && (made_1.with(|rc| *rc.borrow()) == 0)) - && (copies_2.with(|rc| *rc.borrow()) == 0)) - && (moves_3.with(|rc| *rc.borrow()) == 0)) as i32) - }, - &mut (ok), - ) { - (__tmp_25, __tmp_26) => { - (*__tmp_26) = (((*__tmp_26) as i32) & (__tmp_25 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & (((((calls_0.with(|rc| *rc.borrow()) == 1) && (made_1.with(|rc| *rc.borrow()) == 0)) + && (copies_2.with(|rc| *rc.borrow()) == 0)) + && (moves_3.with(|rc| *rc.borrow()) == 0)) as i32)) + != 0 }; { match ( @@ -493,8 +450,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_27, __tmp_28) => { - (*__tmp_28) = (((*__tmp_28) as i32) & (__tmp_27 as i32)) != 0; + (__tmp_15, __tmp_16) => { + (*__tmp_16) = (((*__tmp_16) as i32) & (__tmp_15 as i32)) != 0; } } }; @@ -503,12 +460,12 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_29,) => { + (__tmp_17,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_29).clone() }))), + Rc::new(RefCell::new(Item::move_from({ (__tmp_17).clone() }))), ) }); ( @@ -518,33 +475,18 @@ fn main_0() -> i32 { } }, )); - { - match ( - { - (((((calls_0.with(|rc| *rc.borrow()) == 2) - && (made_1.with(|rc| *rc.borrow()) == 0)) - && (copies_2.with(|rc| *rc.borrow()) == 0)) - && (moves_3.with(|rc| *rc.borrow()) == 0)) as i32) - }, - &mut (ok), - ) { - (__tmp_30, __tmp_31) => { - (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & (((((calls_0.with(|rc| *rc.borrow()) == 2) && (made_1.with(|rc| *rc.borrow()) == 0)) + && (copies_2.with(|rc| *rc.borrow()) == 0)) + && (moves_3.with(|rc| *rc.borrow()) == 0)) as i32)) + != 0 }; - { - match ( - { - (((!(*(*move_hit.borrow()).1.borrow())) && ({ (*source.borrow()).value } == 20)) - as i32) - }, - &mut (ok), - ) { - (__tmp_32, __tmp_33) => { - (*__tmp_33) = (((*__tmp_33) as i32) & (__tmp_32 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & (((!(*(*move_hit.borrow()).1.borrow())) && ({ (*source.borrow()).value } == 20)) + as i32)) + != 0 }; (*key.borrow_mut()).prefix_inc(); let copied: Value<( @@ -552,12 +494,12 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_34,) => { + (__tmp_18,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::copy_from({ (__tmp_34).clone() }))), + Rc::new(RefCell::new(Item::copy_from({ (__tmp_18).clone() }))), ) }); ( @@ -567,20 +509,12 @@ fn main_0() -> i32 { } }, )); - { - match ( - { - (((((calls_0.with(|rc| *rc.borrow()) == 3) - && (made_1.with(|rc| *rc.borrow()) == 0)) - && (copies_2.with(|rc| *rc.borrow()) == 1)) - && (moves_3.with(|rc| *rc.borrow()) == 0)) as i32) - }, - &mut (ok), - ) { - (__tmp_35, __tmp_36) => { - (*__tmp_36) = (((*__tmp_36) as i32) & (__tmp_35 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & (((((calls_0.with(|rc| *rc.borrow()) == 3) && (made_1.with(|rc| *rc.borrow()) == 0)) + && (copies_2.with(|rc| *rc.borrow()) == 1)) + && (moves_3.with(|rc| *rc.borrow()) == 0)) as i32)) + != 0 }; { match ( @@ -592,8 +526,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_37, __tmp_38) => { - (*__tmp_38) = (((*__tmp_38) as i32) & (__tmp_37 as i32)) != 0; + (__tmp_19, __tmp_20) => { + (*__tmp_20) = (((*__tmp_20) as i32) & (__tmp_19 as i32)) != 0; } } }; @@ -603,12 +537,12 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_39,) => { + (__tmp_21,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_39).clone() }))), + Rc::new(RefCell::new(Item::move_from({ (__tmp_21).clone() }))), ) }); ( @@ -618,20 +552,12 @@ fn main_0() -> i32 { } }, )); - { - match ( - { - (((((calls_0.with(|rc| *rc.borrow()) == 4) - && (made_1.with(|rc| *rc.borrow()) == 0)) - && (copies_2.with(|rc| *rc.borrow()) == 1)) - && (moves_3.with(|rc| *rc.borrow()) == 1)) as i32) - }, - &mut (ok), - ) { - (__tmp_40, __tmp_41) => { - (*__tmp_41) = (((*__tmp_41) as i32) & (__tmp_40 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & (((((calls_0.with(|rc| *rc.borrow()) == 4) && (made_1.with(|rc| *rc.borrow()) == 0)) + && (copies_2.with(|rc| *rc.borrow()) == 1)) + && (moves_3.with(|rc| *rc.borrow()) == 1)) as i32)) + != 0 }; { match ( @@ -644,8 +570,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_42, __tmp_43) => { - (*__tmp_43) = (((*__tmp_43) as i32) & (__tmp_42 as i32)) != 0; + (__tmp_22, __tmp_23) => { + (*__tmp_23) = (((*__tmp_23) as i32) & (__tmp_22 as i32)) != 0; } } }; @@ -672,11 +598,11 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ reference_5(counter.as_pointer()) }),) { - (__tmp_44,) => { + (__tmp_24,) => { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(RefItem::new_2({ (__tmp_44).clone() }, { 2 }))), + Rc::new(RefCell::new(RefItem::new_2({ (__tmp_24).clone() }, { 2 }))), ) }); ( @@ -686,19 +612,12 @@ fn main_0() -> i32 { } }, )); - { - match ( - { - (((((calls_0.with(|rc| *rc.borrow()) == 5) && ((*counter.borrow()) == 5)) - && (made_1.with(|rc| *rc.borrow()) == 0)) - && (!(*(*ref_hit.borrow()).1.borrow()))) as i32) - }, - &mut (ok), - ) { - (__tmp_45, __tmp_46) => { - (*__tmp_46) = (((*__tmp_46) as i32) & (__tmp_45 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & (((((calls_0.with(|rc| *rc.borrow()) == 5) && ((*counter.borrow()) == 5)) + && (made_1.with(|rc| *rc.borrow()) == 0)) + && (!(*(*ref_hit.borrow()).1.borrow()))) as i32)) + != 0 }; (*key.borrow_mut()).prefix_inc(); let ref_new: Value<( @@ -706,11 +625,11 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ reference_5(counter.as_pointer()) }),) { - (__tmp_47,) => { + (__tmp_25,) => { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(RefItem::new_2({ (__tmp_47).clone() }, { 2 }))), + Rc::new(RefCell::new(RefItem::new_2({ (__tmp_25).clone() }, { 2 }))), ) }); ( @@ -720,19 +639,12 @@ fn main_0() -> i32 { } }, )); - { - match ( - { - (((((calls_0.with(|rc| *rc.borrow()) == 6) && ((*counter.borrow()) == 7)) - && (made_1.with(|rc| *rc.borrow()) == 1)) - && (*(*ref_new.borrow()).1.borrow())) as i32) - }, - &mut (ok), - ) { - (__tmp_48, __tmp_49) => { - (*__tmp_49) = (((*__tmp_49) as i32) & (__tmp_48 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & (((((calls_0.with(|rc| *rc.borrow()) == 6) && ((*counter.borrow()) == 7)) + && (made_1.with(|rc| *rc.borrow()) == 1)) + && (*(*ref_new.borrow()).1.borrow())) as i32)) + != 0 }; { match ( @@ -746,8 +658,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_50, __tmp_51) => { - (*__tmp_51) = (((*__tmp_51) as i32) & (__tmp_50 as i32)) != 0; + (__tmp_26, __tmp_27) => { + (*__tmp_27) = (((*__tmp_27) as i32) & (__tmp_26 as i32)) != 0; } } }; @@ -757,19 +669,15 @@ fn main_0() -> i32 { match ( { { - match ({ 0 }, &mut (*moves_3.with(Value::clone).borrow_mut())) { - (__tmp_54, __tmp_55) => { - (*__tmp_55) = __tmp_54; - (*__tmp_55).clone() - } - } + moves_3.with(|rc| *rc.borrow_mut() = 0); + moves_3.with(|rc| *rc.borrow()) } }, &mut (*copies_2.with(Value::clone).borrow_mut()), ) { - (__tmp_52, __tmp_53) => { - (*__tmp_53) = __tmp_52; - (*__tmp_53).clone() + (__tmp_28, __tmp_29) => { + (*__tmp_29) = __tmp_28; + (*__tmp_29).clone() } } } @@ -778,18 +686,18 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_57: Value; + let __tmp_31: Value; match ({ - __tmp_57 = Rc::new(RefCell::new(Item::new_1({ 30 }))); - __tmp_57.as_pointer() + __tmp_31 = Rc::new(RefCell::new(Item::new_1({ 30 }))); + __tmp_31.as_pointer() },) { - (__tmp_56,) => { + (__tmp_30,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_56).clone() }))), + Rc::new(RefCell::new(Item::move_from({ (__tmp_30).clone() }))), ) }); ( @@ -799,20 +707,13 @@ fn main_0() -> i32 { } } })); - { - match ( - { - (((((made_1.with(|rc| *rc.borrow()) == 1) - && (copies_2.with(|rc| *rc.borrow()) == 0)) - && (moves_3.with(|rc| *rc.borrow()) == 0)) - && (!(*(*temporary_hit.borrow()).1.borrow()))) as i32) - }, - &mut (ok), - ) { - (__tmp_58, __tmp_59) => { - (*__tmp_59) = (((*__tmp_59) as i32) & (__tmp_58 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & (((((made_1.with(|rc| *rc.borrow()) == 1) + && (copies_2.with(|rc| *rc.borrow()) == 0)) + && (moves_3.with(|rc| *rc.borrow()) == 0)) + && (!(*(*temporary_hit.borrow()).1.borrow()))) as i32)) + != 0 }; (*key.borrow_mut()).prefix_inc(); (*key.borrow_mut()).prefix_inc(); @@ -821,18 +722,18 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_61: Value; + let __tmp_33: Value; match ({ - __tmp_61 = Rc::new(RefCell::new(Item::new_1({ 40 }))); - __tmp_61.as_pointer() + __tmp_33 = Rc::new(RefCell::new(Item::new_1({ 40 }))); + __tmp_33.as_pointer() },) { - (__tmp_60,) => { + (__tmp_32,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_60).clone() }))), + Rc::new(RefCell::new(Item::move_from({ (__tmp_32).clone() }))), ) }); ( @@ -842,20 +743,13 @@ fn main_0() -> i32 { } } })); - { - match ( - { - (((((made_1.with(|rc| *rc.borrow()) == 2) - && (copies_2.with(|rc| *rc.borrow()) == 0)) - && (moves_3.with(|rc| *rc.borrow()) == 1)) - && (*(*temporary_new.borrow()).1.borrow())) as i32) - }, - &mut (ok), - ) { - (__tmp_62, __tmp_63) => { - (*__tmp_63) = (((*__tmp_63) as i32) & (__tmp_62 as i32)) != 0; - } - } + ok = { + ((ok as i32) + & (((((made_1.with(|rc| *rc.borrow()) == 2) + && (copies_2.with(|rc| *rc.borrow()) == 0)) + && (moves_3.with(|rc| *rc.borrow()) == 1)) + && (*(*temporary_new.borrow()).1.borrow())) as i32)) + != 0 }; { match ( @@ -866,8 +760,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_64, __tmp_65) => { - (*__tmp_65) = (((*__tmp_65) as i32) & (__tmp_64 as i32)) != 0; + (__tmp_34, __tmp_35) => { + (*__tmp_35) = (((*__tmp_35) as i32) & (__tmp_34 as i32)) != 0; } } }; diff --git a/tests/unit/out/refcount/map_try_emplace_lvalues.rs b/tests/unit/out/refcount/map_try_emplace_lvalues.rs index ff9bdbbe5b..906db21ba5 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -25,12 +25,11 @@ impl Item { pub fn new_2(counter: Ptr, mut amount: i32) -> Self { let __this: Item = Self { value: { - match ({ amount }, &(counter)) { - (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { - (*__tmp_1) = (((*__tmp_1) as i32) + (__tmp_0 as i32)) as i32; - (*__tmp_1).clone() - }), - } + { + let __rhs = { amount }; + counter.with_mut(|__v| *__v = *__v + __rhs) + }; + (counter.read()) }, }; (*made_0.with(Value::clone).borrow_mut()).prefix_inc(); @@ -180,22 +179,22 @@ thread_local!( Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_4: Value; + let __tmp_2: Value; match ((match { - __tmp_4 = Rc::new(RefCell::new(({ make_temporary_5() }))); - __tmp_4.as_pointer() + __tmp_2 = Rc::new(RefCell::new(({ make_temporary_5() }))); + __tmp_2.as_pointer() } { - __tmp_3 => field_ptr!(__tmp_3, n), + __tmp_1 => field_ptr!(__tmp_1, n), }),) { - (__tmp_2,) => { + (__tmp_0,) => { let (__it, __inserted) = Map::emplace( global_values_7.with(|v| v.as_pointer()), &global_key_8.with(|v| v.as_pointer()), || { ( Rc::new(RefCell::new(global_key_8.with(|v| v.as_pointer()).read())), - Rc::new(RefCell::new((__tmp_2.read()))), + Rc::new(RefCell::new((__tmp_0.read()))), ) }, ); @@ -214,23 +213,23 @@ thread_local!( )> = Rc::new(RefCell::new( match (if global_choose_13.with(|rc| *rc.borrow()) { { - let __tmp_6 = global_a_11.with(|v| v.as_pointer()); - __tmp_6.with_mut(|__v| { + let __tmp_4 = global_a_11.with(|v| v.as_pointer()); + __tmp_4.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_6 + __tmp_4 } } else { { - let __tmp_7 = global_b_12.with(|v| v.as_pointer()); - __tmp_7.with_mut(|__v| { + let __tmp_5 = global_b_12.with(|v| v.as_pointer()); + __tmp_5.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_7 + __tmp_5 } },) { - (__tmp_5,) => { + (__tmp_3,) => { let (__it, __inserted) = Map::emplace( global_values_7.with(|v| v.as_pointer()), &conditional_key_9.with(|v| v.as_pointer()), @@ -239,7 +238,7 @@ thread_local!( Rc::new(RefCell::new( conditional_key_9.with(|v| v.as_pointer()).read(), )), - Rc::new(RefCell::new((__tmp_5.read()))), + Rc::new(RefCell::new((__tmp_3.read()))), ) }, ); @@ -256,24 +255,24 @@ thread_local!( Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_9: Option>; + let mut __tmp_7: Option>; match (field_ptr!( (*{ - __tmp_9 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_9 + __tmp_7 = Some(Rc::new(RefCell::new(Temporary::new()))); + &mut __tmp_7 }) .as_pointer(), n ),) { - (__tmp_8,) => { + (__tmp_6,) => { let (__it, __inserted) = Map::emplace( global_values_7.with(|v| v.as_pointer()), &owned_key_10.with(|v| v.as_pointer()), || { ( Rc::new(RefCell::new(owned_key_10.with(|v| v.as_pointer()).read())), - Rc::new(RefCell::new((__tmp_8.read()))), + Rc::new(RefCell::new((__tmp_6.read()))), ) }, ); @@ -362,20 +361,19 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ receiver_2(m.as_pointer()) }), { - let __tmp_12 = ({ place_3(counter.as_pointer()) }); - __tmp_12.with_mut(|__v| { + let __tmp_10 = ({ place_3(counter.as_pointer()) }); + __tmp_10.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_12 + __tmp_10 }) { - (__tmp_10, __tmp_11) => { - let (__it, __inserted) = - Map::emplace((__tmp_10).clone(), &key.as_pointer(), || { - ( - Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_11).clone() }, { 2 }))), - ) - }); + (__tmp_8, __tmp_9) => { + let (__it, __inserted) = Map::emplace((__tmp_8).clone(), &key.as_pointer(), || { + ( + Rc::new(RefCell::new(key.as_pointer().read())), + Rc::new(RefCell::new(Item::new_2({ (__tmp_9).clone() }, { 2 }))), + ) + }); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -396,18 +394,18 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match ({ - let __tmp_14 = counter.as_pointer(); - __tmp_14.with_mut(|__v| { + let __tmp_12 = counter.as_pointer(); + __tmp_12.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_14 + __tmp_12 },) { - (__tmp_13,) => { + (__tmp_11,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_13).clone() }, { 2 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_11).clone() }, { 2 }))), ) }); ( @@ -428,17 +426,17 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (match ({ 9 }, counter.as_pointer()) { - (__tmp_17, __tmp_16) => { - __tmp_16.write(__tmp_17); - __tmp_16 + (__tmp_15, __tmp_14) => { + __tmp_14.write(__tmp_15); + __tmp_14 } },) { - (__tmp_15,) => { + (__tmp_13,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_15).clone() }, { 2 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_13).clone() }, { 2 }))), ) }); ( @@ -460,17 +458,17 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (match ({ 4 }, counter.as_pointer()) { - (__tmp_20, __tmp_19) => { - __tmp_19.with_mut(|__v| *__v = (((*__v) as i32) + (__tmp_20 as i32)) as i32); - __tmp_19 + (__tmp_18, __tmp_17) => { + __tmp_17.with_mut(|__v| *__v = (((*__v) as i32) + (__tmp_18 as i32)) as i32); + __tmp_17 } },) { - (__tmp_18,) => { + (__tmp_16,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_18).clone() }, { 2 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_16).clone() }, { 2 }))), ) }); ( @@ -500,18 +498,18 @@ fn main_0() -> i32 { let mut index: i32 = 0; (*key.borrow_mut()).prefix_inc(); match ({ - let __tmp_22 = array.decay().offset(index.postfix_inc()); - __tmp_22.with_mut(|__v| { + let __tmp_20 = array.decay().offset(index.postfix_inc()); + __tmp_20.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_22 + __tmp_20 },) { - (__tmp_21,) => { + (__tmp_19,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_21).clone() }, { 3 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_19).clone() }, { 3 }))), ) }); ( @@ -528,17 +526,17 @@ fn main_0() -> i32 { ); (*key.borrow_mut()).prefix_inc(); match (match ({ 5 }, array.decay().offset(index.postfix_inc())) { - (__tmp_25, __tmp_24) => { - __tmp_24.write(__tmp_25); - __tmp_24 + (__tmp_23, __tmp_22) => { + __tmp_22.write(__tmp_23); + __tmp_22 } },) { - (__tmp_23,) => { + (__tmp_21,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_23).clone() }, { 3 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_21).clone() }, { 3 }))), ) }); ( @@ -555,17 +553,17 @@ fn main_0() -> i32 { ); match ( match ({ ((*counter.borrow()) + 1) }, counter.as_pointer()) { - (__tmp_28, __tmp_27) => { - __tmp_27.write(__tmp_28); - __tmp_27 + (__tmp_26, __tmp_25) => { + __tmp_25.write(__tmp_26); + __tmp_25 } }, ) { - (__tmp_26,) => { + (__tmp_24,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_26).clone() }, { 3 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_24).clone() }, { 3 }))), ) }); ( @@ -580,27 +578,27 @@ fn main_0() -> i32 { let mut choose: bool = false; match (if choose { { - let __tmp_30 = a.as_pointer(); - __tmp_30.with_mut(|__v| { + let __tmp_28 = a.as_pointer(); + __tmp_28.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_30 + __tmp_28 } } else { { - let __tmp_31 = b.as_pointer(); - __tmp_31.with_mut(|__v| { + let __tmp_29 = b.as_pointer(); + __tmp_29.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_31 + __tmp_29 } },) { - (__tmp_29,) => { + (__tmp_27,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_29).clone() }, { 3 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_27).clone() }, { 3 }))), ) }); ( @@ -617,27 +615,27 @@ fn main_0() -> i32 { choose = true; match (if choose { { - let __tmp_33 = a.as_pointer(); - __tmp_33.with_mut(|__v| { + let __tmp_31 = a.as_pointer(); + __tmp_31.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_33 + __tmp_31 } } else { { - let __tmp_34 = b.as_pointer(); - __tmp_34.with_mut(|__v| { + let __tmp_32 = b.as_pointer(); + __tmp_32.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_34 + __tmp_32 } },) { - (__tmp_32,) => { + (__tmp_30,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_32).clone() }, { 3 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_30).clone() }, { 3 }))), ) }); ( @@ -656,11 +654,11 @@ fn main_0() -> i32 { counter.as_pointer() },) { - (__tmp_35,) => { + (__tmp_33,) => { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_35).clone() }, { 3 }))), + Rc::new(RefCell::new(Item::new_2({ (__tmp_33).clone() }, { 3 }))), ) }); ( @@ -677,20 +675,20 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (match ({ 1_u32 }, n.as_pointer()) { - (__tmp_38, __tmp_37) => { - __tmp_37.with_mut(|__v| { - *__v = (((*__v) as u32).wrapping_add((__tmp_38 as u32))) as u32 + (__tmp_36, __tmp_35) => { + __tmp_35.with_mut(|__v| { + *__v = (((*__v) as u32).wrapping_add((__tmp_36 as u32))) as u32 }); - __tmp_37 + __tmp_35 } },) { - (__tmp_36,) => { + (__tmp_34,) => { let (__it, __inserted) = Map::emplace(unsigned_map.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new((__tmp_36.read()))), + Rc::new(RefCell::new((__tmp_34.read()))), ) }); ( @@ -719,18 +717,18 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (match ({ 2 }, bytes.decay().offset(index.postfix_inc())) { - (__tmp_41, __tmp_40) => { - __tmp_40.with_mut(|__v| *__v = (((*__v) as i32) + (__tmp_41 as i32)) as u8); - __tmp_40 + (__tmp_39, __tmp_38) => { + __tmp_38.with_mut(|__v| *__v = (((*__v) as i32) + (__tmp_39 as i32)) as u8); + __tmp_38 } },) { - (__tmp_39,) => { + (__tmp_37,) => { let (__it, __inserted) = Map::emplace(unsigned_map.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(((__tmp_39.read()) as u32))), + Rc::new(RefCell::new(((__tmp_37.read()) as u32))), ) }); ( @@ -761,20 +759,20 @@ fn main_0() -> i32 { match ({ Map::erase_key(changed.as_pointer(), &key.as_pointer()); { - let __tmp_43 = effects.as_pointer(); - __tmp_43.with_mut(|__v| { + let __tmp_41 = effects.as_pointer(); + __tmp_41.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_43 + __tmp_41 } },) { - (__tmp_42,) => { + (__tmp_40,) => { let (__it, __inserted) = Map::emplace(changed.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new((__tmp_42.read()))), + Rc::new(RefCell::new((__tmp_40.read()))), ) }); ( @@ -804,20 +802,20 @@ fn main_0() -> i32 { __v.prefix_inc(); }); { - let __tmp_45 = effects.as_pointer(); - __tmp_45.with_mut(|__v| { + let __tmp_43 = effects.as_pointer(); + __tmp_43.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_45 + __tmp_43 } },) { - (__tmp_44,) => { + (__tmp_42,) => { let (__it, __inserted) = Map::emplace(changed.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new((__tmp_44.read()))), + Rc::new(RefCell::new((__tmp_42.read()))), ) }); ( @@ -846,18 +844,18 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (match ({ 1 }, p.as_pointer()) { - (__tmp_48, __tmp_47) => { - __tmp_47.with_mut(|__v| *__v = (*__v).offset((__tmp_48 as isize))); - __tmp_47 + (__tmp_46, __tmp_45) => { + __tmp_45.with_mut(|__v| *__v = (*__v).offset((__tmp_46 as isize))); + __tmp_45 } },) { - (__tmp_46,) => { + (__tmp_44,) => { let (__it, __inserted) = Map::emplace(pointers.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new((__tmp_46.read()))), + Rc::new(RefCell::new((__tmp_44.read()))), ) }); ( @@ -906,19 +904,19 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match ({ - let __tmp_50 = moved.as_pointer(); - __tmp_50.with_mut(|__v| { + let __tmp_48 = moved.as_pointer(); + __tmp_48.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_50 + __tmp_48 },) { - (__tmp_49,) => { + (__tmp_47,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(0), || { ( Rc::new(RefCell::new(keys.decay().offset(0).read())), - Rc::new(RefCell::new((__tmp_49.read()))), + Rc::new(RefCell::new((__tmp_47.read()))), ) }); ( @@ -933,19 +931,19 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match ({ - let __tmp_52 = forwarded.as_pointer(); - __tmp_52.with_mut(|__v| { + let __tmp_50 = forwarded.as_pointer(); + __tmp_50.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_52 + __tmp_50 },) { - (__tmp_51,) => { + (__tmp_49,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(1), || { ( Rc::new(RefCell::new(keys.decay().offset(1).read())), - Rc::new(RefCell::new((__tmp_51.read()))), + Rc::new(RefCell::new((__tmp_49.read()))), ) }); ( @@ -960,19 +958,19 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match ({ - let __tmp_54 = xvalue.as_pointer(); - __tmp_54.with_mut(|__v| { + let __tmp_52 = xvalue.as_pointer(); + __tmp_52.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_54 + __tmp_52 },) { - (__tmp_53,) => { + (__tmp_51,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(2), || { ( Rc::new(RefCell::new(keys.decay().offset(2).read())), - Rc::new(RefCell::new((__tmp_53.read()))), + Rc::new(RefCell::new((__tmp_51.read()))), ) }); ( @@ -987,19 +985,19 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match ({ - let __tmp_56 = lvalue.as_pointer(); - __tmp_56.with_mut(|__v| { + let __tmp_54 = lvalue.as_pointer(); + __tmp_54.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_56 + __tmp_54 },) { - (__tmp_55,) => { + (__tmp_53,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(3), || { ( Rc::new(RefCell::new(keys.decay().offset(3).read())), - Rc::new(RefCell::new((__tmp_55.read()))), + Rc::new(RefCell::new((__tmp_53.read()))), ) }); ( @@ -1014,18 +1012,18 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (match ({ 5 }, assigned.as_pointer()) { - (__tmp_59, __tmp_58) => { - __tmp_58.write(__tmp_59); - __tmp_58 + (__tmp_57, __tmp_56) => { + __tmp_56.write(__tmp_57); + __tmp_56 } },) { - (__tmp_57,) => { + (__tmp_55,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(4), || { ( Rc::new(RefCell::new(keys.decay().offset(4).read())), - Rc::new(RefCell::new((__tmp_57.read()))), + Rc::new(RefCell::new((__tmp_55.read()))), ) }); ( @@ -1040,20 +1038,20 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (match ({ 1 }, nested.as_pointer()) { - (__tmp_62, __tmp_61) => { - __tmp_61.with_mut(|__v| { - *__v = (((*__v) as i32) + (__tmp_62 as i32)) as i32 + (__tmp_60, __tmp_59) => { + __tmp_59.with_mut(|__v| { + *__v = (((*__v) as i32) + (__tmp_60 as i32)) as i32 }); - __tmp_61 + __tmp_59 } },) { - (__tmp_60,) => { + (__tmp_58,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(5), || { ( Rc::new(RefCell::new(keys.decay().offset(5).read())), - Rc::new(RefCell::new((__tmp_60.read()))), + Rc::new(RefCell::new((__tmp_58.read()))), ) }); ( @@ -1141,23 +1139,23 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new( match (if (choose != 0) { { - let __tmp_64 = a.as_pointer(); - __tmp_64.with_mut(|__v| { + let __tmp_62 = a.as_pointer(); + __tmp_62.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_64 + __tmp_62 } } else { { - let __tmp_65 = b.as_pointer(); - __tmp_65.with_mut(|__v| { + let __tmp_63 = b.as_pointer(); + __tmp_63.with_mut(|__v| { __v.prefix_inc(); }); - __tmp_65 + __tmp_63 } },) { - (__tmp_63,) => { + (__tmp_61,) => { let (__it, __inserted) = Map::emplace( selected.as_pointer(), &keys.decay().offset(0), @@ -1167,7 +1165,7 @@ fn main_0() -> i32 { keys.decay().offset(0).read(), )), Rc::new(RefCell::new(Item::new_2( - { (__tmp_63).clone() }, + { (__tmp_61).clone() }, { 2 }, ))), ) @@ -1186,21 +1184,21 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new( match (if (choose != 0) { (match ({ 5 }, c.as_pointer()) { - (__tmp_68, __tmp_67) => { - __tmp_67.write(__tmp_68); - __tmp_67 + (__tmp_66, __tmp_65) => { + __tmp_65.write(__tmp_66); + __tmp_65 } }) } else { (match ({ 6 }, d.as_pointer()) { - (__tmp_70, __tmp_69) => { - __tmp_69.write(__tmp_70); - __tmp_69 + (__tmp_68, __tmp_67) => { + __tmp_67.write(__tmp_68); + __tmp_67 } }) },) { - (__tmp_66,) => { + (__tmp_64,) => { let (__it, __inserted) = Map::emplace( selected.as_pointer(), &keys.decay().offset(1), @@ -1210,7 +1208,7 @@ fn main_0() -> i32 { keys.decay().offset(1).read(), )), Rc::new(RefCell::new(Item::new_2( - { (__tmp_66).clone() }, + { (__tmp_64).clone() }, { 2 }, ))), ) @@ -1229,25 +1227,25 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new( match (if (choose != 0) { (match ({ 1 }, e.as_pointer()) { - (__tmp_73, __tmp_72) => { - __tmp_72.with_mut(|__v| { - *__v = (((*__v) as i32) + (__tmp_73 as i32)) as i32 + (__tmp_71, __tmp_70) => { + __tmp_70.with_mut(|__v| { + *__v = (((*__v) as i32) + (__tmp_71 as i32)) as i32 }); - __tmp_72 + __tmp_70 } }) } else { (match ({ 2 }, f.as_pointer()) { - (__tmp_75, __tmp_74) => { - __tmp_74.with_mut(|__v| { - *__v = (((*__v) as i32) + (__tmp_75 as i32)) as i32 + (__tmp_73, __tmp_72) => { + __tmp_72.with_mut(|__v| { + *__v = (((*__v) as i32) + (__tmp_73 as i32)) as i32 }); - __tmp_74 + __tmp_72 } }) },) { - (__tmp_71,) => { + (__tmp_69,) => { let (__it, __inserted) = Map::emplace( selected.as_pointer(), &keys.decay().offset(2), @@ -1257,7 +1255,7 @@ fn main_0() -> i32 { keys.decay().offset(2).read(), )), Rc::new(RefCell::new(Item::new_2( - { (__tmp_71).clone() }, + { (__tmp_69).clone() }, { 2 }, ))), ) @@ -1378,20 +1376,20 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_78: Value; + let __tmp_76: Value; match ((match { - __tmp_78 = Rc::new(RefCell::new(({ make_temporary_5() }))); - __tmp_78.as_pointer() + __tmp_76 = Rc::new(RefCell::new(({ make_temporary_5() }))); + __tmp_76.as_pointer() } { - __tmp_77 => field_ptr!(__tmp_77, n), + __tmp_75 => field_ptr!(__tmp_75, n), }),) { - (__tmp_76,) => { + (__tmp_74,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(0), || { ( Rc::new(RefCell::new(keys.decay().offset(0).read())), - Rc::new(RefCell::new((__tmp_76.read()))), + Rc::new(RefCell::new((__tmp_74.read()))), ) }); ( @@ -1405,20 +1403,20 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_81: Value; + let __tmp_79: Value; match ((match { - __tmp_81 = Rc::new(RefCell::new(({ make_nested_6() }))); - __tmp_81.as_pointer() + __tmp_79 = Rc::new(RefCell::new(({ make_nested_6() }))); + __tmp_79.as_pointer() } { - __tmp_80 => field_ptr!(field_ptr!(__tmp_80, inner), n), + __tmp_78 => field_ptr!(field_ptr!(__tmp_78, inner), n), }),) { - (__tmp_79,) => { + (__tmp_77,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(1), || { ( Rc::new(RefCell::new(keys.decay().offset(1).read())), - Rc::new(RefCell::new((__tmp_79.read()))), + Rc::new(RefCell::new((__tmp_77.read()))), ) }); ( @@ -1432,21 +1430,21 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_84: Value; + let __tmp_82: Value; match ((match { - __tmp_84 = Rc::new(RefCell::new(({ make_temporary_5() }))); - __tmp_84.as_pointer() + __tmp_82 = Rc::new(RefCell::new(({ make_temporary_5() }))); + __tmp_82.as_pointer() } { - __tmp_83 => array_field_ptr!(__tmp_83, data), + __tmp_81 => array_field_ptr!(__tmp_81, data), }) .offset((index.postfix_inc()) as isize),) { - (__tmp_82,) => { + (__tmp_80,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(2), || { ( Rc::new(RefCell::new(keys.decay().offset(2).read())), - Rc::new(RefCell::new((__tmp_82.read()))), + Rc::new(RefCell::new((__tmp_80.read()))), ) }); ( @@ -1519,28 +1517,28 @@ fn main_0() -> i32 { index = 0; let mut value: i32 = 0; { - let __tmp_87: Value; - let __tmp_89: Value; + let __tmp_85: Value; + let __tmp_87: Value; { match (if (choose != 0) { (match { - __tmp_87 = Rc::new(RefCell::new(({ make_nested_6() }))); - __tmp_87.as_pointer() + __tmp_85 = Rc::new(RefCell::new(({ make_nested_6() }))); + __tmp_85.as_pointer() } { - __tmp_86 => field_ptr!(field_ptr!(__tmp_86, inner), n), + __tmp_84 => field_ptr!(field_ptr!(__tmp_84, inner), n), }) } else { (match { - __tmp_89 = + __tmp_87 = Rc::new(RefCell::new(({ make_temporary_5() }))); - __tmp_89.as_pointer() + __tmp_87.as_pointer() } { - __tmp_88 => array_field_ptr!(__tmp_88, data), + __tmp_86 => array_field_ptr!(__tmp_86, data), }) .offset((index.postfix_inc()) as isize) },) { - (__tmp_85,) => { + (__tmp_83,) => { let (__it, __inserted) = Map::emplace( references.as_pointer(), &key.as_pointer(), @@ -1550,7 +1548,7 @@ fn main_0() -> i32 { key.as_pointer().read(), )), Rc::new(RefCell::new(Held::new_1({ - (__tmp_85).clone() + (__tmp_83).clone() }))), ) }, @@ -1609,29 +1607,29 @@ fn main_0() -> i32 { } before = temporary_calls_4.with(|rc| *rc.borrow()); { - let __tmp_92: Value; - let __tmp_94: Value; + let __tmp_90: Value; + let __tmp_92: Value; { match (if (choose != 0) { (match { - __tmp_92 = Rc::new(RefCell::new(({ make_nested_6() }))); - __tmp_92.as_pointer() + __tmp_90 = Rc::new(RefCell::new(({ make_nested_6() }))); + __tmp_90.as_pointer() } { - __tmp_91 => { - array_field_ptr!(field_ptr!(__tmp_91, inner), data) + __tmp_89 => { + array_field_ptr!(field_ptr!(__tmp_89, inner), data) } }) } else { (match { - __tmp_94 = + __tmp_92 = Rc::new(RefCell::new(({ make_temporary_5() }))); - __tmp_94.as_pointer() + __tmp_92.as_pointer() } { - __tmp_93 => array_field_ptr!(__tmp_93, data), + __tmp_91 => array_field_ptr!(__tmp_91, data), }) },) { - (__tmp_90,) => { + (__tmp_88,) => { let (__it, __inserted) = Map::emplace( arrays.as_pointer(), &key.as_pointer(), @@ -1641,7 +1639,7 @@ fn main_0() -> i32 { key.as_pointer().read(), )), Rc::new(RefCell::new(Held::new_3( - { (__tmp_90).clone() }, + { (__tmp_88).clone() }, { 0 }, ))), ) @@ -1698,22 +1696,22 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_96: Option>; + let mut __tmp_94: Option>; match (field_ptr!( (*{ - __tmp_96 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_96 + __tmp_94 = Some(Rc::new(RefCell::new(Temporary::new()))); + &mut __tmp_94 }) .as_pointer(), n ),) { - (__tmp_95,) => { + (__tmp_93,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(0), || { ( Rc::new(RefCell::new(keys.decay().offset(0).read())), - Rc::new(RefCell::new((__tmp_95.read()))), + Rc::new(RefCell::new((__tmp_93.read()))), ) }); ( @@ -1727,12 +1725,12 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_98: Option>; + let mut __tmp_96: Option>; match (field_ptr!( field_ptr!( (*{ - __tmp_98 = Some(Rc::new(RefCell::new(::default()))); - &mut __tmp_98 + __tmp_96 = Some(Rc::new(RefCell::new(::default()))); + &mut __tmp_96 }) .as_pointer(), inner @@ -1740,12 +1738,12 @@ fn main_0() -> i32 { n ),) { - (__tmp_97,) => { + (__tmp_95,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(1), || { ( Rc::new(RefCell::new(keys.decay().offset(1).read())), - Rc::new(RefCell::new((__tmp_97.read()))), + Rc::new(RefCell::new((__tmp_95.read()))), ) }); ( @@ -1759,23 +1757,23 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_100: Option>; + let mut __tmp_98: Option>; match (array_field_ptr!( (*{ - __tmp_100 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_100 + __tmp_98 = Some(Rc::new(RefCell::new(Temporary::new()))); + &mut __tmp_98 }) .as_pointer(), data ) .offset((index.postfix_inc()) as isize),) { - (__tmp_99,) => { + (__tmp_97,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(2), || { ( Rc::new(RefCell::new(keys.decay().offset(2).read())), - Rc::new(RefCell::new((__tmp_99.read()))), + Rc::new(RefCell::new((__tmp_97.read()))), ) }); ( @@ -1789,22 +1787,22 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_102: Option>; + let mut __tmp_100: Option>; match (field_ptr!( (*{ - __tmp_102 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_102 + __tmp_100 = Some(Rc::new(RefCell::new(Temporary::new()))); + &mut __tmp_100 }) .as_pointer(), n ),) { - (__tmp_101,) => { + (__tmp_99,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(3), || { ( Rc::new(RefCell::new(keys.decay().offset(3).read())), - Rc::new(RefCell::new((__tmp_101.read()))), + Rc::new(RefCell::new((__tmp_99.read()))), ) }); ( @@ -1818,22 +1816,22 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_104: Option>; + let mut __tmp_102: Option>; match (field_ptr!( ((*{ - __tmp_104 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_104 + __tmp_102 = Some(Rc::new(RefCell::new(Temporary::new()))); + &mut __tmp_102 }) .as_pointer()), n ),) { - (__tmp_103,) => { + (__tmp_101,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(4), || { ( Rc::new(RefCell::new(keys.decay().offset(4).read())), - Rc::new(RefCell::new((__tmp_103.read()))), + Rc::new(RefCell::new((__tmp_101.read()))), ) }); ( @@ -1847,13 +1845,13 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_106: Option>>>; + let mut __tmp_104: Option>>>; match (field_ptr!( ((*(*{ - __tmp_106 = Some(Rc::new(RefCell::new(Some(Rc::new(RefCell::new( + __tmp_104 = Some(Rc::new(RefCell::new(Some(Rc::new(RefCell::new( Temporary::new(), )))))); - &mut __tmp_106 + &mut __tmp_104 }) .as_pointer() .upgrade() @@ -1862,12 +1860,12 @@ fn main_0() -> i32 { n ),) { - (__tmp_105,) => { + (__tmp_103,) => { let (__it, __inserted) = Map::emplace(values.as_pointer(), &keys.decay().offset(5), || { ( Rc::new(RefCell::new(keys.decay().offset(5).read())), - Rc::new(RefCell::new((__tmp_105.read()))), + Rc::new(RefCell::new((__tmp_103.read()))), ) }); ( @@ -1938,15 +1936,15 @@ fn main_0() -> i32 { index = 0; let mut value: i32 = 0; { - let mut __tmp_108: Option>; - let mut __tmp_109: Option>; + let mut __tmp_106: Option>; + let mut __tmp_107: Option>; { match (if (choose != 0) { field_ptr!( (*{ - __tmp_108 = + __tmp_106 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_108 + &mut __tmp_106 }) .as_pointer(), n @@ -1954,9 +1952,9 @@ fn main_0() -> i32 { } else { array_field_ptr!( (*{ - __tmp_109 = + __tmp_107 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_109 + &mut __tmp_107 }) .as_pointer(), data @@ -1964,7 +1962,7 @@ fn main_0() -> i32 { .offset((index.postfix_inc()) as isize) },) { - (__tmp_107,) => { + (__tmp_105,) => { let (__it, __inserted) = Map::emplace( references.as_pointer(), &key.as_pointer(), @@ -1974,7 +1972,7 @@ fn main_0() -> i32 { key.as_pointer().read(), )), Rc::new(RefCell::new(Held::new_1({ - (__tmp_107).clone() + (__tmp_105).clone() }))), ) }, @@ -2009,16 +2007,16 @@ fn main_0() -> i32 { let owners: Value, Value)>> = Rc::new(RefCell::new(Map::new())); { - let __tmp_111: Value; + let __tmp_109: Value; { match (({ OwnerImpl::value(&{ - __tmp_111 = Rc::new(RefCell::new(Owner::new())); - __tmp_111.as_pointer() + __tmp_109 = Rc::new(RefCell::new(Owner::new())); + __tmp_109.as_pointer() }) }),) { - (__tmp_110,) => { + (__tmp_108,) => { let (__it, __inserted) = Map::emplace( owners.as_pointer(), &key.as_pointer(), @@ -2028,7 +2026,7 @@ fn main_0() -> i32 { key.as_pointer().read(), )), Rc::new(RefCell::new(Held::new_1({ - (__tmp_110).clone() + (__tmp_108).clone() }))), ) }, @@ -2075,22 +2073,22 @@ fn main_0() -> i32 { >, Value, )> = Rc::new(RefCell::new({ - let __tmp_113: Value>>; + let __tmp_111: Value>>; match ({ - __tmp_113 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( + __tmp_111 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( ::default(), ))))); - __tmp_113.as_pointer() + __tmp_111.as_pointer() },) { - (__tmp_112,) => { + (__tmp_110,) => { let (__it, __inserted) = Map::emplace(move_only.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), Rc::new(RefCell::new(( Rc::new(RefCell::new( - __tmp_112 + __tmp_110 .with_mut(|__v: &mut Option>| __v.take()), )), Rc::new(RefCell::new(7)), @@ -2113,22 +2111,22 @@ fn main_0() -> i32 { >, Value, )> = Rc::new(RefCell::new({ - let __tmp_115: Value>>; + let __tmp_113: Value>>; match ({ - __tmp_115 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( + __tmp_113 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( ::default(), ))))); - __tmp_115.as_pointer() + __tmp_113.as_pointer() },) { - (__tmp_114,) => { + (__tmp_112,) => { let (__it, __inserted) = Map::emplace(move_only.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), Rc::new(RefCell::new(( Rc::new(RefCell::new( - __tmp_114 + __tmp_112 .with_mut(|__v: &mut Option>| __v.take()), )), Rc::new(RefCell::new(9)), @@ -2198,13 +2196,13 @@ fn main_0() -> i32 { text.as_pointer() },) { - (__tmp_116,) => { + (__tmp_114,) => { let (__it, __inserted) = Map::emplace(strings.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), Rc::new(RefCell::new( - __tmp_116.with_mut(|__v| std::mem::replace(__v, vec![0])), + __tmp_114.with_mut(|__v| std::mem::replace(__v, vec![0])), )), ) }); @@ -2233,13 +2231,13 @@ fn main_0() -> i32 { text.as_pointer() },) { - (__tmp_117,) => { + (__tmp_115,) => { let (__it, __inserted) = Map::emplace(strings.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), Rc::new(RefCell::new( - __tmp_117.with_mut(|__v| std::mem::replace(__v, vec![0])), + __tmp_115.with_mut(|__v| std::mem::replace(__v, vec![0])), )), ) }); @@ -2259,9 +2257,9 @@ fn main_0() -> i32 { .1 .as_pointer(),) { - (__tmp_118,) => Ptr::::from_string_literal(b"value").with_c_str(|__s| { - (*__tmp_118.upgrade().deref()) - [..(*__tmp_118.upgrade().deref()).len().saturating_sub(1)] + (__tmp_116,) => Ptr::::from_string_literal(b"value").with_c_str(|__s| { + (*__tmp_116.upgrade().deref()) + [..(*__tmp_116.upgrade().deref()).len().saturating_sub(1)] == *__s }), }) diff --git a/tests/unit/out/refcount/operator_compound_assignment_free.rs b/tests/unit/out/refcount/operator_compound_assignment_free.rs index 76509ce0db..4d7df98b39 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_free.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_free.rs @@ -13,53 +13,23 @@ pub struct S { pub v: u32, } pub fn operator_add_assign_0(a: Ptr, b: Ptr) -> Ptr { - { - match ({ b.with(|__s| __s.v) }, &(field!(a, v))) { - (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { - (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; - }), - } - }; + field!(a, v).write({ (a.with(|__s| __s.v)).wrapping_add(b.with(|__s| __s.v)) }); return (a).clone(); } pub fn operator_sub_assign_1(a: Ptr, b: Ptr) -> Ptr { - { - match ({ b.with(|__s| __s.v) }, &(field!(a, v))) { - (__tmp_2, __tmp_3) => __tmp_3.with_mut(|__tmp_3| { - (*__tmp_3) = (((*__tmp_3) as u32).wrapping_sub((__tmp_2 as u32))) as u32; - }), - } - }; + field!(a, v).write({ (a.with(|__s| __s.v)).wrapping_sub(b.with(|__s| __s.v)) }); return (a).clone(); } pub fn operator_mul_assign_2(a: Ptr, b: Ptr) -> Ptr { - { - match ({ b.with(|__s| __s.v) }, &(field!(a, v))) { - (__tmp_4, __tmp_5) => __tmp_5.with_mut(|__tmp_5| { - (*__tmp_5) = (((*__tmp_5) as u32).wrapping_mul((__tmp_4 as u32))) as u32; - }), - } - }; + field!(a, v).write({ (a.with(|__s| __s.v)).wrapping_mul(b.with(|__s| __s.v)) }); return (a).clone(); } pub fn operator_div_assign_3(a: Ptr, b: Ptr) -> Ptr { - { - match ({ b.with(|__s| __s.v) }, &(field!(a, v))) { - (__tmp_6, __tmp_7) => __tmp_7.with_mut(|__tmp_7| { - (*__tmp_7) = (((*__tmp_7) as u32).wrapping_div((__tmp_6 as u32))) as u32; - }), - } - }; + field!(a, v).write({ (a.with(|__s| __s.v)).wrapping_div(b.with(|__s| __s.v)) }); return (a).clone(); } pub fn operator_rem_assign_4(a: Ptr, b: Ptr) -> Ptr { - { - match ({ b.with(|__s| __s.v) }, &(field!(a, v))) { - (__tmp_8, __tmp_9) => __tmp_9.with_mut(|__tmp_9| { - (*__tmp_9) = (((*__tmp_9) as u32).wrapping_rem((__tmp_8 as u32))) as u32; - }), - } - }; + field!(a, v).write({ (a.with(|__s| __s.v)).wrapping_rem(b.with(|__s| __s.v)) }); return (a).clone(); } pub fn operator_bitand_assign_5(a: Ptr, b: Ptr) -> Ptr { diff --git a/tests/unit/out/refcount/operator_compound_assignment_member.rs b/tests/unit/out/refcount/operator_compound_assignment_member.rs index d33ff8a464..4452be00d5 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_member.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_member.rs @@ -76,53 +76,23 @@ impl SImpl for Ptr { return (*self).clone(); } fn operator_add_assign(&self, o: Ptr) -> Ptr { - { - match ({ o.with(|__s| __s.v) }, &(field!((*self), v))) { - (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { - (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; - }), - } - }; + field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_add(o.with(|__s| __s.v)) }); return (*self).clone(); } fn operator_sub_assign(&self, o: Ptr) -> Ptr { - { - match ({ o.with(|__s| __s.v) }, &(field!((*self), v))) { - (__tmp_2, __tmp_3) => __tmp_3.with_mut(|__tmp_3| { - (*__tmp_3) = (((*__tmp_3) as u32).wrapping_sub((__tmp_2 as u32))) as u32; - }), - } - }; + field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_sub(o.with(|__s| __s.v)) }); return (*self).clone(); } fn operator_mul_assign(&self, o: Ptr) -> Ptr { - { - match ({ o.with(|__s| __s.v) }, &(field!((*self), v))) { - (__tmp_4, __tmp_5) => __tmp_5.with_mut(|__tmp_5| { - (*__tmp_5) = (((*__tmp_5) as u32).wrapping_mul((__tmp_4 as u32))) as u32; - }), - } - }; + field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_mul(o.with(|__s| __s.v)) }); return (*self).clone(); } fn operator_div_assign(&self, o: Ptr) -> Ptr { - { - match ({ o.with(|__s| __s.v) }, &(field!((*self), v))) { - (__tmp_6, __tmp_7) => __tmp_7.with_mut(|__tmp_7| { - (*__tmp_7) = (((*__tmp_7) as u32).wrapping_div((__tmp_6 as u32))) as u32; - }), - } - }; + field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_div(o.with(|__s| __s.v)) }); return (*self).clone(); } fn operator_rem_assign(&self, o: Ptr) -> Ptr { - { - match ({ o.with(|__s| __s.v) }, &(field!((*self), v))) { - (__tmp_8, __tmp_9) => __tmp_9.with_mut(|__tmp_9| { - (*__tmp_9) = (((*__tmp_9) as u32).wrapping_rem((__tmp_8 as u32))) as u32; - }), - } - }; + field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_rem(o.with(|__s| __s.v)) }); return (*self).clone(); } fn operator_bitand_assign(&self, o: Ptr) -> Ptr { diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index 03b2ae6611..e329c56467 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -35,27 +35,9 @@ fn main_0() -> i32 { (chain == (((20 + 10) + 5) as usize).wrapping_add((::std::mem::size_of::() as usize))) ); let mut acc: usize = 100_usize; - { - match ({ ::std::mem::size_of::() }, &mut (acc)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as u64).wrapping_add((__tmp_0 as u64))) as usize; - } - } - }; - { - match ({ 2_usize }, &mut (acc)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = (((*__tmp_3) as usize).wrapping_mul((__tmp_2 as usize))) as usize; - } - } - }; - { - match ({ (*ul.borrow()) }, &mut (acc)) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = (((*__tmp_5) as u64).wrapping_sub((__tmp_4 as u64))) as usize; - } - } - }; + acc = { ((acc as u64).wrapping_add((::std::mem::size_of::() as u64))) as usize }; + acc = { (acc).wrapping_mul(2_usize) }; + acc = { ((acc as u64).wrapping_sub((*ul.borrow()))) as usize }; assert!( (acc == ((((100_usize).wrapping_add((::std::mem::size_of::() as usize))) as usize) .wrapping_mul(2_usize) as usize) @@ -76,37 +58,37 @@ fn main_0() -> i32 { let mut fr2: u64 = ({ take_ulong_1((sz as u64)) }); assert!((fr2 == 21_u64)); let mut lo: usize = (({ - let __tmp_6: Value = Rc::new(RefCell::new( + let __tmp_0: Value = Rc::new(RefCell::new( (::std::mem::size_of::() as u64).wrapping_add((*ul.borrow())), )); - let __tmp_7: Value = Rc::new(RefCell::new((sz as u64))); - (if CppLess::less(&__tmp_6.as_pointer(), &__tmp_7.as_pointer()) { - __tmp_6.as_pointer() + let __tmp_1: Value = Rc::new(RefCell::new((sz as u64))); + (if CppLess::less(&__tmp_0.as_pointer(), &__tmp_1.as_pointer()) { + __tmp_0.as_pointer() } else { - __tmp_7.as_pointer() + __tmp_1.as_pointer() } .read()) }) as usize); let mut hi: usize = (({ - let __tmp_8: Value = Rc::new(RefCell::new( + let __tmp_2: Value = Rc::new(RefCell::new( (::std::mem::size_of::() as u64).wrapping_add((sz as u64)), )); - (if CppLess::less(&__tmp_8.as_pointer(), &ul.as_pointer()) { + (if CppLess::less(&__tmp_2.as_pointer(), &ul.as_pointer()) { ul.as_pointer() } else { - __tmp_8.as_pointer() + __tmp_2.as_pointer() } .read()) }) as usize); assert!((lo == (::std::mem::size_of::() as usize).wrapping_add(10_usize))); assert!((hi == (::std::mem::size_of::() as usize).wrapping_add(21_usize))); let mut bound: usize = (({ - let __tmp_9: Value = Rc::new(RefCell::new((4_usize as u64))); - let __tmp_10: Value = Rc::new(RefCell::new((sz as u64))); - (if CppLess::less(&__tmp_9.as_pointer(), &__tmp_10.as_pointer()) { - __tmp_9.as_pointer() + let __tmp_3: Value = Rc::new(RefCell::new((4_usize as u64))); + let __tmp_4: Value = Rc::new(RefCell::new((sz as u64))); + (if CppLess::less(&__tmp_3.as_pointer(), &__tmp_4.as_pointer()) { + __tmp_3.as_pointer() } else { - __tmp_10.as_pointer() + __tmp_4.as_pointer() } .read()) }) as usize); @@ -128,14 +110,7 @@ fn main_0() -> i32 { let mut i: usize = 0_usize; 'loop_: while (i < count) { 'for_body: { - { - match ({ (data[(i) as usize] as usize) }, &mut (total)) { - (__tmp_11, __tmp_12) => { - (*__tmp_12) = - (((*__tmp_12) as usize).wrapping_add((__tmp_11 as usize))) as usize; - } - } - }; + total = { (total).wrapping_add((data[(i) as usize] as usize)) }; } i.postfix_inc(); } @@ -164,22 +139,22 @@ fn main_0() -> i32 { assert!((sm == 15_isize)); assert!((sm > (l as isize))); let mut smin: isize = (({ - let __tmp_13: Value = Rc::new(RefCell::new((sm as i64))); - let __tmp_14: Value = Rc::new(RefCell::new((sd as i64))); - (if CppLess::less(&__tmp_13.as_pointer(), &__tmp_14.as_pointer()) { - __tmp_13.as_pointer() + let __tmp_5: Value = Rc::new(RefCell::new((sm as i64))); + let __tmp_6: Value = Rc::new(RefCell::new((sd as i64))); + (if CppLess::less(&__tmp_5.as_pointer(), &__tmp_6.as_pointer()) { + __tmp_5.as_pointer() } else { - __tmp_14.as_pointer() + __tmp_6.as_pointer() } .read()) }) as isize); let mut smax: isize = (({ - let __tmp_15: Value = Rc::new(RefCell::new((sd as i64))); - let __tmp_16: Value = Rc::new(RefCell::new((sm as i64))); - (if CppLess::less(&__tmp_15.as_pointer(), &__tmp_16.as_pointer()) { - __tmp_16.as_pointer() + let __tmp_7: Value = Rc::new(RefCell::new((sd as i64))); + let __tmp_8: Value = Rc::new(RefCell::new((sm as i64))); + (if CppLess::less(&__tmp_7.as_pointer(), &__tmp_8.as_pointer()) { + __tmp_8.as_pointer() } else { - __tmp_15.as_pointer() + __tmp_7.as_pointer() } .read()) }) as isize); @@ -201,22 +176,22 @@ fn main_0() -> i32 { let mut mins: [usize; 4] = [ 0_usize, (({ - let __tmp_17: Value = Rc::new(RefCell::new((mx as u64))); - let __tmp_18: Value = Rc::new(RefCell::new(1_u64)); - (if CppLess::less(&__tmp_17.as_pointer(), &__tmp_18.as_pointer()) { - __tmp_17.as_pointer() + let __tmp_9: Value = Rc::new(RefCell::new((mx as u64))); + let __tmp_10: Value = Rc::new(RefCell::new(1_u64)); + (if CppLess::less(&__tmp_9.as_pointer(), &__tmp_10.as_pointer()) { + __tmp_9.as_pointer() } else { - __tmp_18.as_pointer() + __tmp_10.as_pointer() } .read()) }) as usize), (({ - let __tmp_19: Value = Rc::new(RefCell::new(((mx).wrapping_sub(3_usize) as u64))); - let __tmp_20: Value = Rc::new(RefCell::new((mx as u64))); - (if CppLess::less(&__tmp_19.as_pointer(), &__tmp_20.as_pointer()) { - __tmp_19.as_pointer() + let __tmp_11: Value = Rc::new(RefCell::new(((mx).wrapping_sub(3_usize) as u64))); + let __tmp_12: Value = Rc::new(RefCell::new((mx as u64))); + (if CppLess::less(&__tmp_11.as_pointer(), &__tmp_12.as_pointer()) { + __tmp_11.as_pointer() } else { - __tmp_20.as_pointer() + __tmp_12.as_pointer() } .read()) }) as usize), diff --git a/tests/unit/out/refcount/size_t_template_param.rs b/tests/unit/out/refcount/size_t_template_param.rs index b04baa0887..51b7557e55 100644 --- a/tests/unit/out/refcount/size_t_template_param.rs +++ b/tests/unit/out/refcount/size_t_template_param.rs @@ -7,13 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn array_ref_0(a: Ptr) -> u64 { - { - match ({ 1_u64 }, &(elem!(a, 0))) { - (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { - (*__tmp_1) = (((*__tmp_1) as u64).wrapping_add((__tmp_0 as u64))) as u64; - }), - } - }; + elem!(a, 0).write({ (elem!(a, 0).read()).wrapping_add(1_u64) }); return (elem!(a, (3_u64 as u64).wrapping_sub(1_u64)).read()); } #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] diff --git a/tests/unit/out/refcount/swap_map_no_copy.rs b/tests/unit/out/refcount/swap_map_no_copy.rs index cf3942380c..6b516a5055 100644 --- a/tests/unit/out/refcount/swap_map_no_copy.rs +++ b/tests/unit/out/refcount/swap_map_no_copy.rs @@ -224,12 +224,8 @@ pub fn swapped_once_6() -> bool { match ( { { - match ({ 0 }, &mut (*moved_dtors_5.with(Value::clone).borrow_mut())) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } + moved_dtors_5.with(|rc| *rc.borrow_mut() = 0); + moved_dtors_5.with(|rc| *rc.borrow()) } }, &mut (*move_assigns_4.with(Value::clone).borrow_mut()), @@ -272,10 +268,10 @@ fn main_0() -> i32 { let _o: Value = Rc::new(RefCell::new(Tracked::new_1({ 10 }))); TrackedImpl::move_assign( &match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_4,) => { + (__tmp_2,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_4, + __tmp_2, |__k| cpp_move!(__k), || ::default(), ) @@ -289,10 +285,10 @@ fn main_0() -> i32 { let _o: Value = Rc::new(RefCell::new(Tracked::new_1({ 20 }))); TrackedImpl::move_assign( &match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_5,) => { + (__tmp_3,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_5, + __tmp_3, |__k| cpp_move!(__k), || ::default(), ) @@ -307,10 +303,10 @@ fn main_0() -> i32 { let _o: Value = Rc::new(RefCell::new(Tracked::new_1({ 30 }))); TrackedImpl::move_assign( &match (Rc::new(RefCell::new(3)).as_pointer(),) { - (__tmp_6,) => { + (__tmp_4,) => { ({ (*m2.borrow_mut()).subscript_move( - __tmp_6, + __tmp_4, |__k| cpp_move!(__k), || ::default(), ) @@ -323,10 +319,10 @@ fn main_0() -> i32 { assert!((copies_0.with(|rc| *rc.borrow()) == 0)); cpp_swap!( match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_7,) => { + (__tmp_5,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_7, + __tmp_5, |__k| cpp_move!(__k), || ::default(), ) @@ -334,10 +330,10 @@ fn main_0() -> i32 { } }, match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_8,) => { + (__tmp_6,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_8, + __tmp_6, |__k| cpp_move!(__k), || ::default(), ) @@ -347,10 +343,10 @@ fn main_0() -> i32 { ); assert!( (match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_9,) => { + (__tmp_7,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_9, + __tmp_7, |__k| cpp_move!(__k), || ::default(), ) @@ -360,10 +356,10 @@ fn main_0() -> i32 { .with(|__s| __s.v) == 20) && (match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_10,) => { + (__tmp_8,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_10, + __tmp_8, |__k| cpp_move!(__k), || ::default(), ) @@ -378,10 +374,10 @@ fn main_0() -> i32 { assert!( ((*m1.borrow()).len() == 1_usize) && (match (Rc::new(RefCell::new(3)).as_pointer(),) { - (__tmp_11,) => { + (__tmp_9,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_11, + __tmp_9, |__k| cpp_move!(__k), || ::default(), ) @@ -394,10 +390,10 @@ fn main_0() -> i32 { assert!( (((*m2.borrow()).len() == 2_usize) && (match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_12,) => { + (__tmp_10,) => { ({ (*m2.borrow_mut()).subscript_move( - __tmp_12, + __tmp_10, |__k| cpp_move!(__k), || ::default(), ) @@ -407,10 +403,10 @@ fn main_0() -> i32 { .with(|__s| __s.v) == 20)) && (match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_13,) => { + (__tmp_11,) => { ({ (*m2.borrow_mut()).subscript_move( - __tmp_13, + __tmp_11, |__k| cpp_move!(__k), || ::default(), ) @@ -437,12 +433,12 @@ fn main_0() -> i32 { assert!((copies_0.with(|rc| *rc.borrow()) == 0)); let vec_: Value> = Rc::new(RefCell::new(Vec::new())); { - let mut __tmp_14 = { Tracked::new_1({ 4 }) }; - (*vec_.borrow_mut()).push(__tmp_14); + let mut __tmp_12 = { Tracked::new_1({ 4 }) }; + (*vec_.borrow_mut()).push(__tmp_12); }; { - let mut __tmp_15 = { Tracked::new_1({ 5 }) }; - (*vec_.borrow_mut()).push(__tmp_15); + let mut __tmp_13 = { Tracked::new_1({ 5 }) }; + (*vec_.borrow_mut()).push(__tmp_13); }; cpp_swap!(vec_.decay().offset(0_usize), vec_.decay().offset(1_usize)); assert!(({ ({ (*vec_.borrow())[0_usize].v } == 5) && ({ (*vec_.borrow())[1_usize].v } == 4) })); @@ -510,18 +506,18 @@ fn main_0() -> i32 { let grid: Value>> = Rc::new(RefCell::new(Vec::from_fn(2_usize, |_| Default::default()))); match (grid.decay().offset(0_usize), { Tracked::new_1({ 1 }) }) { - (__tmp_16, mut __tmp_17) => { - __tmp_16.with_mut(|__v: &mut Vec| __v.push(__tmp_17)); + (__tmp_14, mut __tmp_15) => { + __tmp_14.with_mut(|__v: &mut Vec| __v.push(__tmp_15)); } }; match (grid.decay().offset(0_usize), { Tracked::new_1({ 2 }) }) { - (__tmp_18, mut __tmp_19) => { - __tmp_18.with_mut(|__v: &mut Vec| __v.push(__tmp_19)); + (__tmp_16, mut __tmp_17) => { + __tmp_16.with_mut(|__v: &mut Vec| __v.push(__tmp_17)); } }; match (grid.decay().offset(1_usize), { Tracked::new_1({ 3 }) }) { - (__tmp_20, mut __tmp_21) => { - __tmp_20.with_mut(|__v: &mut Vec| __v.push(__tmp_21)); + (__tmp_18, mut __tmp_19) => { + __tmp_18.with_mut(|__v: &mut Vec| __v.push(__tmp_19)); } }; cpp_swap!( @@ -549,10 +545,10 @@ fn main_0() -> i32 { let _o: Value = Rc::new(RefCell::new(Tracked::new_1({ 1 }))); TrackedImpl::move_assign( &match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_22,) => { + (__tmp_20,) => { ({ (*maps.borrow_mut())[(0) as usize].subscript_move( - __tmp_22, + __tmp_20, |__k| cpp_move!(__k), || ::default(), ) @@ -566,10 +562,10 @@ fn main_0() -> i32 { let _o: Value = Rc::new(RefCell::new(Tracked::new_1({ 2 }))); TrackedImpl::move_assign( &match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_23,) => { + (__tmp_21,) => { ({ (*maps.borrow_mut())[(1) as usize].subscript_move( - __tmp_23, + __tmp_21, |__k| cpp_move!(__k), || ::default(), ) @@ -583,10 +579,10 @@ fn main_0() -> i32 { assert!( ((*maps.borrow())[(0) as usize].len() == 1_usize) && (match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_24,) => { + (__tmp_22,) => { ({ (*maps.borrow_mut())[(0) as usize].subscript_move( - __tmp_24, + __tmp_22, |__k| cpp_move!(__k), || ::default(), ) @@ -599,10 +595,10 @@ fn main_0() -> i32 { assert!( ((*maps.borrow())[(1) as usize].len() == 1_usize) && (match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_25,) => { + (__tmp_23,) => { ({ (*maps.borrow_mut())[(1) as usize].subscript_move( - __tmp_25, + __tmp_23, |__k| cpp_move!(__k), || ::default(), ) diff --git a/tests/unit/out/refcount/switch_on_assignment.rs b/tests/unit/out/refcount/switch_on_assignment.rs index 02cf599092..997126b24b 100644 --- a/tests/unit/out/refcount/switch_on_assignment.rs +++ b/tests/unit/out/refcount/switch_on_assignment.rs @@ -12,12 +12,8 @@ pub fn switch_on_assignment_0(mut x: i32) -> i32 { 'switch: { match { { - match ({ (x + 1) }, &mut (y)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } - } + y = (x + 1); + y } } { __v if __v == 1 => { diff --git a/tests/unit/out/unsafe/assign_as_value.rs b/tests/unit/out/unsafe/assign_as_value.rs index 55f2edd5f4..55cbab8ae6 100644 --- a/tests/unit/out/unsafe/assign_as_value.rs +++ b/tests/unit/out/unsafe/assign_as_value.rs @@ -16,29 +16,37 @@ unsafe fn main_0() -> i32 { let mut buf: [libc::c_char; 2] = [(0 as libc::c_char); 2]; let mut p: *mut libc::c_char = buf.as_mut_ptr(); let mut q: *mut libc::c_char = std::ptr::null_mut(); - q = match ({ 1 }, &mut (p)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (*__tmp_1).offset((__tmp_0 as isize)); - (*__tmp_1).clone() - } + q = { + p = (p).wrapping_add((1 as i32) as usize); + p }; assert!(((q) == (buf.as_mut_ptr().offset((1) as isize)))); - q = match ({ 1 }, &mut (p)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = (*__tmp_3).offset(-(__tmp_2 as isize)); - (*__tmp_3).clone() + q = { + p = (p).wrapping_sub((1 as i32) as usize); + p + }; + assert!(((p) == (buf.as_mut_ptr()))); + assert!(((q) == (buf.as_mut_ptr()))); + p = (p).wrapping_add((1 as i32) as usize); + let mut i: i32 = 0; + q = match ( + { 1 }, + &mut (*((&mut p as *mut *mut libc::c_char).offset((i.postfix_inc()) as isize))), + ) { + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (*__tmp_1).offset(-(__tmp_0 as isize)); + (*__tmp_1).clone() } }; + assert!(((i) == (1))); assert!(((p) == (buf.as_mut_ptr()))); assert!(((q) == (buf.as_mut_ptr()))); let mut out: libc::c_char = (0 as libc::c_char); 'switch: { match { - ((match ({ (('x' as i32) as libc::c_char) }, &mut (out)) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } + (({ + out = (('x' as i32) as libc::c_char); + out }) as i32) } { __v if __v == ('x' as i32) => { diff --git a/tests/unit/out/unsafe/assign_rhs_first.rs b/tests/unit/out/unsafe/assign_rhs_first.rs index 0eb608b98d..62e5e05779 100644 --- a/tests/unit/out/unsafe/assign_rhs_first.rs +++ b/tests/unit/out/unsafe/assign_rhs_first.rs @@ -52,11 +52,7 @@ unsafe fn main_0() -> i32 { assert!(((s.ptr) == (a.as_mut_ptr().offset((2) as isize))) && ((a[(3) as usize]) == (24))); let mut b: *mut u8 = (a.as_mut_ptr() as *mut u8); (*b.offset((0) as isize)) = 7_u8; - match ({ 1 }, &mut (*b.offset((4) as isize))) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as i32) + (__tmp_0 as i32)) as u8; - } - }; + (*b.offset((4) as isize)) = (((*b.offset((4) as isize)) as i32) + 1) as u8; assert!(((a[(0) as usize]) == (7)) && ((a[(1) as usize]) == (3))); return 0; } diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 143a1de024..bef0b990dc 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -54,13 +54,78 @@ pub unsafe fn test_0() { (a[(1) as usize] as i32), ) }); + let mut plain: u32 = 10_u32; + plain = (plain).wrapping_add(5_u32); + let mut plain_result: u32 = ({ + plain = (plain).wrapping_add(2_u32); + plain + }); + (unsafe { + libc::printf( + c"plain %d %d\n".as_ptr() as *const libc::c_char, + (plain_result as i32), + (plain as i32), + ) + }); + i = 0; + match ( + { + { + i = 1; + 5_u32 + } + }, + &mut (a[(i) as usize]), + ) { + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as u32).wrapping_add((__tmp_6 as u32))) as u32; + } + }; + (unsafe { + libc::printf( + c"rhs target %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32), + ) + }); + a[(0) as usize] = 0_u32; + let mut selected: u32 = (match ({ 1_u32 }, &mut (a[(a[(0) as usize]) as usize])) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as u32).wrapping_add((__tmp_8 as u32))) as u32; + (*__tmp_9).clone() + } + }); + (unsafe { + libc::printf( + c"self compound %d %d %d\n".as_ptr() as *const libc::c_char, + (selected as i32), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32), + ) + }); + a[(0) as usize] = 0_u32; + selected = (match ({ 1_u32 }, &mut (a[(a[(0) as usize]) as usize])) { + (__tmp_10, __tmp_11) => { + (*__tmp_11) = __tmp_10; + (*__tmp_11).clone() + } + }); + (unsafe { + libc::printf( + c"self simple %d %d %d\n".as_ptr() as *const libc::c_char, + (selected as i32), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32), + ) + }); } pub unsafe fn test_1() { let mut a: [i16; 3] = [10_i16, 20_i16, 30_i16]; let mut i: i32 = 0; match ({ 5 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as i32) + (__tmp_6 as i32)) as i16; + (__tmp_12, __tmp_13) => { + (*__tmp_13) = (((*__tmp_13) as i32) + (__tmp_12 as i32)) as i16; } }; (unsafe { @@ -73,9 +138,9 @@ pub unsafe fn test_1() { }); i = 0; let mut sum: i16 = (match ({ 2 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as i32) + (__tmp_8 as i32)) as i16; - (*__tmp_9).clone() + (__tmp_14, __tmp_15) => { + (*__tmp_15) = (((*__tmp_15) as i32) + (__tmp_14 as i32)) as i16; + (*__tmp_15).clone() } }); (unsafe { @@ -89,9 +154,9 @@ pub unsafe fn test_1() { }); i = 0; let mut assigned: i16 = (match ({ 99_i16 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_10, __tmp_11) => { - (*__tmp_11) = __tmp_10; - (*__tmp_11).clone() + (__tmp_16, __tmp_17) => { + (*__tmp_17) = __tmp_16; + (*__tmp_17).clone() } }); (unsafe { @@ -103,6 +168,71 @@ pub unsafe fn test_1() { (a[(1) as usize] as i32), ) }); + let mut plain: i16 = 10_i16; + plain = ((plain as i32) + 5) as i16; + let mut plain_result: i16 = ({ + plain = ((plain as i32) + 2) as i16; + plain + }); + (unsafe { + libc::printf( + c"plain %d %d\n".as_ptr() as *const libc::c_char, + (plain_result as i32), + (plain as i32), + ) + }); + i = 0; + match ( + { + ({ + i = 1; + 5_i16 + } as i32) + }, + &mut (a[(i) as usize]), + ) { + (__tmp_18, __tmp_19) => { + (*__tmp_19) = (((*__tmp_19) as i32) + (__tmp_18 as i32)) as i16; + } + }; + (unsafe { + libc::printf( + c"rhs target %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32), + ) + }); + a[(0) as usize] = 0_i16; + let mut selected: i16 = (match ({ 1 }, &mut (a[(a[(0) as usize]) as usize])) { + (__tmp_20, __tmp_21) => { + (*__tmp_21) = (((*__tmp_21) as i32) + (__tmp_20 as i32)) as i16; + (*__tmp_21).clone() + } + }); + (unsafe { + libc::printf( + c"self compound %d %d %d\n".as_ptr() as *const libc::c_char, + (selected as i32), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32), + ) + }); + a[(0) as usize] = 0_i16; + selected = (match ({ 1_i16 }, &mut (a[(a[(0) as usize]) as usize])) { + (__tmp_22, __tmp_23) => { + (*__tmp_23) = __tmp_22; + (*__tmp_23).clone() + } + }); + (unsafe { + libc::printf( + c"self simple %d %d %d\n".as_ptr() as *const libc::c_char, + (selected as i32), + (a[(0) as usize] as i32), + (a[(1) as usize] as i32), + ) + }); } pub unsafe fn test_2() { let mut a: [i32; 3] = [10, 20, 30]; @@ -118,9 +248,9 @@ pub unsafe fn test_2() { }); i = 0; let mut sum: i32 = (match ({ 2 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = (((*__tmp_13) as i32) + (__tmp_12 as i32)) as i32; - (*__tmp_13).clone() + (__tmp_24, __tmp_25) => { + (*__tmp_25) = (((*__tmp_25) as i32) + (__tmp_24 as i32)) as i32; + (*__tmp_25).clone() } }); (unsafe { @@ -134,9 +264,9 @@ pub unsafe fn test_2() { }); i = 0; let mut assigned: i32 = (match ({ 99 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_14, __tmp_15) => { - (*__tmp_15) = __tmp_14; - (*__tmp_15).clone() + (__tmp_26, __tmp_27) => { + (*__tmp_27) = __tmp_26; + (*__tmp_27).clone() } }); (unsafe { @@ -148,6 +278,62 @@ pub unsafe fn test_2() { (a[(1) as usize]), ) }); + let mut plain: i32 = 10; + plain += 5; + let mut plain_result: i32 = ({ + plain += 2; + plain + }); + (unsafe { + libc::printf( + c"plain %d %d\n".as_ptr() as *const libc::c_char, + (plain_result), + (plain), + ) + }); + i = 0; + a[(i) as usize] += { + i = 1; + 5 + }; + (unsafe { + libc::printf( + c"rhs target %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (a[(0) as usize]), + (a[(1) as usize]), + ) + }); + a[(0) as usize] = 0; + let mut selected: i32 = (match ({ 1 }, &mut (a[(a[(0) as usize]) as usize])) { + (__tmp_28, __tmp_29) => { + (*__tmp_29) = (((*__tmp_29) as i32) + (__tmp_28 as i32)) as i32; + (*__tmp_29).clone() + } + }); + (unsafe { + libc::printf( + c"self compound %d %d %d\n".as_ptr() as *const libc::c_char, + (selected), + (a[(0) as usize]), + (a[(1) as usize]), + ) + }); + a[(0) as usize] = 0; + selected = (match ({ 1 }, &mut (a[(a[(0) as usize]) as usize])) { + (__tmp_30, __tmp_31) => { + (*__tmp_31) = __tmp_30; + (*__tmp_31).clone() + } + }); + (unsafe { + libc::printf( + c"self simple %d %d %d\n".as_ptr() as *const libc::c_char, + (selected), + (a[(0) as usize]), + (a[(1) as usize]), + ) + }); } pub unsafe fn test_comma_3() { let mut x: u32 = 10_u32; @@ -159,8 +345,8 @@ pub unsafe fn test_comma_3() { &mut x })), ) { - (__tmp_16, __tmp_17) => { - (*__tmp_17) = (((*__tmp_17) as u32).wrapping_add((__tmp_16 as u32))) as u32; + (__tmp_32, __tmp_33) => { + (*__tmp_33) = (((*__tmp_33) as u32).wrapping_add((__tmp_32 as u32))) as u32; } }; (unsafe { @@ -177,9 +363,9 @@ pub unsafe fn test_comma_3() { &mut x })), ) { - (__tmp_18, __tmp_19) => { - (*__tmp_19) = (((*__tmp_19) as u32).wrapping_add((__tmp_18 as u32))) as u32; - (*__tmp_19).clone() + (__tmp_34, __tmp_35) => { + (*__tmp_35) = (((*__tmp_35) as u32).wrapping_add((__tmp_34 as u32))) as u32; + (*__tmp_35).clone() } }); (unsafe { @@ -197,9 +383,9 @@ pub unsafe fn test_comma_3() { &mut x })), ) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = __tmp_20; - (*__tmp_21).clone() + (__tmp_36, __tmp_37) => { + (*__tmp_37) = __tmp_36; + (*__tmp_37).clone() } }); (unsafe { @@ -218,8 +404,8 @@ pub unsafe fn test_comma_3() { (p).clone() })), ) { - (__tmp_22, __tmp_23) => { - (*__tmp_23) = (((*__tmp_23) as u32).wrapping_add((__tmp_22 as u32))) as u32; + (__tmp_38, __tmp_39) => { + (*__tmp_39) = (((*__tmp_39) as u32).wrapping_add((__tmp_38 as u32))) as u32; } }; (unsafe { @@ -236,9 +422,9 @@ pub unsafe fn test_comma_3() { (p).clone() })), ) { - (__tmp_24, __tmp_25) => { - (*__tmp_25) = (((*__tmp_25) as u32).wrapping_add((__tmp_24 as u32))) as u32; - (*__tmp_25).clone() + (__tmp_40, __tmp_41) => { + (*__tmp_41) = (((*__tmp_41) as u32).wrapping_add((__tmp_40 as u32))) as u32; + (*__tmp_41).clone() } }); (unsafe { @@ -256,9 +442,9 @@ pub unsafe fn test_comma_3() { (p).clone() })), ) { - (__tmp_26, __tmp_27) => { - (*__tmp_27) = __tmp_26; - (*__tmp_27).clone() + (__tmp_42, __tmp_43) => { + (*__tmp_43) = __tmp_42; + (*__tmp_43).clone() } }); (unsafe { @@ -280,8 +466,8 @@ pub unsafe fn test_comma_4() { &mut x })), ) { - (__tmp_28, __tmp_29) => { - (*__tmp_29) = (((*__tmp_29) as i32) + (__tmp_28 as i32)) as i16; + (__tmp_44, __tmp_45) => { + (*__tmp_45) = (((*__tmp_45) as i32) + (__tmp_44 as i32)) as i16; } }; (unsafe { @@ -298,9 +484,9 @@ pub unsafe fn test_comma_4() { &mut x })), ) { - (__tmp_30, __tmp_31) => { - (*__tmp_31) = (((*__tmp_31) as i32) + (__tmp_30 as i32)) as i16; - (*__tmp_31).clone() + (__tmp_46, __tmp_47) => { + (*__tmp_47) = (((*__tmp_47) as i32) + (__tmp_46 as i32)) as i16; + (*__tmp_47).clone() } }); (unsafe { @@ -318,9 +504,9 @@ pub unsafe fn test_comma_4() { &mut x })), ) { - (__tmp_32, __tmp_33) => { - (*__tmp_33) = __tmp_32; - (*__tmp_33).clone() + (__tmp_48, __tmp_49) => { + (*__tmp_49) = __tmp_48; + (*__tmp_49).clone() } }); (unsafe { @@ -339,8 +525,8 @@ pub unsafe fn test_comma_4() { (p).clone() })), ) { - (__tmp_34, __tmp_35) => { - (*__tmp_35) = (((*__tmp_35) as i32) + (__tmp_34 as i32)) as i16; + (__tmp_50, __tmp_51) => { + (*__tmp_51) = (((*__tmp_51) as i32) + (__tmp_50 as i32)) as i16; } }; (unsafe { @@ -357,9 +543,9 @@ pub unsafe fn test_comma_4() { (p).clone() })), ) { - (__tmp_36, __tmp_37) => { - (*__tmp_37) = (((*__tmp_37) as i32) + (__tmp_36 as i32)) as i16; - (*__tmp_37).clone() + (__tmp_52, __tmp_53) => { + (*__tmp_53) = (((*__tmp_53) as i32) + (__tmp_52 as i32)) as i16; + (*__tmp_53).clone() } }); (unsafe { @@ -377,9 +563,9 @@ pub unsafe fn test_comma_4() { (p).clone() })), ) { - (__tmp_38, __tmp_39) => { - (*__tmp_39) = __tmp_38; - (*__tmp_39).clone() + (__tmp_54, __tmp_55) => { + (*__tmp_55) = __tmp_54; + (*__tmp_55).clone() } }); (unsafe { @@ -403,17 +589,10 @@ pub unsafe fn test_borrows_8() { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - observe_global_6( - match ( - { 99 }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)), - ) { - (__tmp_40, __tmp_41) => { - (*__tmp_41) = __tmp_40; - (*__tmp_41).clone() - } - }, - ) + observe_global_6({ + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)) = 99; + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)) + }) }), ) }); @@ -421,17 +600,10 @@ pub unsafe fn test_borrows_8() { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - observe_global_6( - match ( - { 5 }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)), - ) { - (__tmp_42, __tmp_43) => { - (*__tmp_43) = (((*__tmp_43) as i32) + (__tmp_42 as i32)) as i32; - (*__tmp_43).clone() - } - }, - ) + observe_global_6({ + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)) += 5; + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)) + }) }), ) }); @@ -440,11 +612,9 @@ pub unsafe fn test_borrows_8() { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - let _assigned: i32 = match ({ 99 }, &mut (local)) { - (__tmp_44, __tmp_45) => { - (*__tmp_45) = __tmp_44; - (*__tmp_45).clone() - } + let _assigned: i32 = { + local = 99; + local }; let _stored: *const i32 = (&mut local as *mut i32).cast_const(); observe_7(_assigned, _stored) @@ -455,11 +625,9 @@ pub unsafe fn test_borrows_8() { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - let _assigned: i32 = match ({ 5 }, &mut (local)) { - (__tmp_46, __tmp_47) => { - (*__tmp_47) = (((*__tmp_47) as i32) + (__tmp_46 as i32)) as i32; - (*__tmp_47).clone() - } + let _assigned: i32 = { + local += 5; + local }; let _stored: *const i32 = (&mut local as *mut i32).cast_const(); observe_7(_assigned, _stored) @@ -472,9 +640,9 @@ pub unsafe fn test_borrows_8() { c"%d\n".as_ptr() as *const libc::c_char, (unsafe { let _assigned: i32 = match ({ 99 }, &mut (record.value)) { - (__tmp_48, __tmp_49) => { - (*__tmp_49) = __tmp_48; - (*__tmp_49).clone() + (__tmp_56, __tmp_57) => { + (*__tmp_57) = __tmp_56; + (*__tmp_57).clone() } }; let _stored: *const i32 = (&mut record.value as *mut i32).cast_const(); @@ -487,9 +655,9 @@ pub unsafe fn test_borrows_8() { c"%d\n".as_ptr() as *const libc::c_char, (unsafe { let _assigned: i32 = match ({ 5 }, &mut (record.value)) { - (__tmp_50, __tmp_51) => { - (*__tmp_51) = (((*__tmp_51) as i32) + (__tmp_50 as i32)) as i32; - (*__tmp_51).clone() + (__tmp_58, __tmp_59) => { + (*__tmp_59) = (((*__tmp_59) as i32) + (__tmp_58 as i32)) as i32; + (*__tmp_59).clone() } }; let _stored: *const i32 = (&mut record.value as *mut i32).cast_const(); @@ -503,9 +671,9 @@ pub unsafe fn test_borrows_8() { c"%d\n".as_ptr() as *const libc::c_char, (unsafe { let _assigned: i32 = match ({ 99 }, &mut (values[(0_usize)])) { - (__tmp_52, __tmp_53) => { - (*__tmp_53) = __tmp_52; - (*__tmp_53).clone() + (__tmp_60, __tmp_61) => { + (*__tmp_61) = __tmp_60; + (*__tmp_61).clone() } }; let _stored: *const i32 = (&mut values[(0_usize)] as *mut i32).cast_const(); @@ -518,9 +686,9 @@ pub unsafe fn test_borrows_8() { c"%d\n".as_ptr() as *const libc::c_char, (unsafe { let _assigned: i32 = match ({ 5 }, &mut (values[(0_usize)])) { - (__tmp_54, __tmp_55) => { - (*__tmp_55) = (((*__tmp_55) as i32) + (__tmp_54 as i32)) as i32; - (*__tmp_55).clone() + (__tmp_62, __tmp_63) => { + (*__tmp_63) = (((*__tmp_63) as i32) + (__tmp_62 as i32)) as i32; + (*__tmp_63).clone() } }; let _stored: *const i32 = (&mut values[(0_usize)] as *mut i32).cast_const(); @@ -534,6 +702,39 @@ pub unsafe fn test_borrows_8() { pub struct Record_9 { pub value: i32, } +pub static mut selected_values_10: std::cell::LazyCell<[u32; 3]> = + std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct IndexedBinding {} +impl IndexedBinding { + pub unsafe fn get_1_0(&mut self) -> *mut u32 { + return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_10)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_10))[(0) as usize]) + as usize]; + } +} +pub unsafe fn test_binding_11() { + let mut owner: IndexedBinding = ::default(); + let __decomp_12: *mut IndexedBinding = &mut owner; + let value: *mut u32 = (unsafe { IndexedBinding::get_1_0(&mut (*__decomp_12)) }); + let mut result: u32 = (match ( + { 1_u32 }, + &mut (*(unsafe { IndexedBinding::get_1_0(&mut (*__decomp_12)) })), + ) { + (__tmp_64, __tmp_65) => { + (*__tmp_65) = (((*__tmp_65) as u32).wrapping_add((__tmp_64 as u32))) as u32; + (*__tmp_65).clone() + } + }); + (unsafe { + libc::printf( + c"binding compound %u %u\n".as_ptr() as *const libc::c_char, + (result), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_10))[(0) as usize]), + ) + }); +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -556,9 +757,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_56, __tmp_57) => { - (*__tmp_57) = (((*__tmp_57) as u32).wrapping_add((__tmp_56 as u32))) as u32; - (*__tmp_57).clone() + (__tmp_66, __tmp_67) => { + (*__tmp_67) = (((*__tmp_67) as u32).wrapping_add((__tmp_66 as u32))) as u32; + (*__tmp_67).clone() } }); (unsafe { @@ -570,8 +771,10 @@ unsafe fn main_0() -> i32 { ) }); (unsafe { test_borrows_8() }); + (unsafe { test_binding_11() }); return 0; } pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const global_5); + std::cell::LazyCell::force(&*&raw const selected_values_10); } diff --git a/tests/unit/out/unsafe/compound_assign_paren.rs b/tests/unit/out/unsafe/compound_assign_paren.rs index 0705b27804..62b97b7011 100644 --- a/tests/unit/out/unsafe/compound_assign_paren.rs +++ b/tests/unit/out/unsafe/compound_assign_paren.rs @@ -20,49 +20,21 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut item: Item = Item { flags: 0_u8 }; let mut ptr: *mut Item = (&mut item as *mut Item); - match ({ ((1) << (0)) }, &mut ((*(ptr)).flags)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as i32) | (__tmp_0 as i32)) as u8; - } - }; - match ({ ((1) << (1)) }, &mut ((*(ptr)).flags)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = (((*__tmp_3) as i32) | (__tmp_2 as i32)) as u8; - } - }; + (*(ptr)).flags = (((*(ptr)).flags as i32) | ((1) << (0))) as u8; + (*(ptr)).flags = (((*(ptr)).flags as i32) | ((1) << (1))) as u8; assert!((((*ptr).flags as i32) == (3))); - match ({ ((!((1) << (0)) as u8) as i32) }, &mut ((*(ptr)).flags)) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) as u8; - } - }; + (*(ptr)).flags = (((*(ptr)).flags as i32) & ((!((1) << (0)) as u8) as i32)) as u8; assert!((((*ptr).flags as i32) == (2))); let mut bits: [u8; 4] = [0_u8; 4]; - match ( - { ((((1) << ((5) & (7))) as u8) as i32) }, - &mut ((bits)[((5) / (8)) as usize]), - ) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as i32) | (__tmp_6 as i32)) as u8; - } - }; - match ( - { ((((1) << ((13) & (7))) as u8) as i32) }, - &mut ((bits)[((13) / (8)) as usize]), - ) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as i32) | (__tmp_8 as i32)) as u8; - } - }; + (bits)[((5) / (8)) as usize] = + (((bits)[((5) / (8)) as usize] as i32) | ((((1) << ((5) & (7))) as u8) as i32)) as u8; + (bits)[((13) / (8)) as usize] = + (((bits)[((13) / (8)) as usize] as i32) | ((((1) << ((13) & (7))) as u8) as i32)) as u8; assert!(((bits[(0) as usize] as i32) == (32))); assert!(((bits[(1) as usize] as i32) == (32))); assert!(((bits[(2) as usize] as i32) == (0))); if (((*ptr).flags as i32) != (0)) { - match ({ ((!((1) << (1)) as u8) as i32) }, &mut ((*(ptr)).flags)) { - (__tmp_10, __tmp_11) => { - (*__tmp_11) = (((*__tmp_11) as i32) & (__tmp_10 as i32)) as u8; - } - }; + (*(ptr)).flags = (((*(ptr)).flags as i32) & ((!((1) << (1)) as u8) as i32)) as u8; } assert!((((*ptr).flags as i32) == (0))); return 0; diff --git a/tests/unit/out/unsafe/copy_move_defaulted.rs b/tests/unit/out/unsafe/copy_move_defaulted.rs index 884c0e59cc..88fb268944 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -283,11 +283,9 @@ unsafe fn main_0() -> i32 { assert!((unsafe { same_0(&e, &b,) }) && (unsafe { same_0(&f, &c,) })); let mut g: Explicit = Explicit::new({ 4 }); let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { (*__p).destructor() }); - g = match ({ (f).clone() }, &mut (e)) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } + g = { + e = (f).clone(); + (e).clone() }; assert!((unsafe { same_0(&g, &f,) }) && (unsafe { same_0(&e, &f,) })); let mut i: Implicit = Implicit { @@ -356,8 +354,8 @@ unsafe fn main_0() -> i32 { bufs.push(__a1) }; { - let mut __tmp_6 = { Buffer::move_from({ &mut bufs[(0_usize)] }) }; - bufs.push_mut(__tmp_6) + let mut __tmp_4 = { Buffer::move_from({ &mut bufs[(0_usize)] }) }; + bufs.push_mut(__tmp_4) }; assert!( (((bufs[(1_usize)].n) == (3)) && ((bufs[(1_usize)].data.len()) == (3_usize))) diff --git a/tests/unit/out/unsafe/destructor.rs b/tests/unit/out/unsafe/destructor.rs index beb2b9aac3..7779f7c8f6 100644 --- a/tests/unit/out/unsafe/destructor.rs +++ b/tests/unit/out/unsafe/destructor.rs @@ -74,14 +74,9 @@ pub struct Templated_char_ { } impl Templated_char_ { pub unsafe fn destructor(&mut self) { - match ( - { ::std::mem::size_of::() }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as usize).wrapping_add((__tmp_0 as usize))) as i32; - } - }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) = + (((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) as usize) + .wrapping_add((::std::mem::size_of::() as usize))) as i32; } } #[repr(C)] @@ -91,14 +86,9 @@ pub struct Templated_int_ { } impl Templated_int_ { pub unsafe fn destructor(&mut self) { - match ( - { ::std::mem::size_of::() }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = (((*__tmp_3) as usize).wrapping_add((__tmp_2 as usize))) as i32; - } - }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) = + (((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) as usize) + .wrapping_add((::std::mem::size_of::() as usize))) as i32; } } #[repr(C)] diff --git a/tests/unit/out/unsafe/expr_as_bool_c.rs b/tests/unit/out/unsafe/expr_as_bool_c.rs index e15c20838e..81d5a5f240 100644 --- a/tests/unit/out/unsafe/expr_as_bool_c.rs +++ b/tests/unit/out/unsafe/expr_as_bool_c.rs @@ -24,18 +24,14 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut a: i32 = 0; let mut b: i32 = 0_i32; - if (match ({ a }, &mut (b)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + if ({ + b = a; + b } != 0) {} - 'loop_: while ((match ({ a }, &mut (b)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + 'loop_: while (({ + b = a; + b }) != (0)) {} if (a != 0) {} @@ -43,25 +39,19 @@ unsafe fn main_0() -> i32 { if ((a) < (b)) {} assert!(((a) == (b))); assert!( - !((match ({ b }, &mut (a)) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } + !(({ + a = b; + a }) != 0) ); let mut c: bool = false; - c = (match ({ b }, &mut (a)) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = __tmp_6; - (*__tmp_7).clone() - } + c = ({ + a = b; + a } != 0); - c = ((match ({ a }, &mut (b)) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = __tmp_8; - (*__tmp_9).clone() - } + c = (({ + b = a; + b }) != (0)); c = (a != 0); c = ((a) == (b)); diff --git a/tests/unit/out/unsafe/expr_as_bool_cpp.rs b/tests/unit/out/unsafe/expr_as_bool_cpp.rs index aef0ea8963..65c2f1add3 100644 --- a/tests/unit/out/unsafe/expr_as_bool_cpp.rs +++ b/tests/unit/out/unsafe/expr_as_bool_cpp.rs @@ -24,18 +24,14 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut a: i32 = 0; let mut b: i32 = 0_i32; - if (match ({ a }, &mut (b)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + if ({ + b = a; + b } != 0) {} - 'loop_: while ((match ({ a }, &mut (b)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + 'loop_: while (({ + b = a; + b }) != (0)) {} if (a != 0) {} @@ -43,25 +39,19 @@ unsafe fn main_0() -> i32 { if ((a) < (b)) {} assert!(((a) == (b))); assert!( - !((match ({ b }, &mut (a)) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = __tmp_4; - (*__tmp_5).clone() - } + !(({ + a = b; + a }) != 0) ); let mut c: bool = false; - c = (match ({ b }, &mut (a)) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = __tmp_6; - (*__tmp_7).clone() - } + c = ({ + a = b; + a } != 0); - c = ((match ({ a }, &mut (b)) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = __tmp_8; - (*__tmp_9).clone() - } + c = (({ + b = a; + b }) != (0)); c = (a != 0); c = ((a) == (b)); diff --git a/tests/unit/out/unsafe/field_pointers_malloced_struct.rs b/tests/unit/out/unsafe/field_pointers_malloced_struct.rs index d95c685436..68f4736b65 100644 --- a/tests/unit/out/unsafe/field_pointers_malloced_struct.rs +++ b/tests/unit/out/unsafe/field_pointers_malloced_struct.rs @@ -50,11 +50,9 @@ unsafe fn main_0() -> i32 { })); assert!(((x) == (8)) && (((*s).b) == (3))); let mut y: i32 = 0; - (*s).c = (match ({ 99 }, &mut (y)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + (*s).c = ({ + y = 99; + y }); assert!((((*s).c) == (99)) && ((y) == (99))); (*s).a += (unsafe { bump_0(s) }); diff --git a/tests/unit/out/unsafe/fn_ptr.rs b/tests/unit/out/unsafe/fn_ptr.rs index 4072ecfdee..6a79f9b0e5 100644 --- a/tests/unit/out/unsafe/fn_ptr.rs +++ b/tests/unit/out/unsafe/fn_ptr.rs @@ -19,11 +19,7 @@ pub unsafe fn twice_2(mut x: u64) -> u64 { return (x).wrapping_mul(2_u64); } pub unsafe fn twice_in_place_3(x: *mut u64) -> u64 { - match ({ 2_u64 }, &mut (*x)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as u64).wrapping_mul((__tmp_0 as u64))) as u64; - } - }; + (*x) = (*x).wrapping_mul(2_u64); return (*x); } pub unsafe fn ret_size_4(mut v: i32) -> usize { @@ -90,11 +86,11 @@ unsafe fn main_0() -> i32 { assert!(((m) == (42_usize))); assert!(((unsafe { call_fn_5(Some(ret_size_4), 3,) }) == (8_usize))); let mut hh: HashHolder_unsigned_long__ptr__bool__ = { - let mut __tmp_2: Option u64> = std::mem::transmute::< + let mut __tmp_0: Option u64> = std::mem::transmute::< Option usize>, Option u64>, >(Some(identity_hash_6)); - HashHolder_unsigned_long__ptr__bool__::new({ &mut __tmp_2 }) + HashHolder_unsigned_long__ptr__bool__::new({ &mut __tmp_0 }) }; assert!(((unsafe { (hh.h).unwrap()(true,) }) == (1_u64))); let mut handler: Option = Some(add_to_total_8); diff --git a/tests/unit/out/unsafe/immutable_unsigned_arithmetic.rs b/tests/unit/out/unsafe/immutable_unsigned_arithmetic.rs index e44ca4509a..483651b3e8 100644 --- a/tests/unit/out/unsafe/immutable_unsigned_arithmetic.rs +++ b/tests/unit/out/unsafe/immutable_unsigned_arithmetic.rs @@ -15,11 +15,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut a: u32 = 0_u32; let mut p: *mut u32 = (&mut a as *mut u32); - match ({ (*p) }, &mut (*p)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; - } - }; + (*p) = (*p).wrapping_add((*p)); return ((*p) as i32); } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/inet_pton_ntop.rs b/tests/unit/out/unsafe/inet_pton_ntop.rs index ea12814d1f..04060d5353 100644 --- a/tests/unit/out/unsafe/inet_pton_ntop.rs +++ b/tests/unit/out/unsafe/inet_pton_ntop.rs @@ -50,14 +50,8 @@ pub unsafe fn test_s6_addr_access_0() { ((((*(&mut addr as *mut ::libc::in6_addr)).s6_addr[(0) as usize] as i32) == (32)) && (((*(ap as *mut ::libc::in6_addr)).s6_addr[(1) as usize] as i32) == (1))) ); - match ( - { 4 }, - &mut ((*(&mut addr as *mut ::libc::in6_addr)).s6_addr[(15) as usize]), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = (((*__tmp_3) as i32) + (__tmp_2 as i32)) as u8; - } - }; + (*(&mut addr as *mut ::libc::in6_addr)).s6_addr[(15) as usize] = + (((*(&mut addr as *mut ::libc::in6_addr)).s6_addr[(15) as usize] as i32) + 4) as u8; (*(ap as *mut ::libc::in6_addr)).s6_addr[(15) as usize].postfix_inc(); assert!((((*(&mut addr as *mut ::libc::in6_addr)).s6_addr[(15) as usize] as i32) == (6))); let mut bytes: *mut u8 = (*(&mut addr as *mut ::libc::in6_addr)).s6_addr.as_mut_ptr(); @@ -68,13 +62,13 @@ pub unsafe fn test_s6_addr_access_0() { (*fourth) = 8_u8; assert!((((*(&mut addr as *mut ::libc::in6_addr)).s6_addr[(3) as usize] as i32) == (8))); { - let mut __tmp_4 = + let mut __tmp_2 = { ((*(ap as *mut ::libc::in6_addr)).s6_addr.as_mut_ptr() as *mut ::libc::c_void) }; - let mut __tmp_5 = { (loopback.as_ptr() as *const ::libc::c_void) }; + let mut __tmp_3 = { (loopback.as_ptr() as *const ::libc::c_void) }; if 16_usize != 0 { - ::std::ptr::copy_nonoverlapping(__tmp_5, __tmp_4, 16_usize) + ::std::ptr::copy_nonoverlapping(__tmp_3, __tmp_2, 16_usize) } - __tmp_4 + __tmp_2 }; assert!( (({ diff --git a/tests/unit/out/unsafe/inline_container_fields.rs b/tests/unit/out/unsafe/inline_container_fields.rs index 253d88b085..57a96262be 100644 --- a/tests/unit/out/unsafe/inline_container_fields.rs +++ b/tests/unit/out/unsafe/inline_container_fields.rs @@ -219,11 +219,7 @@ unsafe fn main_0() -> i32 { k.prefix_inc(); } } - match ({ 5 }, &mut (*c)) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = (((*__tmp_5) as i32) + (__tmp_4 as i32)) as i16; - } - }; + (*c) = (((*c) as i32) + 5) as i16; (*id) = 11; s.count = 3; assert!( diff --git a/tests/unit/out/unsafe/lambda_generic.rs b/tests/unit/out/unsafe/lambda_generic.rs index b74abfbd87..5d2d06cf34 100644 --- a/tests/unit/out/unsafe/lambda_generic.rs +++ b/tests/unit/out/unsafe/lambda_generic.rs @@ -50,11 +50,7 @@ unsafe fn main_0() -> i32 { (*total) += ((x) * (y)); }, |mut x: u32, mut y: u32| { - match ({ (x).wrapping_mul(y) }, &mut (*total)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as i32; - } - }; + (*total) = (((*total) as u32).wrapping_add((x).wrapping_mul(y))) as i32; } ); (unsafe { accumulate.spec::(0).call(2, 3) }); diff --git a/tests/unit/out/unsafe/lambda_generic_explicit_args.rs b/tests/unit/out/unsafe/lambda_generic_explicit_args.rs index 69374b2b49..43b63fcd28 100644 --- a/tests/unit/out/unsafe/lambda_generic_explicit_args.rs +++ b/tests/unit/out/unsafe/lambda_generic_explicit_args.rs @@ -28,30 +28,18 @@ unsafe fn main_0() -> i32 { let total: *mut i32 = &mut total; }, || { - match ( - { - (::std::mem::size_of::() as usize) - .wrapping_add((::std::mem::size_of::() as usize)) - }, - &mut (*total), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as usize).wrapping_add((__tmp_0 as usize))) as i32; - } - }; + (*total) = (((*total) as usize).wrapping_add( + ((::std::mem::size_of::() as usize) + .wrapping_add((::std::mem::size_of::() as usize)) + as usize), + )) as i32; }, || { - match ( - { - (::std::mem::size_of::() as usize) - .wrapping_add((::std::mem::size_of::() as usize)) - }, - &mut (*total), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = (((*__tmp_3) as usize).wrapping_add((__tmp_2 as usize))) as i32; - } - }; + (*total) = (((*total) as usize).wrapping_add( + ((::std::mem::size_of::() as usize) + .wrapping_add((::std::mem::size_of::() as usize)) + as usize), + )) as i32; } ); (unsafe { tally.spec::(0).call() }); diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 97a26a65f0..3438895e9c 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -83,56 +83,36 @@ unsafe fn main_0() -> i32 { let mut b: Key = Key::new({ 2 }); let mut c: Key = Key::new({ 3 }); (*m.subscript(&a, || 0_i32)) = 10; - match ( - { (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1)) as i32) }, - &mut (ok), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as i32) & (__tmp_0 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1)) as i32)) + != 0; (*m.subscript(&b, || 0_i32)) = 20; - match ( - { (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32) }, - &mut (ok), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = (((*__tmp_3) as i32) & (__tmp_2 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32)) + != 0; (*m.subscript(&a, || 0_i32)) = 11; - match ( - { (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32) }, - &mut (ok), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32)) + != 0; match ( { ((((*m.find(&a).iter_deref()).1) == (11)) as i32) }, &mut (ok), ) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as i32) & (__tmp_6 as i32)) != 0; + (__tmp_0, __tmp_1) => { + (*__tmp_1) = (((*__tmp_1) as i32) & (__tmp_0 as i32)) != 0; } }; match ( { ((((*m.get(&b).expect("out of range!")).1) == (20)) as i32) }, &mut (ok), ) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as i32) & (__tmp_8 as i32)) != 0; - } - }; - match ( - { (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32) }, - &mut (ok), - ) { - (__tmp_10, __tmp_11) => { - (*__tmp_11) = (((*__tmp_11) as i32) & (__tmp_10 as i32)) != 0; + (__tmp_2, __tmp_3) => { + (*__tmp_3) = (((*__tmp_3) as i32) & (__tmp_2 as i32)) != 0; } }; + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32)) + != 0; (*m.subscript_move( &mut (unsafe { make_key_3(4) }), |__k| cpp_move_unsafe!(__k), @@ -143,36 +123,22 @@ unsafe fn main_0() -> i32 { |__k| cpp_move_unsafe!(__k), || 0_i32, )) = 41; - match ( - { - (((((*std::cell::LazyCell::force_mut(&mut *&raw mut made_2)) == (2)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (1))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2))) - as i32) - }, - &mut (ok), - ) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = (((*__tmp_13) as i32) & (__tmp_12 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (((((*std::cell::LazyCell::force_mut(&mut *&raw mut made_2)) == (2)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (1))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2))) + as i32)) + != 0; (*m.subscript_move(&mut c, |__k| cpp_move_unsafe!(__k), || 0_i32)) = 30; (*m.subscript_move(&mut c, |__k| cpp_move_unsafe!(__k), || 0_i32)) = 31; - match ( - { - (((((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (2)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2))) - && ((c.k) == (3))) as i32) - }, - &mut (ok), - ) { - (__tmp_14, __tmp_15) => { - (*__tmp_15) = (((*__tmp_15) as i32) & (__tmp_14 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (((((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (2)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2))) + && ((c.k) == (3))) as i32)) + != 0; match ({ (((m.len()) == (4_usize)) as i32) }, &mut (ok)) { - (__tmp_16, __tmp_17) => { - (*__tmp_17) = (((*__tmp_17) as i32) & (__tmp_16 as i32)) != 0; + (__tmp_4, __tmp_5) => { + (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) != 0; } }; (*m.subscript(&(*m.begin().iter_deref()).0, || 0_i32)) += 1; @@ -183,82 +149,65 @@ unsafe fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_18, __tmp_19) => { - (*__tmp_19) = (((*__tmp_19) as i32) & (__tmp_18 as i32)) != 0; + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as i32) & (__tmp_6 as i32)) != 0; } }; let mut first: *const Key = (&(*m.begin().iter_deref()).0 as *const Key); (*m.subscript_move(&mut Key::new({ 0 }), |__k| cpp_move_unsafe!(__k), || 0_i32)) = 0; - match ( - { (((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (3)) as i32) }, - &mut (ok), - ) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = (((*__tmp_21) as i32) & (__tmp_20 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (3)) as i32)) + != 0; match ( { (((&(*m.find(&a).iter_deref()).0 as *const Key) == (first)) as i32) }, &mut (ok), ) { - (__tmp_22, __tmp_23) => { - (*__tmp_23) = (((*__tmp_23) as i32) & (__tmp_22 as i32)) != 0; + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as i32) & (__tmp_8 as i32)) != 0; } }; let mut n: UnsafeMap = m.clone(); - match ( - { (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == ((2) + (5))) as i32) }, - &mut (ok), - ) { - (__tmp_24, __tmp_25) => { - (*__tmp_25) = (((*__tmp_25) as i32) & (__tmp_24 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == ((2) + (5))) as i32)) + != 0; match ( { ((((n.len()) == (5_usize)) && ((*n.subscript(&a, || 0_i32)) == (12))) as i32) }, &mut (ok), ) { - (__tmp_26, __tmp_27) => { - (*__tmp_27) = (((*__tmp_27) as i32) & (__tmp_26 as i32)) != 0; + (__tmp_10, __tmp_11) => { + (*__tmp_11) = (((*__tmp_11) as i32) & (__tmp_10 as i32)) != 0; } }; m.erase(&m.find(&a)); match ({ (((m.erase_key(&b)) == (1_usize)) as i32) }, &mut (ok)) { - (__tmp_28, __tmp_29) => { - (*__tmp_29) = (((*__tmp_29) as i32) & (__tmp_28 as i32)) != 0; + (__tmp_12, __tmp_13) => { + (*__tmp_13) = (((*__tmp_13) as i32) & (__tmp_12 as i32)) != 0; } }; match ({ (((m.erase_key(&b)) == (0_usize)) as i32) }, &mut (ok)) { - (__tmp_30, __tmp_31) => { - (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; + (__tmp_14, __tmp_15) => { + (*__tmp_15) = (((*__tmp_15) as i32) & (__tmp_14 as i32)) != 0; } }; match ( { (((m.erase_key(&(*m.begin().iter_deref()).0)) == (1_usize)) as i32) }, &mut (ok), ) { - (__tmp_32, __tmp_33) => { - (*__tmp_33) = (((*__tmp_33) as i32) & (__tmp_32 as i32)) != 0; - } - }; - match ( - { - ((((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (7)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (3))) - as i32) - }, - &mut (ok), - ) { - (__tmp_34, __tmp_35) => { - (*__tmp_35) = (((*__tmp_35) as i32) & (__tmp_34 as i32)) != 0; + (__tmp_16, __tmp_17) => { + (*__tmp_17) = (((*__tmp_17) as i32) & (__tmp_16 as i32)) != 0; } }; + ok = ((ok as i32) + & ((((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (7)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (3))) + as i32)) + != 0; match ( { ((((m.len()) == (2_usize)) && ((n.len()) == (5_usize))) as i32) }, &mut (ok), ) { - (__tmp_36, __tmp_37) => { - (*__tmp_37) = (((*__tmp_37) as i32) & (__tmp_36 as i32)) != 0; + (__tmp_18, __tmp_19) => { + (*__tmp_19) = (((*__tmp_19) as i32) & (__tmp_18 as i32)) != 0; } }; let mut sum: i32 = 0; @@ -266,26 +215,12 @@ unsafe fn main_0() -> i32 { let entry: *const (Key, i32) = &(*entry.iter_deref()); sum += (((*entry).0.k) * ((*entry).1)); } - match ( - { (((sum) == (((3) * (31)) + ((4) * (41)))) as i32) }, - &mut (ok), - ) { - (__tmp_38, __tmp_39) => { - (*__tmp_39) = (((*__tmp_39) as i32) & (__tmp_38 as i32)) != 0; - } - }; - match ( - { - ((((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (7)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (3))) - as i32) - }, - &mut (ok), - ) { - (__tmp_40, __tmp_41) => { - (*__tmp_41) = (((*__tmp_41) as i32) & (__tmp_40 as i32)) != 0; - } - }; + ok = ((ok as i32) & (((sum) == (((3) * (31)) + ((4) * (41)))) as i32)) != 0; + ok = ((ok as i32) + & ((((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (7)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (3))) + as i32)) + != 0; (unsafe { libc::printf( c"%d %d %d\n".as_ptr() as *const libc::c_char, diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index 9f47f4f24b..cce7d71f9f 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -95,78 +95,53 @@ unsafe fn main_0() -> i32 { (*a).value = 11; let mut a_it: UnsafeBidirectionalIterator<(Key, Mapped)> = distinct.find(&distinct_a); let mut a_value: *mut Mapped = (&mut (*a_it.iter_deref()).1 as *mut Mapped); - match ( - { - (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == (1)) - as i32) - }, - &mut (ok), - ) { + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == (1)) + as i32)) + != 0; + let b: *mut Mapped = &mut (*distinct.subscript(&distinct_b, || ::default())); + (*b).value = 22; + let mut b_it: UnsafeBidirectionalIterator<(Key, Mapped)> = distinct.find(&distinct_b); + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == (2)) + as i32)) + != 0; + match ({ (((distinct.len()) == (2_usize)) as i32) }, &mut (ok)) { (__tmp_2, __tmp_3) => { (*__tmp_3) = (((*__tmp_3) as i32) & (__tmp_2 as i32)) != 0; } }; - let b: *mut Mapped = &mut (*distinct.subscript(&distinct_b, || ::default())); - (*b).value = 22; - let mut b_it: UnsafeBidirectionalIterator<(Key, Mapped)> = distinct.find(&distinct_b); - match ( - { - (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == (2)) - as i32) - }, - &mut (ok), - ) { + ok = ((ok as i32) & (((a) != (b)) as i32)) != 0; + ok = ((ok as i32) & (((((*a).value) == (11)) && (((*b).value) == (22))) as i32)) != 0; + match ({ ((a_it == distinct.find(&distinct_a)) as i32) }, &mut (ok)) { (__tmp_4, __tmp_5) => { (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) != 0; } }; - match ({ (((distinct.len()) == (2_usize)) as i32) }, &mut (ok)) { + match ({ ((b_it == distinct.find(&distinct_b)) as i32) }, &mut (ok)) { (__tmp_6, __tmp_7) => { (*__tmp_7) = (((*__tmp_7) as i32) & (__tmp_6 as i32)) != 0; } }; - match ({ (((a) != (b)) as i32) }, &mut (ok)) { + match ({ ((b_it != distinct.end()) as i32) }, &mut (ok)) { (__tmp_8, __tmp_9) => { (*__tmp_9) = (((*__tmp_9) as i32) & (__tmp_8 as i32)) != 0; } }; match ( - { (((((*a).value) == (11)) && (((*b).value) == (22))) as i32) }, + { (((&mut (*a_it.iter_deref()).1 as *mut Mapped) == (a_value)) as i32) }, &mut (ok), ) { (__tmp_10, __tmp_11) => { (*__tmp_11) = (((*__tmp_11) as i32) & (__tmp_10 as i32)) != 0; } }; - match ({ ((a_it == distinct.find(&distinct_a)) as i32) }, &mut (ok)) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = (((*__tmp_13) as i32) & (__tmp_12 as i32)) != 0; - } - }; - match ({ ((b_it == distinct.find(&distinct_b)) as i32) }, &mut (ok)) { - (__tmp_14, __tmp_15) => { - (*__tmp_15) = (((*__tmp_15) as i32) & (__tmp_14 as i32)) != 0; - } - }; - match ({ ((b_it != distinct.end()) as i32) }, &mut (ok)) { - (__tmp_16, __tmp_17) => { - (*__tmp_17) = (((*__tmp_17) as i32) & (__tmp_16 as i32)) != 0; - } - }; - match ( - { (((&mut (*a_it.iter_deref()).1 as *mut Mapped) == (a_value)) as i32) }, - &mut (ok), - ) { - (__tmp_18, __tmp_19) => { - (*__tmp_19) = (((*__tmp_19) as i32) & (__tmp_18 as i32)) != 0; - } - }; match ( { ((((*a_it.iter_deref()).1.value) == (11)) as i32) }, &mut (ok), ) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = (((*__tmp_21) as i32) & (__tmp_20 as i32)) != 0; + (__tmp_12, __tmp_13) => { + (*__tmp_13) = (((*__tmp_13) as i32) & (__tmp_12 as i32)) != 0; } }; match ( @@ -178,39 +153,25 @@ unsafe fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_22, __tmp_23) => { - (*__tmp_23) = (((*__tmp_23) as i32) & (__tmp_22 as i32)) != 0; + (__tmp_14, __tmp_15) => { + (*__tmp_15) = (((*__tmp_15) as i32) & (__tmp_14 as i32)) != 0; } }; let mut distinct_count: usize = 0_usize; 'loop_: for entry in IterRange::new(distinct.begin(), distinct.end()) { let entry: *const (Key, Mapped) = &(*entry.iter_deref()); if ((distinct_count) == (0_usize)) { - match ( - { (((((*entry).0.order) == (1)) && (((*entry).1.value) == (11))) as i32) }, - &mut (ok), - ) { - (__tmp_24, __tmp_25) => { - (*__tmp_25) = (((*__tmp_25) as i32) & (__tmp_24 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (((((*entry).0.order) == (1)) && (((*entry).1.value) == (11))) as i32)) + != 0; } else if ((distinct_count) == (1_usize)) { - match ( - { (((((*entry).0.order) == (2)) && (((*entry).1.value) == (22))) as i32) }, - &mut (ok), - ) { - (__tmp_26, __tmp_27) => { - (*__tmp_27) = (((*__tmp_27) as i32) & (__tmp_26 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (((((*entry).0.order) == (2)) && (((*entry).1.value) == (22))) as i32)) + != 0; } distinct_count.prefix_inc(); } - match ({ (((distinct_count) == (2_usize)) as i32) }, &mut (ok)) { - (__tmp_28, __tmp_29) => { - (*__tmp_29) = (((*__tmp_29) as i32) & (__tmp_28 as i32)) != 0; - } - }; + ok = ((ok as i32) & (((distinct_count) == (2_usize)) as i32)) != 0; let equivalent_a: Key = Key { order: 3, identity: 8, @@ -228,8 +189,8 @@ unsafe fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_30, __tmp_31) => { - (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; + (__tmp_16, __tmp_17) => { + (*__tmp_17) = (((*__tmp_17) as i32) & (__tmp_16 as i32)) != 0; } }; let mut equivalent: UnsafeMap = UnsafeMap::new(); @@ -239,63 +200,48 @@ unsafe fn main_0() -> i32 { (*first).value = 31; let mut first_it: UnsafeBidirectionalIterator<(Key, Mapped)> = equivalent.find(&equivalent_a); let mut first_value: *mut Mapped = (&mut (*first_it.iter_deref()).1 as *mut Mapped); - match ( - { - (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) - == ((before_equivalent) + (1))) as i32) - }, - &mut (ok), - ) { - (__tmp_32, __tmp_33) => { - (*__tmp_33) = (((*__tmp_33) as i32) & (__tmp_32 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) + == ((before_equivalent) + (1))) as i32)) + != 0; let second: *mut Mapped = &mut (*equivalent.subscript(&equivalent_b, || ::default())); let reused: bool = ((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == ((before_equivalent) + (1))); - match ({ (reused as i32) }, &mut (ok)) { - (__tmp_34, __tmp_35) => { - (*__tmp_35) = (((*__tmp_35) as i32) & (__tmp_34 as i32)) != 0; - } - }; + ok = ((ok as i32) & (reused as i32)) != 0; match ({ (((equivalent.len()) == (1_usize)) as i32) }, &mut (ok)) { - (__tmp_36, __tmp_37) => { - (*__tmp_37) = (((*__tmp_37) as i32) & (__tmp_36 as i32)) != 0; + (__tmp_18, __tmp_19) => { + (*__tmp_19) = (((*__tmp_19) as i32) & (__tmp_18 as i32)) != 0; } }; if reused { match ({ ((first_it != equivalent.end()) as i32) }, &mut (ok)) { - (__tmp_38, __tmp_39) => { - (*__tmp_39) = (((*__tmp_39) as i32) & (__tmp_38 as i32)) != 0; - } - }; - match ({ (((first) == (second)) as i32) }, &mut (ok)) { - (__tmp_40, __tmp_41) => { - (*__tmp_41) = (((*__tmp_41) as i32) & (__tmp_40 as i32)) != 0; + (__tmp_20, __tmp_21) => { + (*__tmp_21) = (((*__tmp_21) as i32) & (__tmp_20 as i32)) != 0; } }; + ok = ((ok as i32) & (((first) == (second)) as i32)) != 0; match ( { ((first_it == equivalent.find(&equivalent_a)) as i32) }, &mut (ok), ) { - (__tmp_42, __tmp_43) => { - (*__tmp_43) = (((*__tmp_43) as i32) & (__tmp_42 as i32)) != 0; + (__tmp_22, __tmp_23) => { + (*__tmp_23) = (((*__tmp_23) as i32) & (__tmp_22 as i32)) != 0; } }; match ( { ((first_it == equivalent.find(&equivalent_b)) as i32) }, &mut (ok), ) { - (__tmp_44, __tmp_45) => { - (*__tmp_45) = (((*__tmp_45) as i32) & (__tmp_44 as i32)) != 0; + (__tmp_24, __tmp_25) => { + (*__tmp_25) = (((*__tmp_25) as i32) & (__tmp_24 as i32)) != 0; } }; match ( { (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32) }, &mut (ok), ) { - (__tmp_46, __tmp_47) => { - (*__tmp_47) = (((*__tmp_47) as i32) & (__tmp_46 as i32)) != 0; + (__tmp_26, __tmp_27) => { + (*__tmp_27) = (((*__tmp_27) as i32) & (__tmp_26 as i32)) != 0; } }; match ( @@ -305,28 +251,19 @@ unsafe fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_48, __tmp_49) => { - (*__tmp_49) = (((*__tmp_49) as i32) & (__tmp_48 as i32)) != 0; + (__tmp_28, __tmp_29) => { + (*__tmp_29) = (((*__tmp_29) as i32) & (__tmp_28 as i32)) != 0; } }; let mut equivalent_count: usize = 0_usize; 'loop_: for entry in IterRange::new(equivalent.begin(), equivalent.end()) { let entry: *const (Key, Mapped) = &(*entry.iter_deref()); - match ( - { (((((*entry).0.order) == (3)) && (((*entry).1.value) == (31))) as i32) }, - &mut (ok), - ) { - (__tmp_50, __tmp_51) => { - (*__tmp_51) = (((*__tmp_51) as i32) & (__tmp_50 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (((((*entry).0.order) == (3)) && (((*entry).1.value) == (31))) as i32)) + != 0; equivalent_count.prefix_inc(); } - match ({ (((equivalent_count) == (1_usize)) as i32) }, &mut (ok)) { - (__tmp_52, __tmp_53) => { - (*__tmp_53) = (((*__tmp_53) as i32) & (__tmp_52 as i32)) != 0; - } - }; + ok = ((ok as i32) & (((equivalent_count) == (1_usize)) as i32)) != 0; } match ( { @@ -337,8 +274,8 @@ unsafe fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_54, __tmp_55) => { - (*__tmp_55) = (((*__tmp_55) as i32) & (__tmp_54 as i32)) != 0; + (__tmp_30, __tmp_31) => { + (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; } }; let later_key: Key = Key { @@ -347,20 +284,13 @@ unsafe fn main_0() -> i32 { }; let later: *mut Mapped = &mut (*equivalent.subscript(&later_key, || ::default())); (*later).value = 41; - match ( - { - (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) - == ((before_equivalent) + (2))) as i32) - }, - &mut (ok), - ) { - (__tmp_56, __tmp_57) => { - (*__tmp_57) = (((*__tmp_57) as i32) & (__tmp_56 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) + == ((before_equivalent) + (2))) as i32)) + != 0; match ({ (((equivalent.len()) == (2_usize)) as i32) }, &mut (ok)) { - (__tmp_58, __tmp_59) => { - (*__tmp_59) = (((*__tmp_59) as i32) & (__tmp_58 as i32)) != 0; + (__tmp_32, __tmp_33) => { + (*__tmp_33) = (((*__tmp_33) as i32) & (__tmp_32 as i32)) != 0; } }; if reused { @@ -368,24 +298,24 @@ unsafe fn main_0() -> i32 { { ((first_it == equivalent.find(&equivalent_a)) as i32) }, &mut (ok), ) { - (__tmp_60, __tmp_61) => { - (*__tmp_61) = (((*__tmp_61) as i32) & (__tmp_60 as i32)) != 0; + (__tmp_34, __tmp_35) => { + (*__tmp_35) = (((*__tmp_35) as i32) & (__tmp_34 as i32)) != 0; } }; match ( { (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32) }, &mut (ok), ) { - (__tmp_62, __tmp_63) => { - (*__tmp_63) = (((*__tmp_63) as i32) & (__tmp_62 as i32)) != 0; + (__tmp_36, __tmp_37) => { + (*__tmp_37) = (((*__tmp_37) as i32) & (__tmp_36 as i32)) != 0; } }; match ( { ((((*first_it.iter_deref()).1.value) == (31)) as i32) }, &mut (ok), ) { - (__tmp_64, __tmp_65) => { - (*__tmp_65) = (((*__tmp_65) as i32) & (__tmp_64 as i32)) != 0; + (__tmp_38, __tmp_39) => { + (*__tmp_39) = (((*__tmp_39) as i32) & (__tmp_38 as i32)) != 0; } }; } @@ -408,104 +338,79 @@ unsafe fn main_0() -> i32 { (*matched).value = 51; let mut matched_it: UnsafeBidirectionalIterator<(Key, Mapped)> = matching.find(&matching_a); let mut matched_value: *mut Mapped = (&mut (*matched_it.iter_deref()).1 as *mut Mapped); - match ( - { - (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) - == ((before_matching) + (1))) as i32) - }, - &mut (ok), - ) { - (__tmp_66, __tmp_67) => { - (*__tmp_67) = (((*__tmp_67) as i32) & (__tmp_66 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) + == ((before_matching) + (1))) as i32)) + != 0; let matched_again: *mut Mapped = &mut (*matching.subscript(&matching_b, || ::default())); - match ( - { - (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) - == ((before_matching) + (1))) as i32) - }, - &mut (ok), - ) { - (__tmp_68, __tmp_69) => { - (*__tmp_69) = (((*__tmp_69) as i32) & (__tmp_68 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) + == ((before_matching) + (1))) as i32)) + != 0; match ({ (((matching.len()) == (1_usize)) as i32) }, &mut (ok)) { - (__tmp_70, __tmp_71) => { - (*__tmp_71) = (((*__tmp_71) as i32) & (__tmp_70 as i32)) != 0; - } - }; - match ({ (((matched) == (matched_again)) as i32) }, &mut (ok)) { - (__tmp_72, __tmp_73) => { - (*__tmp_73) = (((*__tmp_73) as i32) & (__tmp_72 as i32)) != 0; + (__tmp_40, __tmp_41) => { + (*__tmp_41) = (((*__tmp_41) as i32) & (__tmp_40 as i32)) != 0; } }; + ok = ((ok as i32) & (((matched) == (matched_again)) as i32)) != 0; match ( { ((matched_it == matching.find(&matching_b)) as i32) }, &mut (ok), ) { - (__tmp_74, __tmp_75) => { - (*__tmp_75) = (((*__tmp_75) as i32) & (__tmp_74 as i32)) != 0; + (__tmp_42, __tmp_43) => { + (*__tmp_43) = (((*__tmp_43) as i32) & (__tmp_42 as i32)) != 0; } }; match ( { (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32) }, &mut (ok), ) { - (__tmp_76, __tmp_77) => { - (*__tmp_77) = (((*__tmp_77) as i32) & (__tmp_76 as i32)) != 0; + (__tmp_44, __tmp_45) => { + (*__tmp_45) = (((*__tmp_45) as i32) & (__tmp_44 as i32)) != 0; } }; match ( { ((((*matched_it.iter_deref()).1.value) == (51)) as i32) }, &mut (ok), ) { - (__tmp_78, __tmp_79) => { - (*__tmp_79) = (((*__tmp_79) as i32) & (__tmp_78 as i32)) != 0; + (__tmp_46, __tmp_47) => { + (*__tmp_47) = (((*__tmp_47) as i32) & (__tmp_46 as i32)) != 0; } }; let other: *mut Mapped = &mut (*matching.subscript(&matching_c, || ::default())); (*other).value = 61; - match ( - { - (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) - == ((before_matching) + (2))) as i32) - }, - &mut (ok), - ) { - (__tmp_80, __tmp_81) => { - (*__tmp_81) = (((*__tmp_81) as i32) & (__tmp_80 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) + == ((before_matching) + (2))) as i32)) + != 0; match ({ (((matching.len()) == (2_usize)) as i32) }, &mut (ok)) { - (__tmp_82, __tmp_83) => { - (*__tmp_83) = (((*__tmp_83) as i32) & (__tmp_82 as i32)) != 0; + (__tmp_48, __tmp_49) => { + (*__tmp_49) = (((*__tmp_49) as i32) & (__tmp_48 as i32)) != 0; } }; match ( { ((matched_it == matching.find(&matching_a)) as i32) }, &mut (ok), ) { - (__tmp_84, __tmp_85) => { - (*__tmp_85) = (((*__tmp_85) as i32) & (__tmp_84 as i32)) != 0; + (__tmp_50, __tmp_51) => { + (*__tmp_51) = (((*__tmp_51) as i32) & (__tmp_50 as i32)) != 0; } }; match ( { (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32) }, &mut (ok), ) { - (__tmp_86, __tmp_87) => { - (*__tmp_87) = (((*__tmp_87) as i32) & (__tmp_86 as i32)) != 0; + (__tmp_52, __tmp_53) => { + (*__tmp_53) = (((*__tmp_53) as i32) & (__tmp_52 as i32)) != 0; } }; match ( { ((((*matched_it.iter_deref()).1.value) == (51)) as i32) }, &mut (ok), ) { - (__tmp_88, __tmp_89) => { - (*__tmp_89) = (((*__tmp_89) as i32) & (__tmp_88 as i32)) != 0; + (__tmp_54, __tmp_55) => { + (*__tmp_55) = (((*__tmp_55) as i32) & (__tmp_54 as i32)) != 0; } }; return if ok { 0 } else { 1 }; diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index 2a2c2edd99..1d3e9412b5 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -68,11 +68,9 @@ impl RefItem { } pub unsafe fn new_2(counter: *mut i32, mut amount: i32) -> Self { let mut this = Self { - value: match ({ amount }, &mut (*counter)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as i32) + (__tmp_0 as i32)) as i32; - (*__tmp_1).clone() - } + value: { + (*counter) += amount; + (*counter) }, }; (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)).prefix_inc(); @@ -105,15 +103,15 @@ pub static mut seed_9: std::cell::LazyCell = std::cell::LazyCell::new(|| un pub static mut global_hit_10: std::cell::LazyCell<(UnsafeBidirectionalIterator<(i32, i32)>, bool)> = std::cell::LazyCell::new(|| unsafe { match (({ - let __tmp_3 = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_counter_8)); - (*__tmp_3).prefix_inc(); - __tmp_3 + let __tmp_1 = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_counter_8)); + (*__tmp_1).prefix_inc(); + __tmp_1 } as *mut i32),) { - (__tmp_2,) => (*std::cell::LazyCell::force_mut(&mut *&raw mut global_map_6)) + (__tmp_0,) => (*std::cell::LazyCell::force_mut(&mut *&raw mut global_map_6)) .try_emplace( (*std::cell::LazyCell::force_mut(&mut *&raw mut global_key_7)), - || (*__tmp_2), + || (*__tmp_0), ), } }); @@ -170,71 +168,46 @@ unsafe fn main_0() -> i32 { UnsafeBidirectionalIterator<(i32, i32)>, bool, ) = { - let mut __tmp_5: i32; + let mut __tmp_3: i32; if (post != 0) { match (({ - __tmp_5 = counter.postfix_inc(); - &mut __tmp_5 + __tmp_3 = counter.postfix_inc(); + &mut __tmp_3 } as *mut i32),) { - (__tmp_4,) => m + (__tmp_2,) => m .try_emplace(key, || { - (*__tmp_4) + (*__tmp_2) }), } } else { match (({ - let __tmp_7 = &mut counter; - (*__tmp_7).prefix_inc(); - __tmp_7 + let __tmp_5 = &mut counter; + (*__tmp_5).prefix_inc(); + __tmp_5 } as *mut i32),) { - (__tmp_6,) => m + (__tmp_4,) => m .try_emplace(key, || { - (*__tmp_6) + (*__tmp_4) }), } } }; let mut hit: bool = (((subset) & ((1) << (key))) != (0)); - match ( - { - (((counter) == ((initial) + (1))) - as i32) - }, - &mut (ok), - ) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as i32) - & (__tmp_8 as i32)) - != 0; - } - }; - match ( - { - ((((result.1) as i32) - == (!(hit) as i32)) - as i32) - }, - &mut (ok), - ) { - (__tmp_10, __tmp_11) => { - (*__tmp_11) = (((*__tmp_11) as i32) - & (__tmp_10 as i32)) - != 0; - } - }; + ok = ((ok as i32) + & (((counter) == ((initial) + (1))) + as i32)) + != 0; + ok = ((ok as i32) + & ((((result.1) as i32) == (!(hit) as i32)) + as i32)) + != 0; let mut found: bool = result.0 == m.find(&key); - match ({ (found as i32) }, &mut (ok)) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = (((*__tmp_13) as i32) - & (__tmp_12 as i32)) - != 0; - } - }; + ok = ((ok as i32) & (found as i32)) != 0; match ( { ((((*result.0.iter_deref()).0) == (key)) @@ -242,9 +215,9 @@ unsafe fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_14, __tmp_15) => { - (*__tmp_15) = (((*__tmp_15) as i32) - & (__tmp_14 as i32)) + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as i32) + & (__tmp_6 as i32)) != 0; } }; @@ -261,9 +234,9 @@ unsafe fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_16, __tmp_17) => { - (*__tmp_17) = (((*__tmp_17) as i32) - & (__tmp_16 as i32)) + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as i32) + & (__tmp_8 as i32)) != 0; } }; @@ -276,9 +249,9 @@ unsafe fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_18, __tmp_19) => { - (*__tmp_19) = (((*__tmp_19) as i32) - & (__tmp_18 as i32)) + (__tmp_10, __tmp_11) => { + (*__tmp_11) = (((*__tmp_11) as i32) + & (__tmp_10 as i32)) != 0; } }; @@ -305,121 +278,81 @@ unsafe fn main_0() -> i32 { let mut source: Item = Item::new_1({ 20 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = match ( { - match ( - { 0 }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)), - ) { - (__tmp_22, __tmp_23) => { - (*__tmp_23) = __tmp_22; - (*__tmp_23).clone() - } + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) } }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)), ) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = __tmp_20; - (*__tmp_21).clone() + (__tmp_12, __tmp_13) => { + (*__tmp_13) = __tmp_12; + (*__tmp_13).clone() } }; let mut hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { argument_4(&mut source) }) as *mut Item),) { - (__tmp_24,) => items.try_emplace(key, || Item::copy_from({ __tmp_24 })), + (__tmp_14,) => items.try_emplace(key, || Item::copy_from({ __tmp_14 })), }; - match ( - { - ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (1)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) - as i32) - }, - &mut (ok), - ) { - (__tmp_25, __tmp_26) => { - (*__tmp_26) = (((*__tmp_26) as i32) & (__tmp_25 as i32)) != 0; - } - }; + ok = ((ok as i32) + & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (1)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) + as i32)) + != 0; match ( { (((!(hit.1)) && (((*hit.0.iter_deref()).1.value) == (10))) as i32) }, &mut (ok), ) { - (__tmp_27, __tmp_28) => { - (*__tmp_28) = (((*__tmp_28) as i32) & (__tmp_27 as i32)) != 0; + (__tmp_15, __tmp_16) => { + (*__tmp_16) = (((*__tmp_16) as i32) & (__tmp_15 as i32)) != 0; } }; let mut move_hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { argument_4(&mut source) }) as *mut Item),) { - (__tmp_29,) => items.try_emplace(key, || Item::move_from({ __tmp_29 })), + (__tmp_17,) => items.try_emplace(key, || Item::move_from({ __tmp_17 })), }; - match ( - { - ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (2)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) - as i32) - }, - &mut (ok), - ) { - (__tmp_30, __tmp_31) => { - (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; - } - }; - match ( - { (((!(move_hit.1)) && ((source.value) == (20))) as i32) }, - &mut (ok), - ) { - (__tmp_32, __tmp_33) => { - (*__tmp_33) = (((*__tmp_33) as i32) & (__tmp_32 as i32)) != 0; - } - }; + ok = ((ok as i32) + & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (2)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) + as i32)) + != 0; + ok = ((ok as i32) & (((!(move_hit.1)) && ((source.value) == (20))) as i32)) != 0; key.prefix_inc(); let mut copied: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { argument_4(&mut source) }) as *mut Item),) { - (__tmp_34,) => items.try_emplace(key, || Item::copy_from({ __tmp_34 })), + (__tmp_18,) => items.try_emplace(key, || Item::copy_from({ __tmp_18 })), }; - match ( - { - ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (3)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (1))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) - as i32) - }, - &mut (ok), - ) { - (__tmp_35, __tmp_36) => { - (*__tmp_36) = (((*__tmp_36) as i32) & (__tmp_35 as i32)) != 0; - } - }; + ok = ((ok as i32) + & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (3)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (1))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) + as i32)) + != 0; match ( { (((copied.1) && (((*copied.0.iter_deref()).1.value) == (20))) as i32) }, &mut (ok), ) { - (__tmp_37, __tmp_38) => { - (*__tmp_38) = (((*__tmp_38) as i32) & (__tmp_37 as i32)) != 0; + (__tmp_19, __tmp_20) => { + (*__tmp_20) = (((*__tmp_20) as i32) & (__tmp_19 as i32)) != 0; } }; key.prefix_inc(); let mut moved: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { argument_4(&mut source) }) as *mut Item),) { - (__tmp_39,) => items.try_emplace(key, || Item::move_from({ __tmp_39 })), + (__tmp_21,) => items.try_emplace(key, || Item::move_from({ __tmp_21 })), }; - match ( - { - ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (4)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (1))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (1))) - as i32) - }, - &mut (ok), - ) { - (__tmp_40, __tmp_41) => { - (*__tmp_41) = (((*__tmp_41) as i32) & (__tmp_40 as i32)) != 0; - } - }; + ok = ((ok as i32) + & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (4)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (1))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (1))) + as i32)) + != 0; match ( { ((((moved.1) && (((*moved.0.iter_deref()).1.value) == (20))) @@ -427,8 +360,8 @@ unsafe fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_42, __tmp_43) => { - (*__tmp_43) = (((*__tmp_43) as i32) & (__tmp_42 as i32)) != 0; + (__tmp_22, __tmp_23) => { + (*__tmp_23) = (((*__tmp_23) as i32) & (__tmp_22 as i32)) != 0; } }; let mut refs: UnsafeMap = UnsafeMap::new(); @@ -438,39 +371,25 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = 0; let mut ref_hit: (UnsafeBidirectionalIterator<(i32, RefItem)>, bool) = match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { - (__tmp_44,) => refs.try_emplace(key, || RefItem::new_2({ __tmp_44 }, { 2 })), + (__tmp_24,) => refs.try_emplace(key, || RefItem::new_2({ __tmp_24 }, { 2 })), }; - match ( - { - ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (5)) - && ((counter) == (5))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) - && (!(ref_hit.1))) as i32) - }, - &mut (ok), - ) { - (__tmp_45, __tmp_46) => { - (*__tmp_46) = (((*__tmp_46) as i32) & (__tmp_45 as i32)) != 0; - } - }; + ok = ((ok as i32) + & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (5)) + && ((counter) == (5))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (0))) + && (!(ref_hit.1))) as i32)) + != 0; key.prefix_inc(); let mut ref_new: (UnsafeBidirectionalIterator<(i32, RefItem)>, bool) = match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { - (__tmp_47,) => refs.try_emplace(key, || RefItem::new_2({ __tmp_47 }, { 2 })), + (__tmp_25,) => refs.try_emplace(key, || RefItem::new_2({ __tmp_25 }, { 2 })), }; - match ( - { - ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (6)) - && ((counter) == (7))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (1))) - && (ref_new.1)) as i32) - }, - &mut (ok), - ) { - (__tmp_48, __tmp_49) => { - (*__tmp_49) = (((*__tmp_49) as i32) & (__tmp_48 as i32)) != 0; - } - }; + ok = ((ok as i32) + & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (6)) + && ((counter) == (7))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (1))) + && (ref_new.1)) as i32)) + != 0; match ( { (((((*ref_hit.0.iter_deref()).1.value) == (5)) @@ -478,85 +397,66 @@ unsafe fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_50, __tmp_51) => { - (*__tmp_51) = (((*__tmp_51) as i32) & (__tmp_50 as i32)) != 0; + (__tmp_26, __tmp_27) => { + (*__tmp_27) = (((*__tmp_27) as i32) & (__tmp_26 as i32)) != 0; } }; key = 0; (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = match ( { - match ( - { 0 }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)), - ) { - (__tmp_54, __tmp_55) => { - (*__tmp_55) = __tmp_54; - (*__tmp_55).clone() - } + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) } }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)), ) { - (__tmp_52, __tmp_53) => { - (*__tmp_53) = __tmp_52; - (*__tmp_53).clone() + (__tmp_28, __tmp_29) => { + (*__tmp_29) = __tmp_28; + (*__tmp_29).clone() } }; let mut temporary_hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { - let mut __tmp_57: Item; + let mut __tmp_31: Item; match (({ - __tmp_57 = Item::new_1({ 30 }); - &mut __tmp_57 + __tmp_31 = Item::new_1({ 30 }); + &mut __tmp_31 } as *mut Item),) { - (__tmp_56,) => items.try_emplace(key, || Item::move_from({ __tmp_56 })), - } - }; - match ( - { - ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (1)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) - && (!(temporary_hit.1))) as i32) - }, - &mut (ok), - ) { - (__tmp_58, __tmp_59) => { - (*__tmp_59) = (((*__tmp_59) as i32) & (__tmp_58 as i32)) != 0; + (__tmp_30,) => items.try_emplace(key, || Item::move_from({ __tmp_30 })), } }; + ok = ((ok as i32) + & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (1)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) + && (!(temporary_hit.1))) as i32)) + != 0; key.prefix_inc(); key.prefix_inc(); key.prefix_inc(); let mut temporary_new: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { - let mut __tmp_61: Item; + let mut __tmp_33: Item; match (({ - __tmp_61 = Item::new_1({ 40 }); - &mut __tmp_61 + __tmp_33 = Item::new_1({ 40 }); + &mut __tmp_33 } as *mut Item),) { - (__tmp_60,) => items.try_emplace(key, || Item::move_from({ __tmp_60 })), - } - }; - match ( - { - ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (2)) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) - && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (1))) - && (temporary_new.1)) as i32) - }, - &mut (ok), - ) { - (__tmp_62, __tmp_63) => { - (*__tmp_63) = (((*__tmp_63) as i32) & (__tmp_62 as i32)) != 0; + (__tmp_32,) => items.try_emplace(key, || Item::move_from({ __tmp_32 })), } }; + ok = ((ok as i32) + & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (2)) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) == (0))) + && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (1))) + && (temporary_new.1)) as i32)) + != 0; match ( { ((((*temporary_new.0.iter_deref()).1.value) == (40)) as i32) }, &mut (ok), ) { - (__tmp_64, __tmp_65) => { - (*__tmp_65) = (((*__tmp_65) as i32) & (__tmp_64 as i32)) != 0; + (__tmp_34, __tmp_35) => { + (*__tmp_35) = (((*__tmp_35) as i32) & (__tmp_34 as i32)) != 0; } }; (unsafe { diff --git a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs index 99593155e6..1613225695 100644 --- a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs +++ b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs @@ -20,11 +20,9 @@ impl Item { } pub unsafe fn new_2(counter: *mut i32, mut amount: i32) -> Self { let mut this = Self { - value: match ({ amount }, &mut (*counter)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as i32) + (__tmp_0 as i32)) as i32; - (*__tmp_1).clone() - } + value: { + (*counter) += amount; + (*counter) }, }; (*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)).prefix_inc(); @@ -163,17 +161,17 @@ pub static mut global_temporary_14: std::cell::LazyCell<( bool, )> = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_3: Temporary; + let mut __tmp_1: Temporary; match ((&mut (*{ - __tmp_3 = (unsafe { make_temporary_5() }); - &mut __tmp_3 + __tmp_1 = (unsafe { make_temporary_5() }); + &mut __tmp_1 }) .n as *mut i32),) { - (__tmp_2,) => (*std::cell::LazyCell::force_mut(&mut *&raw mut global_values_7)) + (__tmp_0,) => (*std::cell::LazyCell::force_mut(&mut *&raw mut global_values_7)) .try_emplace( (*std::cell::LazyCell::force_mut(&mut *&raw mut global_key_8)), - || (*__tmp_2), + || (*__tmp_0), ), } } @@ -185,22 +183,22 @@ pub static mut global_conditional_15: std::cell::LazyCell<( match ( (if (*std::cell::LazyCell::force_mut(&mut *&raw mut global_choose_13)) { ({ - let __tmp_5 = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_a_11)); - (*__tmp_5).prefix_inc(); - __tmp_5 + let __tmp_3 = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_a_11)); + (*__tmp_3).prefix_inc(); + __tmp_3 } as *mut i32) } else { ({ - let __tmp_6 = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_b_12)); - (*__tmp_6).prefix_inc(); - __tmp_6 + let __tmp_4 = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_b_12)); + (*__tmp_4).prefix_inc(); + __tmp_4 } as *mut i32) } as *mut i32), ) { - (__tmp_4,) => (*std::cell::LazyCell::force_mut(&mut *&raw mut global_values_7)) + (__tmp_2,) => (*std::cell::LazyCell::force_mut(&mut *&raw mut global_values_7)) .try_emplace( (*std::cell::LazyCell::force_mut(&mut *&raw mut conditional_key_9)), - || (*__tmp_4), + || (*__tmp_2), ), } }); @@ -209,10 +207,10 @@ pub static mut global_owned_16: std::cell::LazyCell<( bool, )> = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_8: Option>; + let mut __tmp_6: Option>; match ((&mut (*(*{ - __tmp_8 = Some(Box::new(Temporary::new())); - &mut __tmp_8 + __tmp_6 = Some(Box::new(Temporary::new())); + &mut __tmp_6 }) .as_deref() .map_or(::std::ptr::null_mut(), |v| { @@ -220,10 +218,10 @@ pub static mut global_owned_16: std::cell::LazyCell<( })) .n as *mut i32),) { - (__tmp_7,) => (*std::cell::LazyCell::force_mut(&mut *&raw mut global_values_7)) + (__tmp_5,) => (*std::cell::LazyCell::force_mut(&mut *&raw mut global_values_7)) .try_emplace( (*std::cell::LazyCell::force_mut(&mut *&raw mut owned_key_10)), - || (*__tmp_7), + || (*__tmp_5), ), } } @@ -266,12 +264,12 @@ unsafe fn main_0() -> i32 { let mut hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match ( ((unsafe { receiver_2(&mut m) }) as *mut UnsafeMap), ({ - let __tmp_11 = (unsafe { place_3(&mut counter) }); - (*__tmp_11).prefix_inc(); - __tmp_11 + let __tmp_9 = (unsafe { place_3(&mut counter) }); + (*__tmp_9).prefix_inc(); + __tmp_9 } as *mut i32), ) { - (__tmp_9, __tmp_10) => (*__tmp_9).try_emplace(key, || Item::new_2({ __tmp_10 }, { 2 })), + (__tmp_7, __tmp_8) => (*__tmp_7).try_emplace(key, || Item::new_2({ __tmp_8 }, { 2 })), }; assert!( ((((counter) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) == (0))) @@ -280,12 +278,12 @@ unsafe fn main_0() -> i32 { ); key.prefix_inc(); let mut inserted: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (({ - let __tmp_13 = &mut counter; - (*__tmp_13).prefix_inc(); - __tmp_13 + let __tmp_11 = &mut counter; + (*__tmp_11).prefix_inc(); + __tmp_11 } as *mut i32),) { - (__tmp_12,) => m.try_emplace(key, || Item::new_2({ __tmp_12 }, { 2 })), + (__tmp_10,) => m.try_emplace(key, || Item::new_2({ __tmp_10 }, { 2 })), }; assert!( (((counter) == (7)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) == (1))) @@ -293,13 +291,13 @@ unsafe fn main_0() -> i32 { ); let mut assigned: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match ((match ({ 9 }, (&mut counter as *mut i32)) { - (__tmp_16, __tmp_15) => { - __tmp_15.write(__tmp_16); - __tmp_15 + (__tmp_14, __tmp_13) => { + __tmp_13.write(__tmp_14); + __tmp_13 } } as *mut i32),) { - (__tmp_14,) => m.try_emplace(key, || Item::new_2({ __tmp_14 }, { 2 })), + (__tmp_12,) => m.try_emplace(key, || Item::new_2({ __tmp_12 }, { 2 })), }; assert!( (((counter) == (9)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) == (1))) @@ -308,13 +306,13 @@ unsafe fn main_0() -> i32 { key.prefix_inc(); let mut compound: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match ((match ({ 4 }, (&mut counter as *mut i32)) { - (__tmp_19, __tmp_18) => { - __tmp_18.write((((*__tmp_18) as i32) + (__tmp_19 as i32)) as i32); - __tmp_18 + (__tmp_17, __tmp_16) => { + __tmp_16.write((((*__tmp_16) as i32) + (__tmp_17 as i32)) as i32); + __tmp_16 } } as *mut i32),) { - (__tmp_17,) => m.try_emplace(key, || Item::new_2({ __tmp_17 }, { 2 })), + (__tmp_15,) => m.try_emplace(key, || Item::new_2({ __tmp_15 }, { 2 })), }; assert!( (((counter) == (15)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) == (2))) @@ -328,12 +326,12 @@ unsafe fn main_0() -> i32 { let mut index: i32 = 0; key.prefix_inc(); match (({ - let __tmp_21 = &mut array[(index.postfix_inc()) as usize]; - (*__tmp_21).prefix_inc(); - __tmp_21 + let __tmp_19 = &mut array[(index.postfix_inc()) as usize]; + (*__tmp_19).prefix_inc(); + __tmp_19 } as *mut i32),) { - (__tmp_20,) => m.try_emplace(key, || Item::new_2({ __tmp_20 }, { 3 })), + (__tmp_18,) => m.try_emplace(key, || Item::new_2({ __tmp_18 }, { 3 })), }; assert!( (((index) == (1)) && ((array[(0) as usize]) == (4))) @@ -344,26 +342,26 @@ unsafe fn main_0() -> i32 { { 5 }, (&mut array[(index.postfix_inc()) as usize] as *mut i32), ) { - (__tmp_24, __tmp_23) => { - __tmp_23.write(__tmp_24); - __tmp_23 + (__tmp_22, __tmp_21) => { + __tmp_21.write(__tmp_22); + __tmp_21 } } as *mut i32),) { - (__tmp_22,) => m.try_emplace(key, || Item::new_2({ __tmp_22 }, { 3 })), + (__tmp_20,) => m.try_emplace(key, || Item::new_2({ __tmp_20 }, { 3 })), }; assert!( (((index) == (2)) && ((array[(1) as usize]) == (8))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) == (4)) ); match ((match ({ ((counter) + (1)) }, (&mut counter as *mut i32)) { - (__tmp_27, __tmp_26) => { - __tmp_26.write(__tmp_27); - __tmp_26 + (__tmp_25, __tmp_24) => { + __tmp_24.write(__tmp_25); + __tmp_24 } } as *mut i32),) { - (__tmp_25,) => m.try_emplace(key, || Item::new_2({ __tmp_25 }, { 3 })), + (__tmp_23,) => m.try_emplace(key, || Item::new_2({ __tmp_23 }, { 3 })), }; assert!( ((counter) == (16)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) == (4)) @@ -373,19 +371,19 @@ unsafe fn main_0() -> i32 { let mut choose: bool = false; match ((if choose { ({ - let __tmp_29 = &mut a; - (*__tmp_29).prefix_inc(); - __tmp_29 + let __tmp_27 = &mut a; + (*__tmp_27).prefix_inc(); + __tmp_27 } as *mut i32) } else { ({ - let __tmp_30 = &mut b; - (*__tmp_30).prefix_inc(); - __tmp_30 + let __tmp_28 = &mut b; + (*__tmp_28).prefix_inc(); + __tmp_28 } as *mut i32) } as *mut i32),) { - (__tmp_28,) => m.try_emplace(key, || Item::new_2({ __tmp_28 }, { 3 })), + (__tmp_26,) => m.try_emplace(key, || Item::new_2({ __tmp_26 }, { 3 })), }; assert!( (((a) == (0)) && ((b) == (1))) @@ -394,19 +392,19 @@ unsafe fn main_0() -> i32 { choose = true; match ((if choose { ({ - let __tmp_32 = &mut a; - (*__tmp_32).prefix_inc(); - __tmp_32 + let __tmp_30 = &mut a; + (*__tmp_30).prefix_inc(); + __tmp_30 } as *mut i32) } else { ({ - let __tmp_33 = &mut b; - (*__tmp_33).prefix_inc(); - __tmp_33 + let __tmp_31 = &mut b; + (*__tmp_31).prefix_inc(); + __tmp_31 } as *mut i32) } as *mut i32),) { - (__tmp_31,) => m.try_emplace(key, || Item::new_2({ __tmp_31 }, { 3 })), + (__tmp_29,) => m.try_emplace(key, || Item::new_2({ __tmp_29 }, { 3 })), }; assert!( (((a) == (1)) && ((b) == (1))) @@ -417,7 +415,7 @@ unsafe fn main_0() -> i32 { &mut counter } as *mut i32),) { - (__tmp_34,) => m.try_emplace(key, || Item::new_2({ __tmp_34 }, { 3 })), + (__tmp_32,) => m.try_emplace(key, || Item::new_2({ __tmp_32 }, { 3 })), }; assert!( ((counter) == (17)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) == (4)) @@ -426,13 +424,13 @@ unsafe fn main_0() -> i32 { let mut n: u32 = !0_u32; let mut wrapped: (UnsafeBidirectionalIterator<(i32, u32)>, bool) = match ((match ({ 1_u32 }, (&mut n as *mut u32)) { - (__tmp_37, __tmp_36) => { - __tmp_36.write((((*__tmp_36) as u32).wrapping_add((__tmp_37 as u32))) as u32); - __tmp_36 + (__tmp_35, __tmp_34) => { + __tmp_34.write((((*__tmp_34) as u32).wrapping_add((__tmp_35 as u32))) as u32); + __tmp_34 } } as *mut u32),) { - (__tmp_35,) => unsigned_map.try_emplace(key, || (*__tmp_35)), + (__tmp_33,) => unsigned_map.try_emplace(key, || (*__tmp_33)), }; assert!(((n) == (0_u32)) && (((*wrapped.0.iter_deref()).1) == (0_u32))); let mut bytes: [u8; 2] = [255_u8, 0_u8]; @@ -442,13 +440,13 @@ unsafe fn main_0() -> i32 { { 2 }, (&mut bytes[(index.postfix_inc()) as usize] as *mut u8), ) { - (__tmp_40, __tmp_39) => { - __tmp_39.write((((*__tmp_39) as i32) + (__tmp_40 as i32)) as u8); - __tmp_39 + (__tmp_38, __tmp_37) => { + __tmp_37.write((((*__tmp_37) as i32) + (__tmp_38 as i32)) as u8); + __tmp_37 } } as *mut u8),) { - (__tmp_38,) => unsigned_map.try_emplace(key, || ((*__tmp_38) as u32)), + (__tmp_36,) => unsigned_map.try_emplace(key, || ((*__tmp_36) as u32)), }; assert!( (((index) == (1)) && ((bytes[(0) as usize] as i32) == (1))) @@ -460,38 +458,38 @@ unsafe fn main_0() -> i32 { let mut erased: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ changed.erase_key(&key); { - let __tmp_42 = &mut effects; - (*__tmp_42).prefix_inc(); - __tmp_42 + let __tmp_40 = &mut effects; + (*__tmp_40).prefix_inc(); + __tmp_40 } } as *mut i32),) { - (__tmp_41,) => changed.try_emplace(key, || (*__tmp_41)), + (__tmp_39,) => changed.try_emplace(key, || (*__tmp_39)), }; assert!((((effects) == (1)) && (erased.1)) && (((*erased.0.iter_deref()).1) == (1))); let mut updated: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ (*changed.subscript(&key, || 0_i32)).prefix_inc(); { - let __tmp_44 = &mut effects; - (*__tmp_44).prefix_inc(); - __tmp_44 + let __tmp_42 = &mut effects; + (*__tmp_42).prefix_inc(); + __tmp_42 } } as *mut i32),) { - (__tmp_43,) => changed.try_emplace(key, || (*__tmp_43)), + (__tmp_41,) => changed.try_emplace(key, || (*__tmp_41)), }; assert!((((effects) == (2)) && (!(updated.1))) && (((*updated.0.iter_deref()).1) == (2))); let mut pointers: UnsafeMap = UnsafeMap::new(); let mut p: *mut i32 = array.as_mut_ptr(); let mut pointer: (UnsafeBidirectionalIterator<(i32, *mut i32)>, bool) = match ((match ({ 1 }, (&mut p as *mut *mut i32)) { - (__tmp_47, __tmp_46) => { - __tmp_46.write((*__tmp_46).offset((__tmp_47 as isize))); - __tmp_46 + (__tmp_45, __tmp_44) => { + __tmp_44.write((*__tmp_44).offset((__tmp_45 as isize))); + __tmp_44 } } as *mut *mut i32),) { - (__tmp_45,) => pointers.try_emplace(key, || (*__tmp_45)), + (__tmp_43,) => pointers.try_emplace(key, || (*__tmp_43)), }; assert!( ((p) == (array.as_mut_ptr().offset((1) as isize))) @@ -518,60 +516,60 @@ unsafe fn main_0() -> i32 { let mut assigned: i32 = 0; let mut nested: i32 = 0; let mut r0: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ - let __tmp_49 = &mut moved; - (*__tmp_49).prefix_inc(); - __tmp_49 + let __tmp_47 = &mut moved; + (*__tmp_47).prefix_inc(); + __tmp_47 } as *mut i32),) { - (__tmp_48,) => values.try_emplace(keys[(0) as usize], || (*__tmp_48)), + (__tmp_46,) => values.try_emplace(keys[(0) as usize], || (*__tmp_46)), }; let mut r1: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ - let __tmp_51 = &mut forwarded; - (*__tmp_51).prefix_inc(); - __tmp_51 + let __tmp_49 = &mut forwarded; + (*__tmp_49).prefix_inc(); + __tmp_49 } as *mut i32),) { - (__tmp_50,) => values.try_emplace(keys[(1) as usize], || (*__tmp_50)), + (__tmp_48,) => values.try_emplace(keys[(1) as usize], || (*__tmp_48)), }; let mut r2: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ - let __tmp_53 = &mut xvalue; - (*__tmp_53).prefix_inc(); - __tmp_53 + let __tmp_51 = &mut xvalue; + (*__tmp_51).prefix_inc(); + __tmp_51 } as *mut i32),) { - (__tmp_52,) => values.try_emplace(keys[(2) as usize], || (*__tmp_52)), + (__tmp_50,) => values.try_emplace(keys[(2) as usize], || (*__tmp_50)), }; let mut r3: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ - let __tmp_55 = &mut lvalue; - (*__tmp_55).prefix_inc(); - __tmp_55 + let __tmp_53 = &mut lvalue; + (*__tmp_53).prefix_inc(); + __tmp_53 } as *mut i32),) { - (__tmp_54,) => values.try_emplace(keys[(3) as usize], || (*__tmp_54)), + (__tmp_52,) => values.try_emplace(keys[(3) as usize], || (*__tmp_52)), }; let mut r4: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match ((match ({ 5 }, (&mut assigned as *mut i32)) { - (__tmp_58, __tmp_57) => { - __tmp_57.write(__tmp_58); - __tmp_57 + (__tmp_56, __tmp_55) => { + __tmp_55.write(__tmp_56); + __tmp_55 } } as *mut i32),) { - (__tmp_56,) => values.try_emplace(keys[(4) as usize], || (*__tmp_56)), + (__tmp_54,) => values.try_emplace(keys[(4) as usize], || (*__tmp_54)), }; let mut r5: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match ((match ({ 1 }, (&mut nested as *mut i32)) { - (__tmp_61, __tmp_60) => { - __tmp_60.write((((*__tmp_60) as i32) + (__tmp_61 as i32)) as i32); - __tmp_60 + (__tmp_59, __tmp_58) => { + __tmp_58.write((((*__tmp_58) as i32) + (__tmp_59 as i32)) as i32); + __tmp_58 } } as *mut i32),) { - (__tmp_59,) => values.try_emplace(keys[(5) as usize], || (*__tmp_59)), + (__tmp_57,) => values.try_emplace(keys[(5) as usize], || (*__tmp_57)), }; assert!( ((((((moved) == (1)) && ((forwarded) == (1))) && ((xvalue) == (1))) @@ -632,66 +630,66 @@ unsafe fn main_0() -> i32 { let mut prefix: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match ((if (choose != 0) { ({ - let __tmp_63 = &mut a; - (*__tmp_63).prefix_inc(); - __tmp_63 + let __tmp_61 = &mut a; + (*__tmp_61).prefix_inc(); + __tmp_61 } as *mut i32) } else { ({ - let __tmp_64 = &mut b; - (*__tmp_64).prefix_inc(); - __tmp_64 + let __tmp_62 = &mut b; + (*__tmp_62).prefix_inc(); + __tmp_62 } as *mut i32) } as *mut i32),) { - (__tmp_62,) => selected.try_emplace(keys[(0) as usize], || { - Item::new_2({ __tmp_62 }, { 2 }) + (__tmp_60,) => selected.try_emplace(keys[(0) as usize], || { + Item::new_2({ __tmp_60 }, { 2 }) }), }; let mut assignment: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match ((if (choose != 0) { ((match ({ 5 }, (&mut c as *mut i32)) { - (__tmp_67, __tmp_66) => { - __tmp_66.write(__tmp_67); - __tmp_66 + (__tmp_65, __tmp_64) => { + __tmp_64.write(__tmp_65); + __tmp_64 } }) as *mut i32) } else { ((match ({ 6 }, (&mut d as *mut i32)) { - (__tmp_69, __tmp_68) => { - __tmp_68.write(__tmp_69); - __tmp_68 + (__tmp_67, __tmp_66) => { + __tmp_66.write(__tmp_67); + __tmp_66 } }) as *mut i32) } as *mut i32),) { - (__tmp_65,) => selected.try_emplace(keys[(1) as usize], || { - Item::new_2({ __tmp_65 }, { 2 }) + (__tmp_63,) => selected.try_emplace(keys[(1) as usize], || { + Item::new_2({ __tmp_63 }, { 2 }) }), }; let mut compound: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match ((if (choose != 0) { ((match ({ 1 }, (&mut e as *mut i32)) { - (__tmp_72, __tmp_71) => { - __tmp_71.write( - (((*__tmp_71) as i32) + (__tmp_72 as i32)) as i32, + (__tmp_70, __tmp_69) => { + __tmp_69.write( + (((*__tmp_69) as i32) + (__tmp_70 as i32)) as i32, ); - __tmp_71 + __tmp_69 } }) as *mut i32) } else { ((match ({ 2 }, (&mut f as *mut i32)) { - (__tmp_74, __tmp_73) => { - __tmp_73.write( - (((*__tmp_73) as i32) + (__tmp_74 as i32)) as i32, + (__tmp_72, __tmp_71) => { + __tmp_71.write( + (((*__tmp_71) as i32) + (__tmp_72 as i32)) as i32, ); - __tmp_73 + __tmp_71 } }) as *mut i32) } as *mut i32),) { - (__tmp_70,) => selected.try_emplace(keys[(2) as usize], || { - Item::new_2({ __tmp_70 }, { 2 }) + (__tmp_68,) => selected.try_emplace(keys[(2) as usize], || { + Item::new_2({ __tmp_68 }, { 2 }) }), }; assert!( @@ -773,37 +771,37 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); let mut index: i32 = 0; let mut member: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_76: Temporary; + let mut __tmp_74: Temporary; match ((&mut (*{ - __tmp_76 = (unsafe { make_temporary_5() }); - &mut __tmp_76 + __tmp_74 = (unsafe { make_temporary_5() }); + &mut __tmp_74 }) .n as *mut i32),) { - (__tmp_75,) => values.try_emplace(keys[(0) as usize], || (*__tmp_75)), + (__tmp_73,) => values.try_emplace(keys[(0) as usize], || (*__tmp_73)), } }; let mut nested: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_78: Nested; + let mut __tmp_76: Nested; match ((&mut (*&mut (*{ - __tmp_78 = (unsafe { make_nested_6() }); - &mut __tmp_78 + __tmp_76 = (unsafe { make_nested_6() }); + &mut __tmp_76 }) .inner) .n as *mut i32),) { - (__tmp_77,) => values.try_emplace(keys[(1) as usize], || (*__tmp_77)), + (__tmp_75,) => values.try_emplace(keys[(1) as usize], || (*__tmp_75)), } }; let mut element: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_80: Temporary; + let mut __tmp_78: Temporary; match ((&mut (*{ - __tmp_80 = (unsafe { make_temporary_5() }); - &mut __tmp_80 + __tmp_78 = (unsafe { make_temporary_5() }); + &mut __tmp_78 }) .data[(index.postfix_inc()) as usize] as *mut i32),) { - (__tmp_79,) => values.try_emplace(keys[(2) as usize], || (*__tmp_79)), + (__tmp_77,) => values.try_emplace(keys[(2) as usize], || (*__tmp_77)), } }; assert!( @@ -835,28 +833,28 @@ unsafe fn main_0() -> i32 { index = 0; let mut value: i32 = 0; { - let mut __tmp_82: Nested; - let mut __tmp_83: Temporary; + let mut __tmp_80: Nested; + let mut __tmp_81: Temporary; { match ((if (choose != 0) { (&mut (*&mut (*{ - __tmp_82 = (unsafe { make_nested_6() }); - &mut __tmp_82 + __tmp_80 = (unsafe { make_nested_6() }); + &mut __tmp_80 }) .inner) .n as *mut i32) } else { (&mut (*{ - __tmp_83 = (unsafe { make_temporary_5() }); - &mut __tmp_83 + __tmp_81 = (unsafe { make_temporary_5() }); + &mut __tmp_81 }) .data [(index.postfix_inc()) as usize] as *mut i32) } as *mut i32),) { - (__tmp_81,) => references - .try_emplace(key, || Held::new_1({ __tmp_81 })), + (__tmp_79,) => references + .try_emplace(key, || Held::new_1({ __tmp_79 })), }; value = (*(*references.subscript(&key, || ::default())).ptr) @@ -884,28 +882,28 @@ unsafe fn main_0() -> i32 { before = (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); { - let mut __tmp_85: Nested; - let mut __tmp_86: Temporary; + let mut __tmp_83: Nested; + let mut __tmp_84: Temporary; { match ((if (choose != 0) { (&mut (*&mut (*{ - __tmp_85 = (unsafe { make_nested_6() }); - &mut __tmp_85 + __tmp_83 = (unsafe { make_nested_6() }); + &mut __tmp_83 }) .inner) .data as *mut [i32; 2]) } else { (&mut (*{ - __tmp_86 = (unsafe { make_temporary_5() }); - &mut __tmp_86 + __tmp_84 = (unsafe { make_temporary_5() }); + &mut __tmp_84 }) .data as *mut [i32; 2]) } as *mut [i32; 2]),) { - (__tmp_84,) => arrays - .try_emplace(key, || Held::new_3({ __tmp_84 }, { 0 })), + (__tmp_82,) => arrays + .try_emplace(key, || Held::new_3({ __tmp_82 }, { 0 })), }; value = (*(*arrays.subscript(&key, || ::default())) .ptr @@ -944,10 +942,10 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); let mut index: i32 = 0; let mut arrow: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_88: Option>; + let mut __tmp_86: Option>; match ((&mut (*(*{ - __tmp_88 = Some(Box::new(Temporary::new())); - &mut __tmp_88 + __tmp_86 = Some(Box::new(Temporary::new())); + &mut __tmp_86 }) .as_deref() .map_or(::std::ptr::null_mut(), |v| { @@ -955,14 +953,14 @@ unsafe fn main_0() -> i32 { })) .n as *mut i32),) { - (__tmp_87,) => values.try_emplace(keys[(0) as usize], || (*__tmp_87)), + (__tmp_85,) => values.try_emplace(keys[(0) as usize], || (*__tmp_85)), } }; let mut nested: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_90: Option>; + let mut __tmp_88: Option>; match ((&mut (*&mut (*(*{ - __tmp_90 = Some(Box::new(::default())); - &mut __tmp_90 + __tmp_88 = Some(Box::new(::default())); + &mut __tmp_88 }) .as_deref() .map_or(::std::ptr::null_mut(), |v| { @@ -971,14 +969,14 @@ unsafe fn main_0() -> i32 { .inner) .n as *mut i32),) { - (__tmp_89,) => values.try_emplace(keys[(1) as usize], || (*__tmp_89)), + (__tmp_87,) => values.try_emplace(keys[(1) as usize], || (*__tmp_87)), } }; let mut element: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_92: Option>; + let mut __tmp_90: Option>; match ((&mut (*(*{ - __tmp_92 = Some(Box::new(Temporary::new())); - &mut __tmp_92 + __tmp_90 = Some(Box::new(Temporary::new())); + &mut __tmp_90 }) .as_deref() .map_or(::std::ptr::null_mut(), |v| { @@ -986,27 +984,27 @@ unsafe fn main_0() -> i32 { })) .data[(index.postfix_inc()) as usize] as *mut i32),) { - (__tmp_91,) => values.try_emplace(keys[(2) as usize], || (*__tmp_91)), + (__tmp_89,) => values.try_emplace(keys[(2) as usize], || (*__tmp_89)), } }; let mut get: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_94: Option>; + let mut __tmp_92: Option>; match ((&mut (*(*{ - __tmp_94 = Some(Box::new(Temporary::new())); - &mut __tmp_94 + __tmp_92 = Some(Box::new(Temporary::new())); + &mut __tmp_92 }) .as_deref_mut() .map_or(::std::ptr::null_mut(), |v| v as *mut Temporary)) .n as *mut i32),) { - (__tmp_93,) => values.try_emplace(keys[(3) as usize], || (*__tmp_93)), + (__tmp_91,) => values.try_emplace(keys[(3) as usize], || (*__tmp_91)), } }; let mut deref: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_96: Option>; + let mut __tmp_94: Option>; match ((&mut (*((*{ - __tmp_96 = Some(Box::new(Temporary::new())); - &mut __tmp_96 + __tmp_94 = Some(Box::new(Temporary::new())); + &mut __tmp_94 }) .as_deref() .map_or(::std::ptr::null_mut(), |v| { @@ -1014,14 +1012,14 @@ unsafe fn main_0() -> i32 { }))) .n as *mut i32),) { - (__tmp_95,) => values.try_emplace(keys[(4) as usize], || (*__tmp_95)), + (__tmp_93,) => values.try_emplace(keys[(4) as usize], || (*__tmp_93)), } }; let mut indirect: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_98: Option>>>; + let mut __tmp_96: Option>>>; match ((&mut (*((*(*{ - __tmp_98 = Some(Box::new(Some(Box::new(Temporary::new())))); - &mut __tmp_98 + __tmp_96 = Some(Box::new(Some(Box::new(Temporary::new())))); + &mut __tmp_96 }) .as_deref() .map_or(::std::ptr::null_mut(), |v| { @@ -1033,7 +1031,7 @@ unsafe fn main_0() -> i32 { }))) .n as *mut i32),) { - (__tmp_97,) => values.try_emplace(keys[(5) as usize], || (*__tmp_97)), + (__tmp_95,) => values.try_emplace(keys[(5) as usize], || (*__tmp_95)), } }; assert!( @@ -1076,13 +1074,13 @@ unsafe fn main_0() -> i32 { index = 0; let mut value: i32 = 0; { - let mut __tmp_100: Option>; - let mut __tmp_101: Option>; + let mut __tmp_98: Option>; + let mut __tmp_99: Option>; { match ((if (choose != 0) { (&mut (*(*{ - __tmp_100 = Some(Box::new(Temporary::new())); - &mut __tmp_100 + __tmp_98 = Some(Box::new(Temporary::new())); + &mut __tmp_98 }) .as_deref() .map_or(::std::ptr::null_mut(), |v| { @@ -1091,8 +1089,8 @@ unsafe fn main_0() -> i32 { .n as *mut i32) } else { (&mut (*(*{ - __tmp_101 = Some(Box::new(Temporary::new())); - &mut __tmp_101 + __tmp_99 = Some(Box::new(Temporary::new())); + &mut __tmp_99 }) .as_deref() .map_or(::std::ptr::null_mut(), |v| { @@ -1103,8 +1101,8 @@ unsafe fn main_0() -> i32 { as *mut i32) } as *mut i32),) { - (__tmp_99,) => references - .try_emplace(key, || Held::new_1({ __tmp_99 })), + (__tmp_97,) => references + .try_emplace(key, || Held::new_1({ __tmp_97 })), }; value = (*(*references.subscript(&key, || ::default())).ptr) @@ -1126,19 +1124,19 @@ unsafe fn main_0() -> i32 { ); let mut owners: UnsafeMap = UnsafeMap::new(); { - let mut __tmp_103: Owner; + let mut __tmp_101: Owner; { match (((unsafe { Owner::value( &mut (*{ - __tmp_103 = Owner::new(); - &mut __tmp_103 + __tmp_101 = Owner::new(); + &mut __tmp_101 }), ) }) as *const i32),) { - (__tmp_102,) => { - owners.try_emplace(key, || Held::new_1({ __tmp_102 })) + (__tmp_100,) => { + owners.try_emplace(key, || Held::new_1({ __tmp_100 })) } }; value = (*(*owners.subscript(&key, || ::default())).ptr) @@ -1158,26 +1156,26 @@ unsafe fn main_0() -> i32 { UnsafeBidirectionalIterator<(i32, (Option>, i32))>, bool, ) = { - let mut __tmp_105: Option>; + let mut __tmp_103: Option>; match (({ - __tmp_105 = Some(Box::new(::default())); - &mut __tmp_105 + __tmp_103 = Some(Box::new(::default())); + &mut __tmp_103 } as *mut Option>),) { - (__tmp_104,) => move_only.try_emplace(key, || ((*__tmp_104).take(), 7)), + (__tmp_102,) => move_only.try_emplace(key, || ((*__tmp_102).take(), 7)), } }; let mut move_hit: ( UnsafeBidirectionalIterator<(i32, (Option>, i32))>, bool, ) = { - let mut __tmp_107: Option>; + let mut __tmp_105: Option>; match (({ - __tmp_107 = Some(Box::new(::default())); - &mut __tmp_107 + __tmp_105 = Some(Box::new(::default())); + &mut __tmp_105 } as *mut Option>),) { - (__tmp_106,) => move_only.try_emplace(key, || ((*__tmp_106).take(), 9)), + (__tmp_104,) => move_only.try_emplace(key, || ((*__tmp_104).take(), 9)), } }; assert!((move_new.1) && (!(move_hit.1))); @@ -1216,7 +1214,7 @@ unsafe fn main_0() -> i32 { } as *mut Vec),) { - (__tmp_108,) => strings.try_emplace(key, || std::mem::replace(&mut (*__tmp_108), vec![0])), + (__tmp_106,) => strings.try_emplace(key, || std::mem::replace(&mut (*__tmp_106), vec![0])), }; assert!( (((*std::cell::LazyCell::force_mut(&mut *&raw mut visits_1)) == (3)) && (!(string_hit.1))) @@ -1238,7 +1236,7 @@ unsafe fn main_0() -> i32 { } as *mut Vec),) { - (__tmp_109,) => strings.try_emplace(key, || std::mem::replace(&mut (*__tmp_109), vec![0])), + (__tmp_107,) => strings.try_emplace(key, || std::mem::replace(&mut (*__tmp_107), vec![0])), }; assert!( (((*std::cell::LazyCell::force_mut(&mut *&raw mut visits_1)) == (4)) && (string_new.1)) diff --git a/tests/unit/out/unsafe/operator_compound_assignment_free.rs b/tests/unit/out/unsafe/operator_compound_assignment_free.rs index 3a72b07ec5..ca88305817 100644 --- a/tests/unit/out/unsafe/operator_compound_assignment_free.rs +++ b/tests/unit/out/unsafe/operator_compound_assignment_free.rs @@ -12,43 +12,23 @@ pub struct S { pub v: u32, } pub unsafe fn operator_add_assign_0(a: *mut S, b: *const S) -> *mut S { - match ({ (*b).v }, &mut ((*a).v)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; - } - }; + (*a).v = ((*a).v).wrapping_add((*b).v); return a; } pub unsafe fn operator_sub_assign_1(a: *mut S, b: *const S) -> *mut S { - match ({ (*b).v }, &mut ((*a).v)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = (((*__tmp_3) as u32).wrapping_sub((__tmp_2 as u32))) as u32; - } - }; + (*a).v = ((*a).v).wrapping_sub((*b).v); return a; } pub unsafe fn operator_mul_assign_2(a: *mut S, b: *const S) -> *mut S { - match ({ (*b).v }, &mut ((*a).v)) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = (((*__tmp_5) as u32).wrapping_mul((__tmp_4 as u32))) as u32; - } - }; + (*a).v = ((*a).v).wrapping_mul((*b).v); return a; } pub unsafe fn operator_div_assign_3(a: *mut S, b: *const S) -> *mut S { - match ({ (*b).v }, &mut ((*a).v)) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as u32).wrapping_div((__tmp_6 as u32))) as u32; - } - }; + (*a).v = ((*a).v).wrapping_div((*b).v); return a; } pub unsafe fn operator_rem_assign_4(a: *mut S, b: *const S) -> *mut S { - match ({ (*b).v }, &mut ((*a).v)) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as u32).wrapping_rem((__tmp_8 as u32))) as u32; - } - }; + (*a).v = ((*a).v).wrapping_rem((*b).v); return a; } pub unsafe fn operator_bitand_assign_5(a: *mut S, b: *const S) -> *mut S { diff --git a/tests/unit/out/unsafe/operator_compound_assignment_member.rs b/tests/unit/out/unsafe/operator_compound_assignment_member.rs index 4d313eff40..d619d005f4 100644 --- a/tests/unit/out/unsafe/operator_compound_assignment_member.rs +++ b/tests/unit/out/unsafe/operator_compound_assignment_member.rs @@ -17,43 +17,23 @@ impl S { return &mut (*(self as *mut S)); } pub unsafe fn operator_add_assign(&mut self, o: *const S) -> *mut S { - match ({ (*o).v }, &mut (self.v)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; - } - }; + self.v = (self.v).wrapping_add((*o).v); return &mut (*(self as *mut S)); } pub unsafe fn operator_sub_assign(&mut self, o: *const S) -> *mut S { - match ({ (*o).v }, &mut (self.v)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = (((*__tmp_3) as u32).wrapping_sub((__tmp_2 as u32))) as u32; - } - }; + self.v = (self.v).wrapping_sub((*o).v); return &mut (*(self as *mut S)); } pub unsafe fn operator_mul_assign(&mut self, o: *const S) -> *mut S { - match ({ (*o).v }, &mut (self.v)) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = (((*__tmp_5) as u32).wrapping_mul((__tmp_4 as u32))) as u32; - } - }; + self.v = (self.v).wrapping_mul((*o).v); return &mut (*(self as *mut S)); } pub unsafe fn operator_div_assign(&mut self, o: *const S) -> *mut S { - match ({ (*o).v }, &mut (self.v)) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as u32).wrapping_div((__tmp_6 as u32))) as u32; - } - }; + self.v = (self.v).wrapping_div((*o).v); return &mut (*(self as *mut S)); } pub unsafe fn operator_rem_assign(&mut self, o: *const S) -> *mut S { - match ({ (*o).v }, &mut (self.v)) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as u32).wrapping_rem((__tmp_8 as u32))) as u32; - } - }; + self.v = (self.v).wrapping_rem((*o).v); return &mut (*(self as *mut S)); } pub unsafe fn operator_bitand_assign(&mut self, o: *const S) -> *mut S { diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index 7b8ce83d52..957fb85233 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -39,21 +39,9 @@ unsafe fn main_0() -> i32 { .wrapping_add((::std::mem::size_of::() as usize)))) ); let mut acc: usize = 100_usize; - match ({ ::std::mem::size_of::() }, &mut (acc)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as u64).wrapping_add((__tmp_0 as u64))) as usize; - } - }; - match ({ 2_usize }, &mut (acc)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = (((*__tmp_3) as usize).wrapping_mul((__tmp_2 as usize))) as usize; - } - }; - match ({ ul }, &mut (acc)) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = (((*__tmp_5) as u64).wrapping_sub((__tmp_4 as u64))) as usize; - } - }; + acc = ((acc as u64).wrapping_add((::std::mem::size_of::() as u64))) as usize; + acc = (acc).wrapping_mul(2_usize); + acc = ((acc as u64).wrapping_sub(ul)) as usize; assert!( ((acc) == (((((100_usize).wrapping_add((::std::mem::size_of::() as usize))) as usize) @@ -76,18 +64,18 @@ unsafe fn main_0() -> i32 { let mut fr2: u64 = (unsafe { take_ulong_1((sz as u64)) }); assert!(((fr2) == (21_u64))); let mut lo: usize = (({ - let mut __tmp_6: u64 = (sz as u64); - let mut __tmp_7: u64 = (::std::mem::size_of::() as u64).wrapping_add(ul); + let mut __tmp_0: u64 = (sz as u64); + let mut __tmp_1: u64 = (::std::mem::size_of::() as u64).wrapping_add(ul); (*{ - let __a: *const _ = &mut __tmp_6; - let __b: *const _ = &mut __tmp_7; + let __a: *const _ = &mut __tmp_0; + let __b: *const _ = &mut __tmp_1; if *__b < *__a { __b } else { __a } }) }) as usize); let mut hi: usize = (({ - let mut __tmp_8: u64 = (::std::mem::size_of::() as u64).wrapping_add((sz as u64)); + let mut __tmp_2: u64 = (::std::mem::size_of::() as u64).wrapping_add((sz as u64)); (*{ - let __a: *const _ = &mut __tmp_8; + let __a: *const _ = &mut __tmp_2; let __b: *const _ = &mut ul; if *__a < *__b { __b } else { __a } }) @@ -95,11 +83,11 @@ unsafe fn main_0() -> i32 { assert!(((lo) == ((::std::mem::size_of::() as usize).wrapping_add(10_usize)))); assert!(((hi) == ((::std::mem::size_of::() as usize).wrapping_add(21_usize)))); let mut bound: usize = (({ - let mut __tmp_9: u64 = (sz as u64); - let mut __tmp_10: u64 = (4_usize as u64); + let mut __tmp_3: u64 = (sz as u64); + let mut __tmp_4: u64 = (4_usize as u64); (*{ - let __a: *const _ = &mut __tmp_9; - let __b: *const _ = &mut __tmp_10; + let __a: *const _ = &mut __tmp_3; + let __b: *const _ = &mut __tmp_4; if *__b < *__a { __b } else { __a } }) }) as usize); @@ -121,12 +109,7 @@ unsafe fn main_0() -> i32 { let mut i: usize = 0_usize; 'loop_: while ((i) < (count)) { 'for_body: { - match ({ (data[(i)] as usize) }, &mut (total)) { - (__tmp_11, __tmp_12) => { - (*__tmp_12) = - (((*__tmp_12) as usize).wrapping_add((__tmp_11 as usize))) as usize; - } - }; + total = (total).wrapping_add((data[(i)] as usize)); } i.postfix_inc(); } @@ -155,20 +138,20 @@ unsafe fn main_0() -> i32 { assert!(((sm) == (15_isize))); assert!(((sm) > (l as isize))); let mut smin: isize = (({ - let mut __tmp_13: i64 = (sd as i64); - let mut __tmp_14: i64 = (sm as i64); + let mut __tmp_5: i64 = (sd as i64); + let mut __tmp_6: i64 = (sm as i64); (*{ - let __a: *const _ = &mut __tmp_13; - let __b: *const _ = &mut __tmp_14; + let __a: *const _ = &mut __tmp_5; + let __b: *const _ = &mut __tmp_6; if *__b < *__a { __b } else { __a } }) }) as isize); let mut smax: isize = (({ - let mut __tmp_15: i64 = (sd as i64); - let mut __tmp_16: i64 = (sm as i64); + let mut __tmp_7: i64 = (sd as i64); + let mut __tmp_8: i64 = (sm as i64); (*{ - let __a: *const _ = &mut __tmp_15; - let __b: *const _ = &mut __tmp_16; + let __a: *const _ = &mut __tmp_7; + let __b: *const _ = &mut __tmp_8; if *__a < *__b { __b } else { __a } }) }) as isize); @@ -190,20 +173,20 @@ unsafe fn main_0() -> i32 { let mut mins: [usize; 4] = [ 0_usize, (({ - let mut __tmp_17: u64 = 1_u64; - let mut __tmp_18: u64 = (mx as u64); + let mut __tmp_9: u64 = 1_u64; + let mut __tmp_10: u64 = (mx as u64); (*{ - let __a: *const _ = &mut __tmp_17; - let __b: *const _ = &mut __tmp_18; + let __a: *const _ = &mut __tmp_9; + let __b: *const _ = &mut __tmp_10; if *__b < *__a { __b } else { __a } }) }) as usize), (({ - let mut __tmp_19: u64 = (mx as u64); - let mut __tmp_20: u64 = ((mx).wrapping_sub(3_usize) as u64); + let mut __tmp_11: u64 = (mx as u64); + let mut __tmp_12: u64 = ((mx).wrapping_sub(3_usize) as u64); (*{ - let __a: *const _ = &mut __tmp_19; - let __b: *const _ = &mut __tmp_20; + let __a: *const _ = &mut __tmp_11; + let __b: *const _ = &mut __tmp_12; if *__b < *__a { __b } else { __a } }) }) as usize), diff --git a/tests/unit/out/unsafe/size_t_template_param.rs b/tests/unit/out/unsafe/size_t_template_param.rs index 4d71c23736..f23e80672e 100644 --- a/tests/unit/out/unsafe/size_t_template_param.rs +++ b/tests/unit/out/unsafe/size_t_template_param.rs @@ -7,11 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn array_ref_0(a: *mut [u64; 3]) -> u64 { - match ({ 1_u64 }, &mut ((*a)[(0) as usize])) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as u64).wrapping_add((__tmp_0 as u64))) as u64; - } - }; + (*a)[(0) as usize] = ((*a)[(0) as usize]).wrapping_add(1_u64); return (*a)[((3_u64 as u64).wrapping_sub(1_u64)) as usize]; } #[repr(C)] diff --git a/tests/unit/out/unsafe/swap_map_no_copy.rs b/tests/unit/out/unsafe/swap_map_no_copy.rs index 4460eb7873..5688320e22 100644 --- a/tests/unit/out/unsafe/swap_map_no_copy.rs +++ b/tests/unit/out/unsafe/swap_map_no_copy.rs @@ -332,14 +332,9 @@ pub unsafe fn swapped_once_6() -> bool { && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moved_dtors_5)) == (1)); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) = match ( { - match ( - { 0 }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut moved_dtors_5)), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut moved_dtors_5)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut moved_dtors_5)) } }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_4)), diff --git a/tests/unit/out/unsafe/switch_on_assignment.rs b/tests/unit/out/unsafe/switch_on_assignment.rs index 8f5d59b888..9aaca88206 100644 --- a/tests/unit/out/unsafe/switch_on_assignment.rs +++ b/tests/unit/out/unsafe/switch_on_assignment.rs @@ -11,11 +11,9 @@ pub unsafe fn switch_on_assignment_0(mut x: i32) -> i32 { let mut r: i32 = 0; 'switch: { match { - match ({ ((x) + (1)) }, &mut (y)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + { + y = ((x) + (1)); + y } } { __v if __v == 1 => { From 7a6f9159102319f77dbded5f77ec56b15f8097bb Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Wed, 25 Nov 2026 21:21:09 +0000 Subject: [PATCH 03/25] Keep global assignment borrow lifetime covered Signed-off-by: Perfloop Agent --- tests/unit/assignment_single_eval.cpp | 1 + .../out/refcount/assignment_single_eval.rs | 52 +++++++++------ .../unit/out/unsafe/assignment_single_eval.rs | 64 +++++++++++++------ 3 files changed, 81 insertions(+), 36 deletions(-) diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index c8925da7f1..ff6510bf26 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -60,6 +60,7 @@ int observe(int assigned, const int *stored) { return assigned + *stored; } void test_borrows() { std::printf("%d\n", observe_global(global = 99)); std::printf("%d\n", observe_global(global += 5)); + std::printf("%d\n", observe_global(global = observe(0, &global))); int local = 10; std::printf("%d\n", observe(local = 99, &local)); diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 9e7a69cfde..8ec5168f11 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -567,6 +567,22 @@ pub fn test_borrows_8() { }) }) ); + printf!( + b"%d\n", + ({ + observe_global_6({ + match ( + { ({ observe_7(0, (global_5.with(|v| v.as_pointer()))) }) }, + &mut (*global_5.with(Value::clone).borrow_mut()), + ) { + (__tmp_56, __tmp_57) => { + (*__tmp_57) = __tmp_56; + (*__tmp_57).clone() + } + } + }) + }) + ); let local: Value = Rc::new(RefCell::new(10)); printf!( b"%d\n", @@ -596,9 +612,9 @@ pub fn test_borrows_8() { ({ let _assigned: i32 = { match ({ 99 }, &mut ((*record.borrow_mut()).value)) { - (__tmp_56, __tmp_57) => { - (*__tmp_57) = __tmp_56; - (*__tmp_57).clone() + (__tmp_58, __tmp_59) => { + (*__tmp_59) = __tmp_58; + (*__tmp_59).clone() } } }; @@ -611,9 +627,9 @@ pub fn test_borrows_8() { ({ let _assigned: i32 = { match ({ 5 }, &mut ((*record.borrow_mut()).value)) { - (__tmp_58, __tmp_59) => { - (*__tmp_59) = (((*__tmp_59) as i32) + (__tmp_58 as i32)) as i32; - (*__tmp_59).clone() + (__tmp_60, __tmp_61) => { + (*__tmp_61) = (((*__tmp_61) as i32) + (__tmp_60 as i32)) as i32; + (*__tmp_61).clone() } } }; @@ -627,9 +643,9 @@ pub fn test_borrows_8() { ({ let _assigned: i32 = { match ({ 99 }, &mut ((*values.borrow_mut())[0_usize])) { - (__tmp_60, __tmp_61) => { - (*__tmp_61) = __tmp_60; - (*__tmp_61).clone() + (__tmp_62, __tmp_63) => { + (*__tmp_63) = __tmp_62; + (*__tmp_63).clone() } } }; @@ -642,9 +658,9 @@ pub fn test_borrows_8() { ({ let _assigned: i32 = { match ({ 5 }, &mut ((*values.borrow_mut())[0_usize])) { - (__tmp_62, __tmp_63) => { - (*__tmp_63) = (((*__tmp_63) as i32) + (__tmp_62 as i32)) as i32; - (*__tmp_63).clone() + (__tmp_64, __tmp_65) => { + (*__tmp_65) = (((*__tmp_65) as i32) + (__tmp_64 as i32)) as i32; + (*__tmp_65).clone() } } }; @@ -672,9 +688,9 @@ pub fn test_binding_11() { let value: Ptr = ({ IndexedBindingImpl::get_1_0(&__decomp_12) }); let mut result: u32 = ({ match ({ 1_u32 }, &({ IndexedBindingImpl::get_1_0(&__decomp_12) })) { - (__tmp_64, __tmp_65) => __tmp_65.with_mut(|__tmp_65| { - (*__tmp_65) = (((*__tmp_65) as u32).wrapping_add((__tmp_64 as u32))) as u32; - (*__tmp_65).clone() + (__tmp_66, __tmp_67) => __tmp_67.with_mut(|__tmp_67| { + (*__tmp_67) = (((*__tmp_67) as u32).wrapping_add((__tmp_66 as u32))) as u32; + (*__tmp_67).clone() }), } }); @@ -711,9 +727,9 @@ fn main_0() -> i32 { 0 )), ) { - (__tmp_66, __tmp_67) => __tmp_67.with_mut(|__tmp_67| { - (*__tmp_67) = (((*__tmp_67) as u32).wrapping_add((__tmp_66 as u32))) as u32; - (*__tmp_67).clone() + (__tmp_68, __tmp_69) => __tmp_69.with_mut(|__tmp_69| { + (*__tmp_69) = (((*__tmp_69) as u32).wrapping_add((__tmp_68 as u32))) as u32; + (*__tmp_69).clone() }), } }); diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index bef0b990dc..3e85b5529c 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -607,6 +607,34 @@ pub unsafe fn test_borrows_8() { }), ) }); + (unsafe { + libc::printf( + c"%d\n".as_ptr() as *const libc::c_char, + (unsafe { + observe_global_6( + match ( + { + (unsafe { + observe_7( + 0, + (&raw mut (*std::cell::LazyCell::force_mut( + &mut *&raw mut global_5, + )) as *mut i32) + .cast_const(), + ) + }) + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)), + ) { + (__tmp_56, __tmp_57) => { + (*__tmp_57) = __tmp_56; + (*__tmp_57).clone() + } + }, + ) + }), + ) + }); let mut local: i32 = 10; (unsafe { libc::printf( @@ -640,9 +668,9 @@ pub unsafe fn test_borrows_8() { c"%d\n".as_ptr() as *const libc::c_char, (unsafe { let _assigned: i32 = match ({ 99 }, &mut (record.value)) { - (__tmp_56, __tmp_57) => { - (*__tmp_57) = __tmp_56; - (*__tmp_57).clone() + (__tmp_58, __tmp_59) => { + (*__tmp_59) = __tmp_58; + (*__tmp_59).clone() } }; let _stored: *const i32 = (&mut record.value as *mut i32).cast_const(); @@ -655,9 +683,9 @@ pub unsafe fn test_borrows_8() { c"%d\n".as_ptr() as *const libc::c_char, (unsafe { let _assigned: i32 = match ({ 5 }, &mut (record.value)) { - (__tmp_58, __tmp_59) => { - (*__tmp_59) = (((*__tmp_59) as i32) + (__tmp_58 as i32)) as i32; - (*__tmp_59).clone() + (__tmp_60, __tmp_61) => { + (*__tmp_61) = (((*__tmp_61) as i32) + (__tmp_60 as i32)) as i32; + (*__tmp_61).clone() } }; let _stored: *const i32 = (&mut record.value as *mut i32).cast_const(); @@ -671,9 +699,9 @@ pub unsafe fn test_borrows_8() { c"%d\n".as_ptr() as *const libc::c_char, (unsafe { let _assigned: i32 = match ({ 99 }, &mut (values[(0_usize)])) { - (__tmp_60, __tmp_61) => { - (*__tmp_61) = __tmp_60; - (*__tmp_61).clone() + (__tmp_62, __tmp_63) => { + (*__tmp_63) = __tmp_62; + (*__tmp_63).clone() } }; let _stored: *const i32 = (&mut values[(0_usize)] as *mut i32).cast_const(); @@ -686,9 +714,9 @@ pub unsafe fn test_borrows_8() { c"%d\n".as_ptr() as *const libc::c_char, (unsafe { let _assigned: i32 = match ({ 5 }, &mut (values[(0_usize)])) { - (__tmp_62, __tmp_63) => { - (*__tmp_63) = (((*__tmp_63) as i32) + (__tmp_62 as i32)) as i32; - (*__tmp_63).clone() + (__tmp_64, __tmp_65) => { + (*__tmp_65) = (((*__tmp_65) as i32) + (__tmp_64 as i32)) as i32; + (*__tmp_65).clone() } }; let _stored: *const i32 = (&mut values[(0_usize)] as *mut i32).cast_const(); @@ -722,9 +750,9 @@ pub unsafe fn test_binding_11() { { 1_u32 }, &mut (*(unsafe { IndexedBinding::get_1_0(&mut (*__decomp_12)) })), ) { - (__tmp_64, __tmp_65) => { - (*__tmp_65) = (((*__tmp_65) as u32).wrapping_add((__tmp_64 as u32))) as u32; - (*__tmp_65).clone() + (__tmp_66, __tmp_67) => { + (*__tmp_67) = (((*__tmp_67) as u32).wrapping_add((__tmp_66 as u32))) as u32; + (*__tmp_67).clone() } }); (unsafe { @@ -757,9 +785,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_66, __tmp_67) => { - (*__tmp_67) = (((*__tmp_67) as u32).wrapping_add((__tmp_66 as u32))) as u32; - (*__tmp_67).clone() + (__tmp_68, __tmp_69) => { + (*__tmp_69) = (((*__tmp_69) as u32).wrapping_add((__tmp_68 as u32))) as u32; + (*__tmp_69).clone() } }); (unsafe { From 8481360e6f89c341e239baaeb4ed3af83bc21a0d Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Wed, 25 Nov 2026 23:00:20 +0000 Subject: [PATCH 04/25] Avoid target ownership for fixed global assignments Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 7 +- .../converter/models/converter_refcount.cpp | 42 +++- .../out/refcount/p14-class-in-two-files.rs | 34 +--- .../p15-class-template-static-member.rs | 34 +--- .../out/refcount/p15-function-template.rs | 34 +--- .../out/refcount/p15-inline-function.rs | 34 +--- .../out/refcount/p15-inline-variable.rs | 34 +--- .../p16-default-argument-lambda-in-class.rs | 34 +--- .../refcount/p16-lambda-in-inline-function.rs | 34 +--- .../out/refcount/basic.scope.block.rs | 34 +--- tests/std/basic/out/refcount/basic.def.odr.rs | 34 +--- .../stmt.select/out/refcount/stmt.if.rs | 34 +--- .../stmt.select/out/refcount/stmt.switch.rs | 34 +--- tests/unit/assignment_single_eval.cpp | 15 ++ .../out/refcount/assignment_single_eval.rs | 164 +++++++++++---- .../out/refcount/global_call_temporaries.rs | 192 ++++++++---------- tests/unit/out/refcount/map_try_emplace.rs | 102 ++++------ tests/unit/out/refcount/swap_map_no_copy.rs | 95 ++++----- .../unit/out/unsafe/assignment_single_eval.rs | 179 +++++++++++++--- 19 files changed, 615 insertions(+), 555 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 48a3938909..fa7f31646b 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -3206,6 +3206,10 @@ Converter::ConvertCompoundAssignValue(clang::CompoundAssignOperator *expr, { PushParen inner(*this); StrCat(lhs_value.empty() ? ConvertRValue(lhs) : lhs_value); + if (lhs->getType()->isBooleanType() && + computation_result_type->isFloatingType()) { + StrCat(keyword::kAs, "u8"); + } ConvertCast(computation_result_type); } if (IsUnsignedArithOp(expr)) { @@ -3223,7 +3227,8 @@ Converter::ConvertCompoundAssignValue(clang::CompoundAssignOperator *expr, } } if (lhs->getType()->isBooleanType()) { - StrCat(token::kDiff, token::kZero); + StrCat(token::kDiff, + computation_result_type->isFloatingType() ? "0.0" : "0"); } else { ConvertCast(lhs->getType()); } diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 54f3fd0d17..55df746737 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -2398,15 +2398,19 @@ void ConverterRefCount::ConvertVarInit(clang::QualType qual_type, StrCat(BoxValue(ConvertVarInitValue(qual_type, expr))); } +static const clang::VarDecl *GetGlobalValueDecl(const clang::Expr *expr) { + auto *ref = clang::dyn_cast(expr->IgnoreImplicit()); + auto *var = ref ? clang::dyn_cast(ref->getDecl()) : nullptr; + return var && IsGlobalVar(var) && !var->getType()->isReferenceType() + ? var + : nullptr; +} + bool ConverterRefCount::EmitGlobalValueAssign(clang::Expr *lhs, std::string_view assign_operator, std::string_view rhs) { - auto *decl_ref = clang::dyn_cast(lhs->IgnoreImplicit()); - if (!decl_ref) { - return false; - } - auto *var = clang::dyn_cast(decl_ref->getDecl()); - if (!var || !IsGlobalVar(var) || var->getType()->isReferenceType()) { + auto *var = GetGlobalValueDecl(lhs); + if (!var) { return false; } PushBrace brace(*this, in_const_initializer_); @@ -2454,7 +2458,31 @@ void ConverterRefCount::EmitCompoundSetOrAssign(clang::Expr *lhs, void ConverterRefCount::ConvertAssignment( clang::Expr *lhs, clang::Expr *rhs, std::string_view assign_operator, clang::CompoundAssignOperator *compound) { - if (compound || (isRValue() && NeedsAssignmentBinding(lhs, rhs))) { + auto *global = GetGlobalValueDecl(lhs); + if (global && compound && + (lhs->getType()->isPointerType() || IsUnsignedArithOp(compound) || + GetSafeTypeAsString(lhs->getType()) != + GetSafeTypeAsString(compound->getComputationResultType()))) { + // The target is fixed, but the right operand can change its value. + PushBrace brace(*this); + auto right = NewTempName(); + StrCat(keyword::kLet, right, token::kAssign, ConvertFreshRValue(rhs), + token::kSemiColon); + if (lhs->getType()->isPointerType()) { + EmitGlobalValueAssign(lhs, assign_operator, + std::format("({} as isize)", right)); + if (isRValue()) { + StrCat(token::kSemiColon, ConvertFreshRValue(lhs)); + } + MarkFresh(); + } else { + EmitCompoundSetOrAssign( + lhs, ConvertCompoundAssignValue(compound, ConvertRValue(lhs), right)); + } + return; + } + if (!global && + (compound || (isRValue() && NeedsAssignmentBinding(lhs, rhs)))) { // End target borrows before an enclosing expression consumes the result. PushBrace brace(*this); auto right = NewTempName(); diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs index 7d2ff02f09..34f713292b 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs @@ -28,32 +28,18 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - match ( - { - { - match ( - { - { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) - } - }, - &mut (*dtorCount_2.with(Value::clone).borrow_mut()), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } - } - }, - &mut (*copyCount_1.with(Value::clone).borrow_mut()), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() + }); + dtorCount_2.with(|rc| *rc.borrow()) } - } + }); + copyCount_1.with(|rc| *rc.borrow()) } }); } diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs index 90dae667a2..d2ffb7060e 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs @@ -28,32 +28,18 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - match ( - { - { - match ( - { - { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) - } - }, - &mut (*dtorCount_2.with(Value::clone).borrow_mut()), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } - } - }, - &mut (*copyCount_1.with(Value::clone).borrow_mut()), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() + }); + dtorCount_2.with(|rc| *rc.borrow()) } - } + }); + copyCount_1.with(|rc| *rc.borrow()) } }); } diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs index 96d2a68301..dd6c90c7ef 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs @@ -28,32 +28,18 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - match ( - { - { - match ( - { - { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) - } - }, - &mut (*dtorCount_2.with(Value::clone).borrow_mut()), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } - } - }, - &mut (*copyCount_1.with(Value::clone).borrow_mut()), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() + }); + dtorCount_2.with(|rc| *rc.borrow()) } - } + }); + copyCount_1.with(|rc| *rc.borrow()) } }); } diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs index d02a04e315..01e84bfcb3 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs @@ -28,32 +28,18 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - match ( - { - { - match ( - { - { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) - } - }, - &mut (*dtorCount_2.with(Value::clone).borrow_mut()), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } - } - }, - &mut (*copyCount_1.with(Value::clone).borrow_mut()), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() + }); + dtorCount_2.with(|rc| *rc.borrow()) } - } + }); + copyCount_1.with(|rc| *rc.borrow()) } }); } diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs index d3152789e0..21b612eed3 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs @@ -28,32 +28,18 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - match ( - { - { - match ( - { - { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) - } - }, - &mut (*dtorCount_2.with(Value::clone).borrow_mut()), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } - } - }, - &mut (*copyCount_1.with(Value::clone).borrow_mut()), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() + }); + dtorCount_2.with(|rc| *rc.borrow()) } - } + }); + copyCount_1.with(|rc| *rc.borrow()) } }); } diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs index 4b807369d7..da9dce2d90 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs @@ -28,32 +28,18 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - match ( - { - { - match ( - { - { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) - } - }, - &mut (*dtorCount_2.with(Value::clone).borrow_mut()), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } - } - }, - &mut (*copyCount_1.with(Value::clone).borrow_mut()), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() + }); + dtorCount_2.with(|rc| *rc.borrow()) } - } + }); + copyCount_1.with(|rc| *rc.borrow()) } }); } diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs index 47f49092e6..98847588b6 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs @@ -28,32 +28,18 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - match ( - { - { - match ( - { - { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) - } - }, - &mut (*dtorCount_2.with(Value::clone).borrow_mut()), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } - } - }, - &mut (*copyCount_1.with(Value::clone).borrow_mut()), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() + }); + dtorCount_2.with(|rc| *rc.borrow()) } - } + }); + copyCount_1.with(|rc| *rc.borrow()) } }); } diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs index 224d0acbbd..fbd6e1813e 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs @@ -28,32 +28,18 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - match ( - { - { - match ( - { - { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) - } - }, - &mut (*dtorCount_2.with(Value::clone).borrow_mut()), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } - } - }, - &mut (*copyCount_1.with(Value::clone).borrow_mut()), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() + }); + dtorCount_2.with(|rc| *rc.borrow()) } - } + }); + copyCount_1.with(|rc| *rc.borrow()) } }); } diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index dd2f665a12..66705328fd 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -60,32 +60,18 @@ impl LifetimeTracked { pub fn reset() { ctorCount_1.with(|rc| { *rc.borrow_mut() = { - match ( - { - { - match ( - { - { - useCount_4.with(|rc| *rc.borrow_mut() = 0); - useCount_4.with(|rc| *rc.borrow()) - } - }, - &mut (*dtorCount_3.with(Value::clone).borrow_mut()), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + copyCount_2.with(|rc| { + *rc.borrow_mut() = { + dtorCount_3.with(|rc| { + *rc.borrow_mut() = { + useCount_4.with(|rc| *rc.borrow_mut() = 0); + useCount_4.with(|rc| *rc.borrow()) } - } - }, - &mut (*copyCount_2.with(Value::clone).borrow_mut()), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() + }); + dtorCount_3.with(|rc| *rc.borrow()) } - } + }); + copyCount_2.with(|rc| *rc.borrow()) } }); } diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs index cb3b51776c..6f94c793f0 100644 --- a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs @@ -28,32 +28,18 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - match ( - { - { - match ( - { - { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) - } - }, - &mut (*dtorCount_2.with(Value::clone).borrow_mut()), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } - } - }, - &mut (*copyCount_1.with(Value::clone).borrow_mut()), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() + }); + dtorCount_2.with(|rc| *rc.borrow()) } - } + }); + copyCount_1.with(|rc| *rc.borrow()) } }); } diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs index a04576aa31..0935da1fb3 100644 --- a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs @@ -28,32 +28,18 @@ impl LifetimeTracked { pub fn reset() { ctorCount_0.with(|rc| { *rc.borrow_mut() = { - match ( - { - { - match ( - { - { - useCount_3.with(|rc| *rc.borrow_mut() = 0); - useCount_3.with(|rc| *rc.borrow()) - } - }, - &mut (*dtorCount_2.with(Value::clone).borrow_mut()), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) } - } - }, - &mut (*copyCount_1.with(Value::clone).borrow_mut()), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() + }); + dtorCount_2.with(|rc| *rc.borrow()) } - } + }); + copyCount_1.with(|rc| *rc.borrow()) } }); } diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index ff6510bf26..c8f2b3f1c3 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -56,11 +56,26 @@ template void test_comma() { int global = 10; int observe_global(int assigned) { return assigned + global; } int observe(int assigned, const int *stored) { return assigned + *stored; } +struct GlobalRecord { + int value; +} global_record{10}; +int observe_record(int assigned) { return assigned + global_record.value; } +int targets[2] = {10, 20}; +int *cursor = targets; void test_borrows() { std::printf("%d\n", observe_global(global = 99)); std::printf("%d\n", observe_global(global += 5)); std::printf("%d\n", observe_global(global = observe(0, &global))); + static short promoted = 10; + int assigned = (promoted += (promoted = -1, 0.5)); + std::printf("%d %d\n", assigned, int(promoted)); + static bool flag = false; + bool enabled = (flag += (observe(0, &global), 0.5)); + std::printf("%d %d\n", int(enabled), int(flag)); + std::printf("%d\n", observe_record(global_record.value = 99)); + int *shifted = (cursor -= (cursor = targets + 1, 1)); + std::printf("%d %d\n", cursor == targets, shifted == cursor); int local = 10; std::printf("%d\n", observe(local = 99, &local)); diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 8ec5168f11..4a3600abbe 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -548,7 +548,26 @@ pub fn observe_global_6(mut assigned: i32) -> i32 { pub fn observe_7(mut assigned: i32, mut stored: Ptr) -> i32 { return ({ assigned } + { (stored.read()) }); } -pub fn test_borrows_8() { +#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(4)] +pub struct GlobalRecord { + #[offset(0)] + pub value: i32, +} +thread_local!( + pub static global_record_8: Value = + Rc::new(RefCell::new(GlobalRecord { value: 10 })); +); +pub fn observe_record_9(mut assigned: i32) -> i32 { + return (assigned + { global_record_8.with(|rc| *rc.borrow()).value }); +} +thread_local!( + pub static targets_10: Value> = Rc::new(RefCell::new(Box::new([10, 20]))); +); +thread_local!( + pub static cursor_11: Value> = Rc::new(RefCell::new(targets_10.with(|v| v.decay()))); +); +pub fn test_borrows_12() { printf!( b"%d\n", ({ @@ -571,18 +590,80 @@ pub fn test_borrows_8() { b"%d\n", ({ observe_global_6({ + let __rhs = ({ observe_7(0, (global_5.with(|v| v.as_pointer()))) }); + global_5.with(|rc| *rc.borrow_mut() = __rhs); + global_5.with(|rc| *rc.borrow()) + }) + }) + ); + let mut assigned: i32 = (({ + let __tmp_56 = { + promoted_13.with(|rc| *rc.borrow_mut() = (-1_i32 as i16)); + 0.5_f64 + }; + { + promoted_13.with(|rc| { + *rc.borrow_mut() = + { ((promoted_13.with(|rc| *rc.borrow()) as f64) + (__tmp_56 as f64)) as i16 } + }); + promoted_13.with(|rc| *rc.borrow()) + } + }) as i32); + printf!( + b"%d %d\n", + assigned, + (promoted_13.with(|rc| *rc.borrow()) as i32) + ); + let mut enabled: bool = ({ + let __tmp_57 = { + ({ observe_7(0, (global_5.with(|v| v.as_pointer()))) }); + 0.5_f64 + }; + { + flag_14.with(|rc| { + *rc.borrow_mut() = + { ((flag_14.with(|rc| *rc.borrow()) as u8 as f64) + (__tmp_57 as f64)) != 0.0 } + }); + flag_14.with(|rc| *rc.borrow()) + } + }); + printf!( + b"%d %d\n", + (enabled as i32), + (flag_14.with(|rc| *rc.borrow()) as i32) + ); + printf!( + b"%d\n", + ({ + observe_record_9({ match ( - { ({ observe_7(0, (global_5.with(|v| v.as_pointer()))) }) }, - &mut (*global_5.with(Value::clone).borrow_mut()), + { 99 }, + &mut ((*global_record_8.with(Value::clone).borrow_mut()).value), ) { - (__tmp_56, __tmp_57) => { - (*__tmp_57) = __tmp_56; - (*__tmp_57).clone() + (__tmp_58, __tmp_59) => { + (*__tmp_59) = __tmp_58; + (*__tmp_59).clone() } } }) }) ); + let mut shifted: Ptr = ({ + let __tmp_60 = { + cursor_11 + .with(|rc| *rc.borrow_mut() = targets_10.with(|v| v.decay()).offset((1) as isize)); + 1 + }; + cursor_11.with(|rc| *rc.borrow_mut() -= (__tmp_60 as isize)); + (*cursor_11.with(Value::clone).borrow()).clone() + }); + printf!( + b"%d %d\n", + (({ (*cursor_11.with(Value::clone).borrow()).clone() } == { + targets_10.with(|v| v.decay()) + }) as i32), + (({ (shifted).clone() } == { (*cursor_11.with(Value::clone).borrow()).clone() }) as i32) + ); let local: Value = Rc::new(RefCell::new(10)); printf!( b"%d\n", @@ -606,15 +687,15 @@ pub fn test_borrows_8() { observe_7(_assigned, _stored) }) ); - let record: Value = Rc::new(RefCell::new(Record_9 { value: 10 })); + let record: Value = Rc::new(RefCell::new(Record_15 { value: 10 })); printf!( b"%d\n", ({ let _assigned: i32 = { match ({ 99 }, &mut ((*record.borrow_mut()).value)) { - (__tmp_58, __tmp_59) => { - (*__tmp_59) = __tmp_58; - (*__tmp_59).clone() + (__tmp_61, __tmp_62) => { + (*__tmp_62) = __tmp_61; + (*__tmp_62).clone() } } }; @@ -627,9 +708,9 @@ pub fn test_borrows_8() { ({ let _assigned: i32 = { match ({ 5 }, &mut ((*record.borrow_mut()).value)) { - (__tmp_60, __tmp_61) => { - (*__tmp_61) = (((*__tmp_61) as i32) + (__tmp_60 as i32)) as i32; - (*__tmp_61).clone() + (__tmp_63, __tmp_64) => { + (*__tmp_64) = (((*__tmp_64) as i32) + (__tmp_63 as i32)) as i32; + (*__tmp_64).clone() } } }; @@ -643,9 +724,9 @@ pub fn test_borrows_8() { ({ let _assigned: i32 = { match ({ 99 }, &mut ((*values.borrow_mut())[0_usize])) { - (__tmp_62, __tmp_63) => { - (*__tmp_63) = __tmp_62; - (*__tmp_63).clone() + (__tmp_65, __tmp_66) => { + (*__tmp_66) = __tmp_65; + (*__tmp_66).clone() } } }; @@ -658,9 +739,9 @@ pub fn test_borrows_8() { ({ let _assigned: i32 = { match ({ 5 }, &mut ((*values.borrow_mut())[0_usize])) { - (__tmp_64, __tmp_65) => { - (*__tmp_65) = (((*__tmp_65) as i32) + (__tmp_64 as i32)) as i32; - (*__tmp_65).clone() + (__tmp_67, __tmp_68) => { + (*__tmp_68) = (((*__tmp_68) as i32) + (__tmp_67 as i32)) as i32; + (*__tmp_68).clone() } } }; @@ -669,28 +750,34 @@ pub fn test_borrows_8() { }) ); } +thread_local!( + static promoted_13: Value = Rc::new(RefCell::new(10_i16)); +); +thread_local!( + static flag_14: Value = Rc::new(RefCell::new(false)); +); #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(4)] -pub struct Record_9 { +pub struct Record_15 { #[offset(0)] pub value: i32, } thread_local!( - pub static selected_values_10: Value> = + pub static selected_values_16: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); ); #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct IndexedBinding {} -pub fn test_binding_11() { +pub fn test_binding_17() { let owner: Value = Rc::new(RefCell::new(::default())); - let __decomp_12: Ptr = owner.as_pointer(); - let value: Ptr = ({ IndexedBindingImpl::get_1_0(&__decomp_12) }); + let __decomp_18: Ptr = owner.as_pointer(); + let value: Ptr = ({ IndexedBindingImpl::get_1_0(&__decomp_18) }); let mut result: u32 = ({ - match ({ 1_u32 }, &({ IndexedBindingImpl::get_1_0(&__decomp_12) })) { - (__tmp_66, __tmp_67) => __tmp_67.with_mut(|__tmp_67| { - (*__tmp_67) = (((*__tmp_67) as u32).wrapping_add((__tmp_66 as u32))) as u32; - (*__tmp_67).clone() + match ({ 1_u32 }, &({ IndexedBindingImpl::get_1_0(&__decomp_18) })) { + (__tmp_69, __tmp_70) => __tmp_70.with_mut(|__tmp_70| { + (*__tmp_70) = (((*__tmp_70) as u32).wrapping_add((__tmp_69 as u32))) as u32; + (*__tmp_70).clone() }), } }); @@ -699,7 +786,7 @@ pub fn test_binding_11() { result, ({ let __idx0 = (0) as usize; - selected_values_10.with(|rc| rc.borrow()[__idx0]) + selected_values_16.with(|rc| rc.borrow()[__idx0]) }) ); } @@ -727,9 +814,9 @@ fn main_0() -> i32 { 0 )), ) { - (__tmp_68, __tmp_69) => __tmp_69.with_mut(|__tmp_69| { - (*__tmp_69) = (((*__tmp_69) as u32).wrapping_add((__tmp_68 as u32))) as u32; - (*__tmp_69).clone() + (__tmp_71, __tmp_72) => __tmp_72.with_mut(|__tmp_72| { + (*__tmp_72) = (((*__tmp_72) as u32).wrapping_add((__tmp_71 as u32))) as u32; + (*__tmp_72).clone() }), } }); @@ -739,8 +826,8 @@ fn main_0() -> i32 { result, (*values.borrow())[(0) as usize] ); - ({ test_borrows_8() }); - ({ test_binding_11() }); + ({ test_borrows_12() }); + ({ test_binding_17() }); return 0; } pub trait IndexedBindingImpl { @@ -748,15 +835,18 @@ pub trait IndexedBindingImpl { } impl IndexedBindingImpl for Ptr { fn get_1_0(&self) -> Ptr { - return selected_values_10.with(|v| v.decay()).offset( + return selected_values_16.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; - selected_values_10.with(|rc| rc.borrow()[__idx0]) + selected_values_16.with(|rc| rc.borrow()[__idx0]) }), ); } } pub fn __cpp2rust_init_globals() { let _ = global_5.with(|_| ()); - let _ = selected_values_10.with(|_| ()); + let _ = global_record_8.with(|_| ()); + let _ = targets_10.with(|_| ()); + let _ = cursor_11.with(|_| ()); + let _ = selected_values_16.with(|_| ()); } diff --git a/tests/unit/out/refcount/global_call_temporaries.rs b/tests/unit/out/refcount/global_call_temporaries.rs index 9d97328416..6beec818a6 100644 --- a/tests/unit/out/refcount/global_call_temporaries.rs +++ b/tests/unit/out/refcount/global_call_temporaries.rs @@ -36,78 +36,60 @@ thread_local!( ); thread_local!( pub static assigned_4: Value = Rc::new(RefCell::new({ - let __tmp_4: Value; - let __tmp_5: Value; + let __tmp_2: Value; + let __tmp_3: Value; ({ - match ( - { - { - __tmp_4 = Rc::new(RefCell::new(6)); - __tmp_5 = Rc::new(RefCell::new(5)); - (if CppLess::less(&__tmp_4.as_pointer(), &__tmp_5.as_pointer()) { - __tmp_4.as_pointer() - } else { - __tmp_5.as_pointer() - } - .read()) + { + let __rhs = { + __tmp_2 = Rc::new(RefCell::new(6)); + __tmp_3 = Rc::new(RefCell::new(5)); + (if CppLess::less(&__tmp_2.as_pointer(), &__tmp_3.as_pointer()) { + __tmp_2.as_pointer() + } else { + __tmp_3.as_pointer() } - }, - &mut (*x_2.with(Value::clone).borrow_mut()), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } + .read()) + }; + x_2.with(|rc| *rc.borrow_mut() = __rhs) + }; + x_2.with(|rc| *rc.borrow()) }) })); ); thread_local!( pub static accumulated_5: Value = Rc::new(RefCell::new({ - let __tmp_8: Value; - let __tmp_9: Value; + let __tmp_4: Value; + let __tmp_5: Value; ({ - match ( - { - { - __tmp_8 = Rc::new(RefCell::new(1)); - __tmp_9 = Rc::new(RefCell::new(2)); - (if CppLess::less(&__tmp_8.as_pointer(), &__tmp_9.as_pointer()) { - __tmp_9.as_pointer() - } else { - __tmp_8.as_pointer() - } - .read()) + { + let __rhs = { + __tmp_4 = Rc::new(RefCell::new(1)); + __tmp_5 = Rc::new(RefCell::new(2)); + (if CppLess::less(&__tmp_4.as_pointer(), &__tmp_5.as_pointer()) { + __tmp_5.as_pointer() + } else { + __tmp_4.as_pointer() } - }, - &mut (*y_3.with(Value::clone).borrow_mut()), - ) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as i32) + (__tmp_6 as i32)) as i32; - (*__tmp_7).clone() - } - } + .read()) + }; + y_3.with(|rc| *rc.borrow_mut() += __rhs) + }; + y_3.with(|rc| *rc.borrow()) }) })); ); thread_local!( pub static call_assigned_6: Value = Rc::new(RefCell::new({ - let __tmp_12: Value; + let __tmp_6: Value; ({ - match ( - { - ({ - __tmp_12 = Rc::new(RefCell::new(5)); - read_0(__tmp_12.as_pointer()) - }) - }, - &mut (*x_2.with(Value::clone).borrow_mut()), - ) { - (__tmp_10, __tmp_11) => { - (*__tmp_11) = __tmp_10; - (*__tmp_11).clone() - } - } + { + let __rhs = ({ + __tmp_6 = Rc::new(RefCell::new(5)); + read_0(__tmp_6.as_pointer()) + }); + x_2.with(|rc| *rc.borrow_mut() = __rhs) + }; + x_2.with(|rc| *rc.borrow()) }) })); ); @@ -125,38 +107,38 @@ pub fn read_record_8(value: Ptr) -> i32 { } thread_local!( pub static aggregate_selected_9: Value = Rc::new(RefCell::new({ - let __tmp_14: Value; - let __tmp_15: Value; - let __tmp_13: Value>; - let __tmp_17: Value; - let __tmp_18: Value; - let __tmp_16: Value; + let __tmp_8: Value; + let __tmp_9: Value; + let __tmp_7: Value>; + let __tmp_11: Value; + let __tmp_12: Value; + let __tmp_10: Value; (({ - __tmp_13 = Rc::new(RefCell::new(Box::new([{ - __tmp_14 = Rc::new(RefCell::new(4)); - __tmp_15 = Rc::new(RefCell::new(3)); - (if CppLess::less(&__tmp_14.as_pointer(), &__tmp_15.as_pointer()) { - __tmp_14.as_pointer() + __tmp_7 = Rc::new(RefCell::new(Box::new([{ + __tmp_8 = Rc::new(RefCell::new(4)); + __tmp_9 = Rc::new(RefCell::new(3)); + (if CppLess::less(&__tmp_8.as_pointer(), &__tmp_9.as_pointer()) { + __tmp_8.as_pointer() } else { - __tmp_15.as_pointer() + __tmp_9.as_pointer() } .read()) }]))); - read_array_7(__tmp_13.decay()) + read_array_7(__tmp_7.decay()) }) + ({ - __tmp_16 = Rc::new(RefCell::new(Item { + __tmp_10 = Rc::new(RefCell::new(Item { value: { - __tmp_17 = Rc::new(RefCell::new(5)); - __tmp_18 = Rc::new(RefCell::new(6)); - (if CppLess::less(&__tmp_17.as_pointer(), &__tmp_18.as_pointer()) { - __tmp_18.as_pointer() + __tmp_11 = Rc::new(RefCell::new(5)); + __tmp_12 = Rc::new(RefCell::new(6)); + (if CppLess::less(&__tmp_11.as_pointer(), &__tmp_12.as_pointer()) { + __tmp_12.as_pointer() } else { - __tmp_17.as_pointer() + __tmp_11.as_pointer() } .read()) }, })); - read_record_8(__tmp_16.as_pointer()) + read_record_8(__tmp_10.as_pointer()) })) })); ); @@ -168,12 +150,12 @@ thread_local!( ); thread_local!( pub static mapped_selected_12: Value = { - let __tmp_19: Value; + let __tmp_13: Value; Rc::new(RefCell::new( (({ - __tmp_19 = Rc::new(RefCell::new((right_11.with(|rc| *rc.borrow()) as u64))); - (if CppLess::less(&__tmp_19.as_pointer(), &left_10.with(|v| v.as_pointer())) { - __tmp_19.as_pointer() + __tmp_13 = Rc::new(RefCell::new((right_11.with(|rc| *rc.borrow()) as u64))); + (if CppLess::less(&__tmp_13.as_pointer(), &left_10.with(|v| v.as_pointer())) { + __tmp_13.as_pointer() } else { left_10.with(|v| v.as_pointer()) } @@ -187,12 +169,12 @@ pub fn get_13() -> usize { } thread_local!( static value_14: Value = { - let __tmp_20: Value; + let __tmp_14: Value; Rc::new(RefCell::new( (({ - __tmp_20 = Rc::new(RefCell::new((right_11.with(|rc| *rc.borrow()) as u64))); - (if CppLess::less(&left_10.with(|v| v.as_pointer()), &__tmp_20.as_pointer()) { - __tmp_20.as_pointer() + __tmp_14 = Rc::new(RefCell::new((right_11.with(|rc| *rc.borrow()) as u64))); + (if CppLess::less(&left_10.with(|v| v.as_pointer()), &__tmp_14.as_pointer()) { + __tmp_14.as_pointer() } else { left_10.with(|v| v.as_pointer()) } @@ -218,38 +200,38 @@ fn main_0() -> i32 { } thread_local!( static aggregate_static_15: Value = Rc::new(RefCell::new({ - let __tmp_22: Value; - let __tmp_23: Value; - let __tmp_21: Value>; - let __tmp_25: Value; - let __tmp_26: Value; - let __tmp_24: Value; + let __tmp_16: Value; + let __tmp_17: Value; + let __tmp_15: Value>; + let __tmp_19: Value; + let __tmp_20: Value; + let __tmp_18: Value; (({ - __tmp_21 = Rc::new(RefCell::new(Box::new([{ - __tmp_22 = Rc::new(RefCell::new(7)); - __tmp_23 = Rc::new(RefCell::new(8)); - (if CppLess::less(&__tmp_22.as_pointer(), &__tmp_23.as_pointer()) { - __tmp_23.as_pointer() + __tmp_15 = Rc::new(RefCell::new(Box::new([{ + __tmp_16 = Rc::new(RefCell::new(7)); + __tmp_17 = Rc::new(RefCell::new(8)); + (if CppLess::less(&__tmp_16.as_pointer(), &__tmp_17.as_pointer()) { + __tmp_17.as_pointer() } else { - __tmp_22.as_pointer() + __tmp_16.as_pointer() } .read()) }]))); - read_array_7(__tmp_21.decay()) + read_array_7(__tmp_15.decay()) }) + ({ - __tmp_24 = Rc::new(RefCell::new(Item { + __tmp_18 = Rc::new(RefCell::new(Item { value: { - __tmp_25 = Rc::new(RefCell::new(10)); - __tmp_26 = Rc::new(RefCell::new(9)); - (if CppLess::less(&__tmp_25.as_pointer(), &__tmp_26.as_pointer()) { - __tmp_25.as_pointer() + __tmp_19 = Rc::new(RefCell::new(10)); + __tmp_20 = Rc::new(RefCell::new(9)); + (if CppLess::less(&__tmp_19.as_pointer(), &__tmp_20.as_pointer()) { + __tmp_19.as_pointer() } else { - __tmp_26.as_pointer() + __tmp_20.as_pointer() } .read()) }, })); - read_record_8(__tmp_24.as_pointer()) + read_record_8(__tmp_18.as_pointer()) })) })); ); diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index 951c394e87..a0652c2b21 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -397,20 +397,13 @@ fn main_0() -> i32 { let source: Value = Rc::new(RefCell::new(Item::new_1({ 20 }))); made_1.with(|rc| { *rc.borrow_mut() = { - match ( - { - { - moves_3.with(|rc| *rc.borrow_mut() = 0); - moves_3.with(|rc| *rc.borrow()) - } - }, - &mut (*copies_2.with(Value::clone).borrow_mut()), - ) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = __tmp_12; - (*__tmp_13).clone() + copies_2.with(|rc| { + *rc.borrow_mut() = { + moves_3.with(|rc| *rc.borrow_mut() = 0); + moves_3.with(|rc| *rc.borrow()) } - } + }); + copies_2.with(|rc| *rc.borrow()) } }); let hit: Value<( @@ -418,12 +411,12 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_14,) => { + (__tmp_12,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::copy_from({ (__tmp_14).clone() }))), + Rc::new(RefCell::new(Item::copy_from({ (__tmp_12).clone() }))), ) }); ( @@ -450,8 +443,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_15, __tmp_16) => { - (*__tmp_16) = (((*__tmp_16) as i32) & (__tmp_15 as i32)) != 0; + (__tmp_13, __tmp_14) => { + (*__tmp_14) = (((*__tmp_14) as i32) & (__tmp_13 as i32)) != 0; } } }; @@ -460,12 +453,12 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_17,) => { + (__tmp_15,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_17).clone() }))), + Rc::new(RefCell::new(Item::move_from({ (__tmp_15).clone() }))), ) }); ( @@ -494,12 +487,12 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_18,) => { + (__tmp_16,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::copy_from({ (__tmp_18).clone() }))), + Rc::new(RefCell::new(Item::copy_from({ (__tmp_16).clone() }))), ) }); ( @@ -526,8 +519,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_19, __tmp_20) => { - (*__tmp_20) = (((*__tmp_20) as i32) & (__tmp_19 as i32)) != 0; + (__tmp_17, __tmp_18) => { + (*__tmp_18) = (((*__tmp_18) as i32) & (__tmp_17 as i32)) != 0; } } }; @@ -537,12 +530,12 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_21,) => { + (__tmp_19,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_21).clone() }))), + Rc::new(RefCell::new(Item::move_from({ (__tmp_19).clone() }))), ) }); ( @@ -570,8 +563,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_22, __tmp_23) => { - (*__tmp_23) = (((*__tmp_23) as i32) & (__tmp_22 as i32)) != 0; + (__tmp_20, __tmp_21) => { + (*__tmp_21) = (((*__tmp_21) as i32) & (__tmp_20 as i32)) != 0; } } }; @@ -598,11 +591,11 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ reference_5(counter.as_pointer()) }),) { - (__tmp_24,) => { + (__tmp_22,) => { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(RefItem::new_2({ (__tmp_24).clone() }, { 2 }))), + Rc::new(RefCell::new(RefItem::new_2({ (__tmp_22).clone() }, { 2 }))), ) }); ( @@ -625,11 +618,11 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ reference_5(counter.as_pointer()) }),) { - (__tmp_25,) => { + (__tmp_23,) => { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(RefItem::new_2({ (__tmp_25).clone() }, { 2 }))), + Rc::new(RefCell::new(RefItem::new_2({ (__tmp_23).clone() }, { 2 }))), ) }); ( @@ -658,46 +651,39 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_26, __tmp_27) => { - (*__tmp_27) = (((*__tmp_27) as i32) & (__tmp_26 as i32)) != 0; + (__tmp_24, __tmp_25) => { + (*__tmp_25) = (((*__tmp_25) as i32) & (__tmp_24 as i32)) != 0; } } }; (*key.borrow_mut()) = 0; made_1.with(|rc| { *rc.borrow_mut() = { - match ( - { - { - moves_3.with(|rc| *rc.borrow_mut() = 0); - moves_3.with(|rc| *rc.borrow()) - } - }, - &mut (*copies_2.with(Value::clone).borrow_mut()), - ) { - (__tmp_28, __tmp_29) => { - (*__tmp_29) = __tmp_28; - (*__tmp_29).clone() + copies_2.with(|rc| { + *rc.borrow_mut() = { + moves_3.with(|rc| *rc.borrow_mut() = 0); + moves_3.with(|rc| *rc.borrow()) } - } + }); + copies_2.with(|rc| *rc.borrow()) } }); let temporary_hit: Value<( Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_31: Value; + let __tmp_27: Value; match ({ - __tmp_31 = Rc::new(RefCell::new(Item::new_1({ 30 }))); - __tmp_31.as_pointer() + __tmp_27 = Rc::new(RefCell::new(Item::new_1({ 30 }))); + __tmp_27.as_pointer() },) { - (__tmp_30,) => { + (__tmp_26,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_30).clone() }))), + Rc::new(RefCell::new(Item::move_from({ (__tmp_26).clone() }))), ) }); ( @@ -722,18 +708,18 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_33: Value; + let __tmp_29: Value; match ({ - __tmp_33 = Rc::new(RefCell::new(Item::new_1({ 40 }))); - __tmp_33.as_pointer() + __tmp_29 = Rc::new(RefCell::new(Item::new_1({ 40 }))); + __tmp_29.as_pointer() },) { - (__tmp_32,) => { + (__tmp_28,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_32).clone() }))), + Rc::new(RefCell::new(Item::move_from({ (__tmp_28).clone() }))), ) }); ( @@ -760,8 +746,8 @@ fn main_0() -> i32 { }, &mut (ok), ) { - (__tmp_34, __tmp_35) => { - (*__tmp_35) = (((*__tmp_35) as i32) & (__tmp_34 as i32)) != 0; + (__tmp_30, __tmp_31) => { + (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; } } }; diff --git a/tests/unit/out/refcount/swap_map_no_copy.rs b/tests/unit/out/refcount/swap_map_no_copy.rs index 6b516a5055..1e6b008c52 100644 --- a/tests/unit/out/refcount/swap_map_no_copy.rs +++ b/tests/unit/out/refcount/swap_map_no_copy.rs @@ -221,20 +221,13 @@ pub fn swapped_once_6() -> bool { && (moved_dtors_5.with(|rc| *rc.borrow()) == 1); moves_3.with(|rc| { *rc.borrow_mut() = { - match ( - { - { - moved_dtors_5.with(|rc| *rc.borrow_mut() = 0); - moved_dtors_5.with(|rc| *rc.borrow()) - } - }, - &mut (*move_assigns_4.with(Value::clone).borrow_mut()), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() + move_assigns_4.with(|rc| { + *rc.borrow_mut() = { + moved_dtors_5.with(|rc| *rc.borrow_mut() = 0); + moved_dtors_5.with(|rc| *rc.borrow()) } - } + }); + move_assigns_4.with(|rc| *rc.borrow()) } }); return ok; @@ -268,10 +261,10 @@ fn main_0() -> i32 { let _o: Value = Rc::new(RefCell::new(Tracked::new_1({ 10 }))); TrackedImpl::move_assign( &match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_2,) => { + (__tmp_0,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_2, + __tmp_0, |__k| cpp_move!(__k), || ::default(), ) @@ -285,10 +278,10 @@ fn main_0() -> i32 { let _o: Value = Rc::new(RefCell::new(Tracked::new_1({ 20 }))); TrackedImpl::move_assign( &match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_3,) => { + (__tmp_1,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_3, + __tmp_1, |__k| cpp_move!(__k), || ::default(), ) @@ -303,10 +296,10 @@ fn main_0() -> i32 { let _o: Value = Rc::new(RefCell::new(Tracked::new_1({ 30 }))); TrackedImpl::move_assign( &match (Rc::new(RefCell::new(3)).as_pointer(),) { - (__tmp_4,) => { + (__tmp_2,) => { ({ (*m2.borrow_mut()).subscript_move( - __tmp_4, + __tmp_2, |__k| cpp_move!(__k), || ::default(), ) @@ -319,10 +312,10 @@ fn main_0() -> i32 { assert!((copies_0.with(|rc| *rc.borrow()) == 0)); cpp_swap!( match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_5,) => { + (__tmp_3,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_5, + __tmp_3, |__k| cpp_move!(__k), || ::default(), ) @@ -330,10 +323,10 @@ fn main_0() -> i32 { } }, match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_6,) => { + (__tmp_4,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_6, + __tmp_4, |__k| cpp_move!(__k), || ::default(), ) @@ -343,10 +336,10 @@ fn main_0() -> i32 { ); assert!( (match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_7,) => { + (__tmp_5,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_7, + __tmp_5, |__k| cpp_move!(__k), || ::default(), ) @@ -356,10 +349,10 @@ fn main_0() -> i32 { .with(|__s| __s.v) == 20) && (match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_8,) => { + (__tmp_6,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_8, + __tmp_6, |__k| cpp_move!(__k), || ::default(), ) @@ -374,10 +367,10 @@ fn main_0() -> i32 { assert!( ((*m1.borrow()).len() == 1_usize) && (match (Rc::new(RefCell::new(3)).as_pointer(),) { - (__tmp_9,) => { + (__tmp_7,) => { ({ (*m1.borrow_mut()).subscript_move( - __tmp_9, + __tmp_7, |__k| cpp_move!(__k), || ::default(), ) @@ -390,10 +383,10 @@ fn main_0() -> i32 { assert!( (((*m2.borrow()).len() == 2_usize) && (match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_10,) => { + (__tmp_8,) => { ({ (*m2.borrow_mut()).subscript_move( - __tmp_10, + __tmp_8, |__k| cpp_move!(__k), || ::default(), ) @@ -403,10 +396,10 @@ fn main_0() -> i32 { .with(|__s| __s.v) == 20)) && (match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_11,) => { + (__tmp_9,) => { ({ (*m2.borrow_mut()).subscript_move( - __tmp_11, + __tmp_9, |__k| cpp_move!(__k), || ::default(), ) @@ -433,12 +426,12 @@ fn main_0() -> i32 { assert!((copies_0.with(|rc| *rc.borrow()) == 0)); let vec_: Value> = Rc::new(RefCell::new(Vec::new())); { - let mut __tmp_12 = { Tracked::new_1({ 4 }) }; - (*vec_.borrow_mut()).push(__tmp_12); + let mut __tmp_10 = { Tracked::new_1({ 4 }) }; + (*vec_.borrow_mut()).push(__tmp_10); }; { - let mut __tmp_13 = { Tracked::new_1({ 5 }) }; - (*vec_.borrow_mut()).push(__tmp_13); + let mut __tmp_11 = { Tracked::new_1({ 5 }) }; + (*vec_.borrow_mut()).push(__tmp_11); }; cpp_swap!(vec_.decay().offset(0_usize), vec_.decay().offset(1_usize)); assert!(({ ({ (*vec_.borrow())[0_usize].v } == 5) && ({ (*vec_.borrow())[1_usize].v } == 4) })); @@ -506,18 +499,18 @@ fn main_0() -> i32 { let grid: Value>> = Rc::new(RefCell::new(Vec::from_fn(2_usize, |_| Default::default()))); match (grid.decay().offset(0_usize), { Tracked::new_1({ 1 }) }) { - (__tmp_14, mut __tmp_15) => { - __tmp_14.with_mut(|__v: &mut Vec| __v.push(__tmp_15)); + (__tmp_12, mut __tmp_13) => { + __tmp_12.with_mut(|__v: &mut Vec| __v.push(__tmp_13)); } }; match (grid.decay().offset(0_usize), { Tracked::new_1({ 2 }) }) { - (__tmp_16, mut __tmp_17) => { - __tmp_16.with_mut(|__v: &mut Vec| __v.push(__tmp_17)); + (__tmp_14, mut __tmp_15) => { + __tmp_14.with_mut(|__v: &mut Vec| __v.push(__tmp_15)); } }; match (grid.decay().offset(1_usize), { Tracked::new_1({ 3 }) }) { - (__tmp_18, mut __tmp_19) => { - __tmp_18.with_mut(|__v: &mut Vec| __v.push(__tmp_19)); + (__tmp_16, mut __tmp_17) => { + __tmp_16.with_mut(|__v: &mut Vec| __v.push(__tmp_17)); } }; cpp_swap!( @@ -545,10 +538,10 @@ fn main_0() -> i32 { let _o: Value = Rc::new(RefCell::new(Tracked::new_1({ 1 }))); TrackedImpl::move_assign( &match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_20,) => { + (__tmp_18,) => { ({ (*maps.borrow_mut())[(0) as usize].subscript_move( - __tmp_20, + __tmp_18, |__k| cpp_move!(__k), || ::default(), ) @@ -562,10 +555,10 @@ fn main_0() -> i32 { let _o: Value = Rc::new(RefCell::new(Tracked::new_1({ 2 }))); TrackedImpl::move_assign( &match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_21,) => { + (__tmp_19,) => { ({ (*maps.borrow_mut())[(1) as usize].subscript_move( - __tmp_21, + __tmp_19, |__k| cpp_move!(__k), || ::default(), ) @@ -579,10 +572,10 @@ fn main_0() -> i32 { assert!( ((*maps.borrow())[(0) as usize].len() == 1_usize) && (match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_22,) => { + (__tmp_20,) => { ({ (*maps.borrow_mut())[(0) as usize].subscript_move( - __tmp_22, + __tmp_20, |__k| cpp_move!(__k), || ::default(), ) @@ -595,10 +588,10 @@ fn main_0() -> i32 { assert!( ((*maps.borrow())[(1) as usize].len() == 1_usize) && (match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_23,) => { + (__tmp_21,) => { ({ (*maps.borrow_mut())[(1) as usize].subscript_move( - __tmp_23, + __tmp_21, |__k| cpp_move!(__k), || ::default(), ) diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 3e85b5529c..3681648ed8 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -584,7 +584,23 @@ pub unsafe fn observe_global_6(mut assigned: i32) -> i32 { pub unsafe fn observe_7(mut assigned: i32, mut stored: *const i32) -> i32 { return ((assigned) + (*stored)); } -pub unsafe fn test_borrows_8() { +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct GlobalRecord { + pub value: i32, +} +pub static mut global_record_8: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { GlobalRecord { value: 10 } }); +pub unsafe fn observe_record_9(mut assigned: i32) -> i32 { + return ((assigned) + + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_8)).value)); +} +pub static mut targets_10: std::cell::LazyCell<[i32; 2]> = + std::cell::LazyCell::new(|| unsafe { [10, 20] }); +pub static mut cursor_11: std::cell::LazyCell<*mut i32> = std::cell::LazyCell::new(|| unsafe { + (*std::cell::LazyCell::force_mut(&mut *&raw mut targets_10)).as_mut_ptr() +}); +pub unsafe fn test_borrows_12() { (unsafe { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, @@ -635,6 +651,100 @@ pub unsafe fn test_borrows_8() { }), ) }); + let mut assigned: i32 = ((match ( + { + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_13)) = (-1_i32 as i16); + 0.5_f64 + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_13)), + ) { + (__tmp_58, __tmp_59) => { + (*__tmp_59) = (((*__tmp_59) as f64) + (__tmp_58 as f64)) as i16; + (*__tmp_59).clone() + } + }) as i32); + (unsafe { + libc::printf( + c"%d %d\n".as_ptr() as *const libc::c_char, + (assigned), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_13)) as i32), + ) + }); + let mut enabled: bool = (match ( + { + { + (unsafe { + observe_7( + 0, + (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)) + as *mut i32) + .cast_const(), + ) + }); + 0.5_f64 + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut flag_14)), + ) { + (__tmp_60, __tmp_61) => { + (*__tmp_61) = (((*__tmp_61) as u8 as f64) + (__tmp_60 as f64)) != 0.0; + (*__tmp_61).clone() + } + }); + (unsafe { + libc::printf( + c"%d %d\n".as_ptr() as *const libc::c_char, + (enabled as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut flag_14)) as i32), + ) + }); + (unsafe { + libc::printf( + c"%d\n".as_ptr() as *const libc::c_char, + (unsafe { + observe_record_9( + match ( + { 99 }, + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_8)) + .value), + ) { + (__tmp_62, __tmp_63) => { + (*__tmp_63) = __tmp_62; + (*__tmp_63).clone() + } + }, + ) + }), + ) + }); + let mut shifted: *mut i32 = (match ( + { + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_11)) = + (*std::cell::LazyCell::force_mut(&mut *&raw mut targets_10)) + .as_mut_ptr() + .offset((1) as isize); + 1 + } + }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_11)), + ) { + (__tmp_64, __tmp_65) => { + (*__tmp_65) = (*__tmp_65).offset(-(__tmp_64 as isize)); + (*__tmp_65).clone() + } + }); + (unsafe { + libc::printf( + c"%d %d\n".as_ptr() as *const libc::c_char, + (((*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_11)) + == ((*std::cell::LazyCell::force_mut(&mut *&raw mut targets_10)).as_mut_ptr())) + as i32), + (((shifted) == (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_11))) as i32), + ) + }); let mut local: i32 = 10; (unsafe { libc::printf( @@ -662,15 +772,15 @@ pub unsafe fn test_borrows_8() { }), ) }); - let mut record: Record_9 = Record_9 { value: 10 }; + let mut record: Record_15 = Record_15 { value: 10 }; (unsafe { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { let _assigned: i32 = match ({ 99 }, &mut (record.value)) { - (__tmp_58, __tmp_59) => { - (*__tmp_59) = __tmp_58; - (*__tmp_59).clone() + (__tmp_66, __tmp_67) => { + (*__tmp_67) = __tmp_66; + (*__tmp_67).clone() } }; let _stored: *const i32 = (&mut record.value as *mut i32).cast_const(); @@ -683,9 +793,9 @@ pub unsafe fn test_borrows_8() { c"%d\n".as_ptr() as *const libc::c_char, (unsafe { let _assigned: i32 = match ({ 5 }, &mut (record.value)) { - (__tmp_60, __tmp_61) => { - (*__tmp_61) = (((*__tmp_61) as i32) + (__tmp_60 as i32)) as i32; - (*__tmp_61).clone() + (__tmp_68, __tmp_69) => { + (*__tmp_69) = (((*__tmp_69) as i32) + (__tmp_68 as i32)) as i32; + (*__tmp_69).clone() } }; let _stored: *const i32 = (&mut record.value as *mut i32).cast_const(); @@ -699,9 +809,9 @@ pub unsafe fn test_borrows_8() { c"%d\n".as_ptr() as *const libc::c_char, (unsafe { let _assigned: i32 = match ({ 99 }, &mut (values[(0_usize)])) { - (__tmp_62, __tmp_63) => { - (*__tmp_63) = __tmp_62; - (*__tmp_63).clone() + (__tmp_70, __tmp_71) => { + (*__tmp_71) = __tmp_70; + (*__tmp_71).clone() } }; let _stored: *const i32 = (&mut values[(0_usize)] as *mut i32).cast_const(); @@ -714,9 +824,9 @@ pub unsafe fn test_borrows_8() { c"%d\n".as_ptr() as *const libc::c_char, (unsafe { let _assigned: i32 = match ({ 5 }, &mut (values[(0_usize)])) { - (__tmp_64, __tmp_65) => { - (*__tmp_65) = (((*__tmp_65) as i32) + (__tmp_64 as i32)) as i32; - (*__tmp_65).clone() + (__tmp_72, __tmp_73) => { + (*__tmp_73) = (((*__tmp_73) as i32) + (__tmp_72 as i32)) as i32; + (*__tmp_73).clone() } }; let _stored: *const i32 = (&mut values[(0_usize)] as *mut i32).cast_const(); @@ -725,41 +835,43 @@ pub unsafe fn test_borrows_8() { ) }); } +static mut promoted_13: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10_i16 }); +static mut flag_14: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { false }); #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Record_9 { +pub struct Record_15 { pub value: i32, } -pub static mut selected_values_10: std::cell::LazyCell<[u32; 3]> = +pub static mut selected_values_16: std::cell::LazyCell<[u32; 3]> = std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] pub struct IndexedBinding {} impl IndexedBinding { pub unsafe fn get_1_0(&mut self) -> *mut u32 { - return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_10)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_10))[(0) as usize]) + return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_16)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_16))[(0) as usize]) as usize]; } } -pub unsafe fn test_binding_11() { +pub unsafe fn test_binding_17() { let mut owner: IndexedBinding = ::default(); - let __decomp_12: *mut IndexedBinding = &mut owner; - let value: *mut u32 = (unsafe { IndexedBinding::get_1_0(&mut (*__decomp_12)) }); + let __decomp_18: *mut IndexedBinding = &mut owner; + let value: *mut u32 = (unsafe { IndexedBinding::get_1_0(&mut (*__decomp_18)) }); let mut result: u32 = (match ( { 1_u32 }, - &mut (*(unsafe { IndexedBinding::get_1_0(&mut (*__decomp_12)) })), + &mut (*(unsafe { IndexedBinding::get_1_0(&mut (*__decomp_18)) })), ) { - (__tmp_66, __tmp_67) => { - (*__tmp_67) = (((*__tmp_67) as u32).wrapping_add((__tmp_66 as u32))) as u32; - (*__tmp_67).clone() + (__tmp_74, __tmp_75) => { + (*__tmp_75) = (((*__tmp_75) as u32).wrapping_add((__tmp_74 as u32))) as u32; + (*__tmp_75).clone() } }); (unsafe { libc::printf( c"binding compound %u %u\n".as_ptr() as *const libc::c_char, (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_10))[(0) as usize]), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_16))[(0) as usize]), ) }); } @@ -785,9 +897,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_68, __tmp_69) => { - (*__tmp_69) = (((*__tmp_69) as u32).wrapping_add((__tmp_68 as u32))) as u32; - (*__tmp_69).clone() + (__tmp_76, __tmp_77) => { + (*__tmp_77) = (((*__tmp_77) as u32).wrapping_add((__tmp_76 as u32))) as u32; + (*__tmp_77).clone() } }); (unsafe { @@ -798,11 +910,14 @@ unsafe fn main_0() -> i32 { (values[(0) as usize]), ) }); - (unsafe { test_borrows_8() }); - (unsafe { test_binding_11() }); + (unsafe { test_borrows_12() }); + (unsafe { test_binding_17() }); return 0; } pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const global_5); - std::cell::LazyCell::force(&*&raw const selected_values_10); + std::cell::LazyCell::force(&*&raw const global_record_8); + std::cell::LazyCell::force(&*&raw const targets_10); + std::cell::LazyCell::force(&*&raw const cursor_11); + std::cell::LazyCell::force(&*&raw const selected_values_16); } From a70ffd728275aa1fa8e8568519ac709f8d1a52f4 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Thu, 26 Nov 2026 01:33:15 +0000 Subject: [PATCH 05/25] Avoid unnecessary assignment target bindings Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 65 ++- cpp2rust/converter/converter.h | 7 +- .../converter/models/converter_refcount.cpp | 26 +- .../converter/models/converter_refcount.h | 6 +- .../out/unsafe/p14-class-in-two-files.rs | 32 +- .../p15-class-template-static-member.rs | 32 +- .../out/unsafe/p15-function-template.rs | 32 +- .../out/unsafe/p15-inline-function.rs | 32 +- .../out/unsafe/p15-inline-variable.rs | 32 +- .../p16-default-argument-lambda-in-class.rs | 32 +- .../unsafe/p16-lambda-in-inline-function.rs | 32 +- .../out/unsafe/basic.scope.block.rs | 32 +- tests/std/basic/out/unsafe/basic.def.odr.rs | 32 +- .../stmt.select/out/unsafe/stmt.if.rs | 32 +- .../stmt.select/out/unsafe/stmt.switch.rs | 32 +- tests/unit/assignment_single_eval.cpp | 24 +- tests/unit/out/refcount/anonymous-struct.rs | 16 +- tests/unit/out/refcount/anonymous-struct_c.rs | 16 +- .../out/refcount/assignment_single_eval.rs | 158 ++++-- .../field_pointers_malloced_struct.rs | 8 +- tests/unit/out/refcount/map_key_copy_ctor.rs | 237 +++----- tests/unit/out/refcount/map_key_identity.rs | 534 ++++++------------ tests/unit/out/refcount/map_try_emplace.rs | 247 ++++---- tests/unit/out/refcount/va_arg_concat.rs | 8 +- tests/unit/out/refcount/va_arg_two_passes.rs | 16 +- .../out/refcount/vector_subscript_borrow.rs | 7 +- tests/unit/out/unsafe/anonymous-struct.rs | 16 +- tests/unit/out/unsafe/anonymous-struct_c.rs | 16 +- .../unit/out/unsafe/assignment_single_eval.rs | 168 ++++-- .../unsafe/field_pointers_malloced_struct.rs | 8 +- .../out/unsafe/global_call_temporaries.rs | 171 +++--- tests/unit/out/unsafe/map_key_copy_ctor.rs | 89 +-- tests/unit/out/unsafe/map_key_identity.rs | 279 ++------- tests/unit/out/unsafe/map_try_emplace.rs | 189 ++----- tests/unit/out/unsafe/swap_map_no_copy.rs | 19 +- tests/unit/out/unsafe/va_arg_concat.rs | 8 +- tests/unit/out/unsafe/va_arg_two_passes.rs | 16 +- .../out/unsafe/vector_subscript_borrow.rs | 6 +- 38 files changed, 1032 insertions(+), 1680 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index fa7f31646b..3d10776f0e 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -23,6 +23,7 @@ #include "converter/converter_lib.h" #include "converter/lex.h" #include "converter/mapper.h" +#include "converter/models/boxed_vars.h" #include "converter/printer.h" #include "converter/rules/registry.h" @@ -3073,7 +3074,7 @@ void Converter::ConvertBinaryOperator(clang::BinaryOperator *expr) { (isRValue() || IsUnsignedArithOp(expr) || GetUnsafeTypeAsString(lhs_type) != GetUnsafeTypeAsString(compound->getComputationResultType())) && - NeedsAssignmentBinding(lhs, rhs)) { + NeedsAssignmentBinding(lhs, rhs, compound)) { ConvertAssignment(lhs, rhs, opcode_as_string, compound); } else if (compound && GetUnsafeTypeAsString(lhs_type) != @@ -4969,21 +4970,63 @@ void Converter::ConvertArraySubscript(clang::Expr *base, clang::Expr *idx, } } -bool Converter::NeedsAssignmentBinding(const clang::Expr *lhs, - const clang::Expr *rhs) const { - if (lhs->HasSideEffects(ctx_) || rhs->HasSideEffects(ctx_)) { +bool Converter::NeedsAssignmentBinding( + const clang::Expr *lhs, const clang::Expr *rhs, + const clang::CompoundAssignOperator *compound) { + const auto *target = lhs->IgnoreParenImpCasts(); + const auto *ref = clang::dyn_cast(target); + const auto *var = + ref ? clang::dyn_cast(ref->getDecl()) : nullptr; + bool rhs_effects = rhs->HasSideEffects(ctx_); + if (var && !var->isImplicit()) { + // A variable's storage never changes. Only compound assignments can read + // its old value too early, before an effectful right operand changes it. + if (!compound || + (!IsUnsignedArithOp(compound) && !lhs->getType()->isPointerType() && + ctx_.hasSameUnqualifiedType(lhs->getType(), + compound->getComputationResultType()))) { + return false; + } + if (!rhs_effects) { + return false; + } + if (!GetAllVars(rhs).contains(var)) { + if (!boxed_vars_) { + boxed_vars_ = std::make_shared(ctx_); + } + if (!boxed_vars_->contains(var)) { + return false; + } + } return true; } - if (!isRValue()) { - return false; + if (!rhs_effects) { + if (const auto *member = clang::dyn_cast(target)) { + const auto *base = clang::dyn_cast( + member->getBase()->IgnoreParenImpCasts()); + const auto *object = + base ? clang::dyn_cast(base->getDecl()) : nullptr; + if (object && !object->isImplicit() && + (!member->isArrow() || !object->getType()->isReferenceType()) && + !lhs->HasSideEffects(ctx_)) { + return false; + } + } + // The standard flat-vector subscript is a call in the AST, but a constant + // index and an effect-free receiver keep selecting the same element. + if (const auto *call = clang::dyn_cast(target); + call && call->getOperator() == clang::OO_Subscript && + GetEnclosingObject(call) && !call->getArg(0)->HasSideEffects(ctx_) && + call->getArg(1)->isIntegerConstantExpr(ctx_)) { + return false; + } + } + if (lhs->HasSideEffects(ctx_) || rhs_effects) { + return true; } // A store can change which element a composite target selects. Implicit // variables and structured bindings can expand to such targets too. - const auto *ref = - clang::dyn_cast(lhs->IgnoreParenImpCasts()); - const auto *var = - ref ? clang::dyn_cast(ref->getDecl()) : nullptr; - return !var || var->isImplicit(); + return isRValue(); } void Converter::ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 4762d9001a..983b010078 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -27,6 +27,7 @@ #include "logging.h" namespace cpp2rust { +class BoxedVars; inline constexpr const char kDestructorName[] = "destructor"; // Sets var to value while in scope. @@ -794,8 +795,9 @@ class Converter : public clang::RecursiveASTVisitor { void EmitFlexibleArrayElementPtr(clang::Expr *array, clang::Expr *idx, bool is_mut); - bool NeedsAssignmentBinding(const clang::Expr *lhs, - const clang::Expr *rhs) const; + bool NeedsAssignmentBinding( + const clang::Expr *lhs, const clang::Expr *rhs, + const clang::CompoundAssignOperator *compound = nullptr); virtual void ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, std::string_view assign_operator, @@ -1050,6 +1052,7 @@ class Converter : public clang::RecursiveASTVisitor { std::string *rs_code_; clang::ASTContext &ctx_; + std::shared_ptr boxed_vars_; std::unique_ptr mangle_context_; clang::FunctionDecl *curr_function_ = nullptr; clang::Expr *return_value_ = nullptr; diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 55df746737..d2468bd469 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -37,8 +37,10 @@ ConverterRefCount::ConverterRefCount(std::string &rs_code, ConverterRefCount::ConverterRefCount( std::string &rs_code, clang::ASTContext &ctx, std::shared_ptr boxed_vars) - : Converter(rs_code, ctx, "", ""), boxed_vars_(std::move(boxed_vars)), - conversion_kind_({ConversionKind::Unboxed}) {} + : Converter(rs_code, ctx, "", ""), + conversion_kind_({ConversionKind::Unboxed}) { + boxed_vars_ = std::move(boxed_vars); +} void ConverterRefCount::EmitFilePreamble() { StrCat(R"( @@ -1596,7 +1598,7 @@ void ConverterRefCount::ConvertBinaryOperator(clang::BinaryOperator *expr) { (isRValue() || IsUnsignedArithOp(expr) || GetSafeTypeAsString(lhs_type) != GetSafeTypeAsString(compound->getComputationResultType())) && - NeedsAssignmentBinding(lhs, rhs)) { + NeedsAssignmentBinding(lhs, rhs, compound)) { ConvertAssignment(lhs, rhs, opcode_as_string, compound); return; } @@ -1604,7 +1606,7 @@ void ConverterRefCount::ConvertBinaryOperator(clang::BinaryOperator *expr) { if (compound && GetSafeTypeAsString(lhs_type) != GetSafeTypeAsString(compound->getComputationResultType())) { - EmitCompoundSetOrAssign(lhs, ConvertCompoundAssignValue(compound)); + EmitCompoundSetOrAssign(lhs, rhs, ConvertCompoundAssignValue(compound)); return; } @@ -1625,7 +1627,7 @@ void ConverterRefCount::ConvertBinaryOperator(clang::BinaryOperator *expr) { if (compound) { auto value = std::move(*buf).str(); buf.reset(); - EmitCompoundSetOrAssign(lhs, value); + EmitCompoundSetOrAssign(lhs, rhs, value); } else { MarkFresh(); } @@ -2447,9 +2449,16 @@ bool ConverterRefCount::CanBraceAssignedValue( } void ConverterRefCount::EmitCompoundSetOrAssign(clang::Expr *lhs, + clang::Expr *rhs, std::string_view value) { - PushBrace brace(*this, isRValue()); - EmitSetOrAssign(lhs, std::format("{{ {} }}", value)); + bool can_brace = CanBraceAssignedValue(lhs, rhs, "="); + PushBrace brace(*this, isRValue() || !can_brace); + if (can_brace) { + EmitSetOrAssign(lhs, std::format("{{ {} }}", value)); + } else { + StrCat(keyword::kLet, "rhs_0", token::kAssign, value, token::kSemiColon); + EmitSetOrAssign(lhs, "rhs_0"); + } if (isRValue()) { StrCat(token::kSemiColon, ConvertFreshRValue(lhs)); } @@ -2477,7 +2486,8 @@ void ConverterRefCount::ConvertAssignment( MarkFresh(); } else { EmitCompoundSetOrAssign( - lhs, ConvertCompoundAssignValue(compound, ConvertRValue(lhs), right)); + lhs, rhs, + ConvertCompoundAssignValue(compound, ConvertRValue(lhs), right)); } return; } diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 6473eafdf0..f3f691ca8b 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -458,7 +458,10 @@ class ConverterRefCount final : public Converter { bool CanBraceAssignedValue(clang::Expr *lhs, clang::Expr *rhs, std::string_view assign_operator); - void EmitCompoundSetOrAssign(clang::Expr *lhs, std::string_view value); + // Emits `lhs = value`, where value is the result of the compound assignment + // `lhs op= rhs` and thus reads lhs. + void EmitCompoundSetOrAssign(clang::Expr *lhs, clang::Expr *rhs, + std::string_view value); // If lhs is a direct reference to a global/static value (not a reference // type), emits `var.with(|rc| *rc.borrow_mut() )` and returns @@ -580,7 +583,6 @@ class ConverterRefCount final : public Converter { // Whether expr is a field of an unboxed variable, or of a field of one, // which is stored in place, even if it is a reference. bool IsFieldOfUnboxedPlace(const clang::MemberExpr *expr) const; - std::shared_ptr boxed_vars_; // Set when a constructor's translation refers to `this`, which then needs // the object being built to be in a Value. diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs index 7ee1db2acd..5309797a65 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs @@ -17,29 +17,15 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( - { - match ( - { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } pub unsafe fn new() -> Self { diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs index c91a55f672..f366dd2b83 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs @@ -17,29 +17,15 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( - { - match ( - { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } pub unsafe fn new() -> Self { diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs index 620fba257b..e822da1ad5 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs @@ -17,29 +17,15 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( - { - match ( - { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } pub unsafe fn new() -> Self { diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs index f4bc9820bf..d71518db48 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs @@ -17,29 +17,15 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( - { - match ( - { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } pub unsafe fn new() -> Self { diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs index f0ed2b87b3..c7006c1478 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs @@ -17,29 +17,15 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( - { - match ( - { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } pub unsafe fn new() -> Self { diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs index 56185caae2..ad5d698cef 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs @@ -17,29 +17,15 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( - { - match ( - { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } pub unsafe fn new() -> Self { diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs index bb26c62ce3..fe1766c880 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs @@ -17,29 +17,15 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( - { - match ( - { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } pub unsafe fn new() -> Self { diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs index cdd526036f..cfaf288d6e 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs @@ -17,29 +17,15 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( - { - match ( - { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } pub unsafe fn new() -> Self { diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index ebfdb3e81f..d482309b05 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -47,29 +47,15 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)) = match ( - { - match ( - { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) }; } pub unsafe fn new() -> Self { diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs index 3afc1310e7..fd22be5aba 100644 --- a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs @@ -17,29 +17,15 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( - { - match ( - { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } pub unsafe fn new() -> Self { diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs index 94d41e22f4..177fa848ed 100644 --- a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs @@ -17,29 +17,15 @@ pub struct LifetimeTracked { } impl LifetimeTracked { pub unsafe fn reset() { - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = match ( - { - match ( - { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } pub unsafe fn new() -> Self { diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index c8f2b3f1c3..0b615b7fc4 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -57,9 +57,13 @@ int global = 10; int observe_global(int assigned) { return assigned + global; } int observe(int assigned, const int *stored) { return assigned + *stored; } struct GlobalRecord { - int value; -} global_record{10}; -int observe_record(int assigned) { return assigned + global_record.value; } + struct Inner { + int value; + } inner; +} global_record{{10}}; +int observe_record(int assigned) { + return assigned + global_record.inner.value; +} int targets[2] = {10, 20}; int *cursor = targets; @@ -70,10 +74,14 @@ void test_borrows() { static short promoted = 10; int assigned = (promoted += (promoted = -1, 0.5)); std::printf("%d %d\n", assigned, int(promoted)); + short aliased = 10; + short *alias = &aliased; + assigned = (aliased += (*alias = -1, 0.5)); + std::printf("%d %d\n", assigned, int(aliased)); static bool flag = false; bool enabled = (flag += (observe(0, &global), 0.5)); std::printf("%d %d\n", int(enabled), int(flag)); - std::printf("%d\n", observe_record(global_record.value = 99)); + std::printf("%d\n", observe_record(global_record.inner.value = 99)); int *shifted = (cursor -= (cursor = targets + 1, 1)); std::printf("%d %d\n", cursor == targets, shifted == cursor); @@ -88,6 +96,14 @@ void test_borrows() { std::printf("%d\n", observe(record.value = 99, &record.value)); std::printf("%d\n", observe(record.value += 5, &record.value)); + struct Link { + Link *next; + }; + Link first{&first}, second{&first}; + Link *&selector = first.next; + Link *selected = (selector->next = &second); + std::printf("%d %d\n", selected == &second, first.next == &second); + std::vector values(1, 10); std::printf("%d\n", observe(values[0] = 99, &values[0])); std::printf("%d\n", observe(values[0] += 5, &values[0])); diff --git a/tests/unit/out/refcount/anonymous-struct.rs b/tests/unit/out/refcount/anonymous-struct.rs index bc685c12df..d8b0921f4d 100644 --- a/tests/unit/out/refcount/anonymous-struct.rs +++ b/tests/unit/out/refcount/anonymous-struct.rs @@ -114,22 +114,14 @@ fn main_0() -> i32 { s.z = 2; assert!( ({ - match ({ 1 }, &mut (s.x)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } - } + s.x = 1; + s.x } != 0) ); assert!( ({ - match ({ 2 }, &mut (s.z)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } + s.z = 2; + s.z } != 0) ); return 0; diff --git a/tests/unit/out/refcount/anonymous-struct_c.rs b/tests/unit/out/refcount/anonymous-struct_c.rs index b6ba504c05..c903903369 100644 --- a/tests/unit/out/refcount/anonymous-struct_c.rs +++ b/tests/unit/out/refcount/anonymous-struct_c.rs @@ -120,22 +120,14 @@ fn main_0() -> i32 { s.z = 2; assert!( ({ - match ({ 1 }, &mut (s.x)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } - } + s.x = 1; + s.x } != 0) ); assert!( ({ - match ({ 2 }, &mut (s.z)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } + s.z = 2; + s.z } != 0) ); return 0; diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 4a3600abbe..239607dd9e 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -550,16 +550,24 @@ pub fn observe_7(mut assigned: i32, mut stored: Ptr) -> i32 { } #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(4)] -pub struct GlobalRecord { +pub struct GlobalRecord_Inner { #[offset(0)] pub value: i32, } +#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(4)] +pub struct GlobalRecord { + #[offset(0)] + #[byte_size(4)] + pub inner: GlobalRecord_Inner, +} thread_local!( - pub static global_record_8: Value = - Rc::new(RefCell::new(GlobalRecord { value: 10 })); + pub static global_record_8: Value = Rc::new(RefCell::new(GlobalRecord { + inner: GlobalRecord_Inner { value: 10 }, + })); ); pub fn observe_record_9(mut assigned: i32) -> i32 { - return (assigned + { global_record_8.with(|rc| *rc.borrow()).value }); + return (assigned + { global_record_8.with(|rc| *rc.borrow()).inner.value }); } thread_local!( pub static targets_10: Value> = Rc::new(RefCell::new(Box::new([10, 20]))); @@ -602,10 +610,8 @@ pub fn test_borrows_12() { 0.5_f64 }; { - promoted_13.with(|rc| { - *rc.borrow_mut() = - { ((promoted_13.with(|rc| *rc.borrow()) as f64) + (__tmp_56 as f64)) as i16 } - }); + let rhs_0 = ((promoted_13.with(|rc| *rc.borrow()) as f64) + (__tmp_56 as f64)) as i16; + promoted_13.with(|rc| *rc.borrow_mut() = rhs_0); promoted_13.with(|rc| *rc.borrow()) } }) as i32); @@ -614,16 +620,33 @@ pub fn test_borrows_12() { assigned, (promoted_13.with(|rc| *rc.borrow()) as i32) ); + let aliased: Value = Rc::new(RefCell::new(10_i16)); + let mut alias: Ptr = (aliased.as_pointer()); + assigned = (({ + match ( + { + { + alias.write((-1_i32 as i16)); + 0.5_f64 + } + }, + &mut (*aliased.borrow_mut()), + ) { + (__tmp_57, __tmp_58) => { + (*__tmp_58) = (((*__tmp_58) as f64) + (__tmp_57 as f64)) as i16; + (*__tmp_58).clone() + } + } + }) as i32); + printf!(b"%d %d\n", assigned, ((*aliased.borrow()) as i32)); let mut enabled: bool = ({ - let __tmp_57 = { + let __tmp_59 = { ({ observe_7(0, (global_5.with(|v| v.as_pointer()))) }); 0.5_f64 }; { - flag_14.with(|rc| { - *rc.borrow_mut() = - { ((flag_14.with(|rc| *rc.borrow()) as u8 as f64) + (__tmp_57 as f64)) != 0.0 } - }); + let rhs_0 = ((flag_14.with(|rc| *rc.borrow()) as u8 as f64) + (__tmp_59 as f64)) != 0.0; + flag_14.with(|rc| *rc.borrow_mut() = rhs_0); flag_14.with(|rc| *rc.borrow()) } }); @@ -638,23 +661,25 @@ pub fn test_borrows_12() { observe_record_9({ match ( { 99 }, - &mut ((*global_record_8.with(Value::clone).borrow_mut()).value), + &mut ((*global_record_8.with(Value::clone).borrow_mut()) + .inner + .value), ) { - (__tmp_58, __tmp_59) => { - (*__tmp_59) = __tmp_58; - (*__tmp_59).clone() + (__tmp_60, __tmp_61) => { + (*__tmp_61) = __tmp_60; + (*__tmp_61).clone() } } }) }) ); let mut shifted: Ptr = ({ - let __tmp_60 = { + let __tmp_62 = { cursor_11 .with(|rc| *rc.borrow_mut() = targets_10.with(|v| v.decay()).offset((1) as isize)); 1 }; - cursor_11.with(|rc| *rc.borrow_mut() -= (__tmp_60 as isize)); + cursor_11.with(|rc| *rc.borrow_mut() -= (__tmp_62 as isize)); (*cursor_11.with(Value::clone).borrow()).clone() }); printf!( @@ -692,12 +717,8 @@ pub fn test_borrows_12() { b"%d\n", ({ let _assigned: i32 = { - match ({ 99 }, &mut ((*record.borrow_mut()).value)) { - (__tmp_61, __tmp_62) => { - (*__tmp_62) = __tmp_61; - (*__tmp_62).clone() - } - } + (*record.borrow_mut()).value = 99; + { (*record.borrow()).value } }; let _stored: Ptr = (field_ptr!(record.as_pointer(), value)); observe_7(_assigned, _stored) @@ -707,28 +728,44 @@ pub fn test_borrows_12() { b"%d\n", ({ let _assigned: i32 = { - match ({ 5 }, &mut ((*record.borrow_mut()).value)) { - (__tmp_63, __tmp_64) => { - (*__tmp_64) = (((*__tmp_64) as i32) + (__tmp_63 as i32)) as i32; - (*__tmp_64).clone() - } - } + (*record.borrow_mut()).value += 5; + { (*record.borrow()).value } }; let _stored: Ptr = (field_ptr!(record.as_pointer(), value)); observe_7(_assigned, _stored) }) ); + let first: Value = >::default(); + *first.borrow_mut() = Link_16 { + next: (first.as_pointer()), + }; + let second: Value = Rc::new(RefCell::new(Link_16 { + next: (first.as_pointer()), + })); + let selector: Ptr> = field_ptr!(first.as_pointer(), next); + let mut selected: Ptr = ({ + match ( + { (second.as_pointer()) }, + &(field!((selector.read()), next)), + ) { + (__tmp_63, __tmp_64) => __tmp_64.with_mut(|__tmp_64| { + (*__tmp_64) = __tmp_63; + (*__tmp_64).clone() + }), + } + }); + printf!( + b"%d %d\n", + (({ (selected).clone() } == { (second.as_pointer()) }) as i32), + (({ { (*first.borrow()).next.clone() } } == { (second.as_pointer()) }) as i32) + ); let values: Value> = Rc::new(RefCell::new(vec![10; 1_usize])); printf!( b"%d\n", ({ let _assigned: i32 = { - match ({ 99 }, &mut ((*values.borrow_mut())[0_usize])) { - (__tmp_65, __tmp_66) => { - (*__tmp_66) = __tmp_65; - (*__tmp_66).clone() - } - } + (*values.borrow_mut())[0_usize] = 99; + { (*values.borrow())[0_usize] } }; let _stored: Ptr = (values.decay().offset(0_usize)); observe_7(_assigned, _stored) @@ -738,12 +775,8 @@ pub fn test_borrows_12() { b"%d\n", ({ let _assigned: i32 = { - match ({ 5 }, &mut ((*values.borrow_mut())[0_usize])) { - (__tmp_67, __tmp_68) => { - (*__tmp_68) = (((*__tmp_68) as i32) + (__tmp_67 as i32)) as i32; - (*__tmp_68).clone() - } - } + (*values.borrow_mut())[0_usize] += 5; + { (*values.borrow())[0_usize] } }; let _stored: Ptr = (values.decay().offset(0_usize)); observe_7(_assigned, _stored) @@ -762,22 +795,29 @@ pub struct Record_15 { #[offset(0)] pub value: i32, } +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct Link_16 { + #[offset(0)] + #[byte_size(8)] + pub next: Ptr, +} thread_local!( - pub static selected_values_16: Value> = + pub static selected_values_17: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); ); #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct IndexedBinding {} -pub fn test_binding_17() { +pub fn test_binding_18() { let owner: Value = Rc::new(RefCell::new(::default())); - let __decomp_18: Ptr = owner.as_pointer(); - let value: Ptr = ({ IndexedBindingImpl::get_1_0(&__decomp_18) }); + let __decomp_19: Ptr = owner.as_pointer(); + let value: Ptr = ({ IndexedBindingImpl::get_1_0(&__decomp_19) }); let mut result: u32 = ({ - match ({ 1_u32 }, &({ IndexedBindingImpl::get_1_0(&__decomp_18) })) { - (__tmp_69, __tmp_70) => __tmp_70.with_mut(|__tmp_70| { - (*__tmp_70) = (((*__tmp_70) as u32).wrapping_add((__tmp_69 as u32))) as u32; - (*__tmp_70).clone() + match ({ 1_u32 }, &({ IndexedBindingImpl::get_1_0(&__decomp_19) })) { + (__tmp_65, __tmp_66) => __tmp_66.with_mut(|__tmp_66| { + (*__tmp_66) = (((*__tmp_66) as u32).wrapping_add((__tmp_65 as u32))) as u32; + (*__tmp_66).clone() }), } }); @@ -786,7 +826,7 @@ pub fn test_binding_17() { result, ({ let __idx0 = (0) as usize; - selected_values_16.with(|rc| rc.borrow()[__idx0]) + selected_values_17.with(|rc| rc.borrow()[__idx0]) }) ); } @@ -814,9 +854,9 @@ fn main_0() -> i32 { 0 )), ) { - (__tmp_71, __tmp_72) => __tmp_72.with_mut(|__tmp_72| { - (*__tmp_72) = (((*__tmp_72) as u32).wrapping_add((__tmp_71 as u32))) as u32; - (*__tmp_72).clone() + (__tmp_67, __tmp_68) => __tmp_68.with_mut(|__tmp_68| { + (*__tmp_68) = (((*__tmp_68) as u32).wrapping_add((__tmp_67 as u32))) as u32; + (*__tmp_68).clone() }), } }); @@ -827,7 +867,7 @@ fn main_0() -> i32 { (*values.borrow())[(0) as usize] ); ({ test_borrows_12() }); - ({ test_binding_17() }); + ({ test_binding_18() }); return 0; } pub trait IndexedBindingImpl { @@ -835,10 +875,10 @@ pub trait IndexedBindingImpl { } impl IndexedBindingImpl for Ptr { fn get_1_0(&self) -> Ptr { - return selected_values_16.with(|v| v.decay()).offset( + return selected_values_17.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; - selected_values_16.with(|rc| rc.borrow()[__idx0]) + selected_values_17.with(|rc| rc.borrow()[__idx0]) }), ); } @@ -848,5 +888,5 @@ pub fn __cpp2rust_init_globals() { let _ = global_record_8.with(|_| ()); let _ = targets_10.with(|_| ()); let _ = cursor_11.with(|_| ()); - let _ = selected_values_16.with(|_| ()); + let _ = selected_values_17.with(|_| ()); } diff --git a/tests/unit/out/refcount/field_pointers_malloced_struct.rs b/tests/unit/out/refcount/field_pointers_malloced_struct.rs index cbb5987840..dc4b1b0639 100644 --- a/tests/unit/out/refcount/field_pointers_malloced_struct.rs +++ b/tests/unit/out/refcount/field_pointers_malloced_struct.rs @@ -51,12 +51,8 @@ fn main_0() -> i32 { assert!((s.with(|__s| __s.a) == 5) && (s.with(|__s| __s.c) == 1)); let mut x: i32 = ({ s.with(|__s| __s.a) } + { ({ - match ({ 3 }, &(field!(s, b))) { - (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - }), - } + field!(s, b).write(3); + s.with(|__s| __s.b) }) }); assert!((x == 8) && (s.with(|__s| __s.b) == 3)); diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index 6942bd5626..2e7f91d5b6 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -88,56 +88,44 @@ fn main_0() -> i32 { .write(11); ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; { - match ( - { - (((*(*m - .as_pointer() - .with(|__m: &Map, Value)>| __m.find(&a.as_pointer())) - .iter_deref() - .upgrade() - .deref()) - .1 - .borrow()) - == 11) as i32) - }, - &mut (ok), - ) { - (__tmp_3, __tmp_4) => { - (*__tmp_4) = (((*__tmp_4) as i32) & (__tmp_3 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (((*(*m + .as_pointer() + .with(|__m: &Map, Value)>| __m.find(&a.as_pointer())) + .iter_deref() + .upgrade() + .deref()) + .1 + .borrow()) + == 11) as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - (((({ - (*m.borrow()) - .get(&b.as_pointer()) - .expect("out of range!") - .borrow() - .1 - .as_pointer() - }) - .read()) - == 20) as i32) - }, - &mut (ok), - ) { - (__tmp_5, __tmp_6) => { - (*__tmp_6) = (((*__tmp_6) as i32) & (__tmp_5 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (((({ + (*m.borrow()) + .get(&b.as_pointer()) + .expect("out of range!") + .borrow() + .1 + .as_pointer() + }) + .read()) + == 20) as i32)) + != 0; + ok = rhs_0 }; ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; match (Rc::new(RefCell::new(({ make_key_3(4) }))).as_pointer(),) { - (__tmp_7,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_7, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_3,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_3, |__k| cpp_move!(__k), || 0_i32) }) } } .write(40); match (Rc::new(RefCell::new(({ make_key_3(4) }))).as_pointer(),) { - (__tmp_8,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_8, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_4,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_4, |__k| cpp_move!(__k), || 0_i32) }) } } .write(41); @@ -148,14 +136,14 @@ fn main_0() -> i32 { != 0 }; match (c.as_pointer(),) { - (__tmp_9,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_9, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_5,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_5, |__k| cpp_move!(__k), || 0_i32) }) } } .write(30); match (c.as_pointer(),) { - (__tmp_10,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_10, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_6,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_6, |__k| cpp_move!(__k), || 0_i32) }) } } .write(31); @@ -166,11 +154,8 @@ fn main_0() -> i32 { != 0 }; { - match ({ (((*m.borrow()).len() == 4_usize) as i32) }, &mut (ok)) { - (__tmp_11, __tmp_12) => { - (*__tmp_12) = (((*__tmp_12) as i32) & (__tmp_11 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) & (((*m.borrow()).len() == 4_usize) as i32)) != 0; + ok = rhs_0 }; { match ((*m @@ -182,26 +167,20 @@ fn main_0() -> i32 { .0 .as_pointer(),) { - (__tmp_13,) => ({ (*m.borrow_mut()).subscript(__tmp_13, || 0_i32) }), + (__tmp_7,) => ({ (*m.borrow_mut()).subscript(__tmp_7, || 0_i32) }), } .with_mut(|__v| *__v = *__v + 1) }; { - match ( - { - (((copies_0.with(|rc| *rc.borrow()) == 2) - && ((match (a.as_pointer(),) { - (__tmp_16,) => ({ (*m.borrow_mut()).subscript(__tmp_16, || 0_i32) }), - } - .read()) - == 12)) as i32) - }, - &mut (ok), - ) { - (__tmp_14, __tmp_15) => { - (*__tmp_15) = (((*__tmp_15) as i32) & (__tmp_14 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (((copies_0.with(|rc| *rc.borrow()) == 2) + && ((match (a.as_pointer(),) { + (__tmp_8,) => ({ (*m.borrow_mut()).subscript(__tmp_8, || 0_i32) }), + } + .read()) + == 12)) as i32)) + != 0; + ok = rhs_0 }; let mut first: Ptr = ((*m .as_pointer() @@ -212,50 +191,38 @@ fn main_0() -> i32 { .0 .as_pointer()); match (Rc::new(RefCell::new(Key::new({ 0 }))).as_pointer(),) { - (__tmp_17,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_17, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_9,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_9, |__k| cpp_move!(__k), || 0_i32) }) } } .write(0); ok = { ((ok as i32) & ((moves_1.with(|rc| *rc.borrow()) == 3) as i32)) != 0 }; { - match ( - { - (({ - ((*m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&a.as_pointer())) - .iter_deref() - .upgrade() - .deref()) - .0 - .as_pointer()) - } == { (first).clone() }) as i32) - }, - &mut (ok), - ) { - (__tmp_18, __tmp_19) => { - (*__tmp_19) = (((*__tmp_19) as i32) & (__tmp_18 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (({ + ((*m.as_pointer() + .with(|__m: &Map, Value)>| __m.find(&a.as_pointer())) + .iter_deref() + .upgrade() + .deref()) + .0 + .as_pointer()) + } == { (first).clone() }) as i32)) + != 0; + ok = rhs_0 }; let n: Value, Value)>> = Rc::new(RefCell::new((*m.borrow()).clone())); ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == (2 + 5)) as i32)) != 0 }; { - match ( - { - ((((*n.borrow()).len() == 5_usize) - && ((match (a.as_pointer(),) { - (__tmp_22,) => ({ (*n.borrow_mut()).subscript(__tmp_22, || 0_i32) }), - } - .read()) - == 12)) as i32) - }, - &mut (ok), - ) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = (((*__tmp_21) as i32) & (__tmp_20 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & ((((*n.borrow()).len() == 5_usize) + && ((match (a.as_pointer(),) { + (__tmp_10,) => ({ (*n.borrow_mut()).subscript(__tmp_10, || 0_i32) }), + } + .read()) + == 12)) as i32)) + != 0; + ok = rhs_0 }; Map::erase( m.as_pointer(), @@ -263,45 +230,31 @@ fn main_0() -> i32 { .with(|__m: &Map, Value)>| __m.find(&a.as_pointer())), ); { - match ( - { ((Map::erase_key(m.as_pointer(), &b.as_pointer()) == 1_usize) as i32) }, - &mut (ok), - ) { - (__tmp_23, __tmp_24) => { - (*__tmp_24) = (((*__tmp_24) as i32) & (__tmp_23 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & ((Map::erase_key(m.as_pointer(), &b.as_pointer()) == 1_usize) as i32)) + != 0; + ok = rhs_0 }; { - match ( - { ((Map::erase_key(m.as_pointer(), &b.as_pointer()) == 0_usize) as i32) }, - &mut (ok), - ) { - (__tmp_25, __tmp_26) => { - (*__tmp_26) = (((*__tmp_26) as i32) & (__tmp_25 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & ((Map::erase_key(m.as_pointer(), &b.as_pointer()) == 0_usize) as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - ((Map::erase_key( - m.as_pointer(), - &(*m.as_pointer() - .with(|__m: &Map, Value)>| __m.begin()) - .iter_deref() - .upgrade() - .deref()) - .0 - .as_pointer(), - ) == 1_usize) as i32) - }, - &mut (ok), - ) { - (__tmp_27, __tmp_28) => { - (*__tmp_28) = (((*__tmp_28) as i32) & (__tmp_27 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & ((Map::erase_key( + m.as_pointer(), + &(*m.as_pointer() + .with(|__m: &Map, Value)>| __m.begin()) + .iter_deref() + .upgrade() + .deref()) + .0 + .as_pointer(), + ) == 1_usize) as i32)) + != 0; + ok = rhs_0 }; ok = { ((ok as i32) @@ -310,14 +263,10 @@ fn main_0() -> i32 { != 0 }; { - match ( - { ((((*m.borrow()).len() == 2_usize) && ((*n.borrow()).len() == 5_usize)) as i32) }, - &mut (ok), - ) { - (__tmp_29, __tmp_30) => { - (*__tmp_30) = (((*__tmp_30) as i32) & (__tmp_29 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & ((((*m.borrow()).len() == 2_usize) && ((*n.borrow()).len() == 5_usize)) as i32)) + != 0; + ok = rhs_0 }; let mut sum: i32 = 0; 'loop_: for entry in IterRange::new( diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index 5cd38120b9..8d9695dd17 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -66,19 +66,13 @@ fn main_0() -> i32 { identity: 7, })); { - match ( - { - (({ - let _a: Ptr = distinct_a.as_pointer(); - operator_eq_2(_a, distinct_b.as_pointer()) - }) as i32) - }, - &mut (ok), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as i32) & (__tmp_0 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (({ + let _a: Ptr = distinct_a.as_pointer(); + operator_eq_2(_a, distinct_b.as_pointer()) + }) as i32)) + != 0; + ok = rhs_0 }; let distinct: Value, Value)>> = Rc::new(RefCell::new(Map::new())); let a: Ptr = @@ -101,14 +95,8 @@ fn main_0() -> i32 { ))); ok = { ((ok as i32) & ((default_constructions_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; { - match ( - { (((*distinct.borrow()).len() == 2_usize) as i32) }, - &mut (ok), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = (((*__tmp_3) as i32) & (__tmp_2 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) & (((*distinct.borrow()).len() == 2_usize) as i32)) != 0; + ok = rhs_0 }; ok = { ((ok as i32) & (({ (a).clone() } != { (b).clone() }) as i32)) != 0 }; ok = { @@ -117,98 +105,62 @@ fn main_0() -> i32 { != 0 }; { - match ( - { - (((*a_it.borrow()) - == distinct - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&distinct_a.as_pointer()) - })) as i32) - }, - &mut (ok), - ) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (((*a_it.borrow()) + == distinct + .as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&distinct_a.as_pointer()) + })) as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - (((*b_it.borrow()) - == distinct - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&distinct_b.as_pointer()) - })) as i32) - }, - &mut (ok), - ) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as i32) & (__tmp_6 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (((*b_it.borrow()) + == distinct + .as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&distinct_b.as_pointer()) + })) as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - (((*b_it.borrow()) - != distinct - .as_pointer() - .with(|__m: &Map, Value)>| __m.end())) - as i32) - }, - &mut (ok), - ) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as i32) & (__tmp_8 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (((*b_it.borrow()) + != distinct + .as_pointer() + .with(|__m: &Map, Value)>| __m.end())) + as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - (({ - ((*({ (*a_it.borrow()).iter_deref() }).upgrade().deref()) - .1 - .as_pointer()) - } == { (a_value).clone() }) as i32) - }, - &mut (ok), - ) { - (__tmp_10, __tmp_11) => { - (*__tmp_11) = (((*__tmp_11) as i32) & (__tmp_10 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (({ + ((*({ (*a_it.borrow()).iter_deref() }).upgrade().deref()) + .1 + .as_pointer()) + } == { (a_value).clone() }) as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - ((({ (*a_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) == 11) - as i32) - }, - &mut (ok), - ) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = (((*__tmp_13) as i32) & (__tmp_12 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & ((({ (*a_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) == 11) + as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - (({ - let _a: Ptr = distinct_a.as_pointer(); - operator_eq_2(_a, distinct_b.as_pointer()) - }) as i32) - }, - &mut (ok), - ) { - (__tmp_14, __tmp_15) => { - (*__tmp_15) = (((*__tmp_15) as i32) & (__tmp_14 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (({ + let _a: Ptr = distinct_a.as_pointer(); + operator_eq_2(_a, distinct_b.as_pointer()) + }) as i32)) + != 0; + ok = rhs_0 }; let mut distinct_count: usize = 0_usize; 'loop_: for entry in IterRange::new( @@ -249,19 +201,13 @@ fn main_0() -> i32 { identity: 9, })); { - match ( - { - (!({ - let _a: Ptr = equivalent_a.as_pointer(); - operator_eq_2(_a, equivalent_b.as_pointer()) - }) as i32) - }, - &mut (ok), - ) { - (__tmp_16, __tmp_17) => { - (*__tmp_17) = (((*__tmp_17) as i32) & (__tmp_16 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (!({ + let _a: Ptr = equivalent_a.as_pointer(); + operator_eq_2(_a, equivalent_b.as_pointer()) + }) as i32)) + != 0; + ok = rhs_0 }; let equivalent: Value, Value)>> = Rc::new(RefCell::new(Map::new())); @@ -290,96 +236,60 @@ fn main_0() -> i32 { (default_constructions_0.with(|rc| *rc.borrow()) == (before_equivalent + 1)); ok = { ((ok as i32) & (reused as i32)) != 0 }; { - match ( - { (((*equivalent.borrow()).len() == 1_usize) as i32) }, - &mut (ok), - ) { - (__tmp_18, __tmp_19) => { - (*__tmp_19) = (((*__tmp_19) as i32) & (__tmp_18 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) & (((*equivalent.borrow()).len() == 1_usize) as i32)) != 0; + ok = rhs_0 }; if reused { { - match ( - { - (((*first_it.borrow()) - != equivalent - .as_pointer() - .with(|__m: &Map, Value)>| __m.end())) - as i32) - }, - &mut (ok), - ) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = (((*__tmp_21) as i32) & (__tmp_20 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (((*first_it.borrow()) + != equivalent + .as_pointer() + .with(|__m: &Map, Value)>| __m.end())) + as i32)) + != 0; + ok = rhs_0 }; ok = { ((ok as i32) & (({ (first).clone() } == { (second).clone() }) as i32)) != 0 }; { - match ( - { - (((*first_it.borrow()) - == equivalent.as_pointer().with( - |__m: &Map, Value)>| { - __m.find(&equivalent_a.as_pointer()) - }, - )) as i32) - }, - &mut (ok), - ) { - (__tmp_22, __tmp_23) => { - (*__tmp_23) = (((*__tmp_23) as i32) & (__tmp_22 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (((*first_it.borrow()) + == equivalent.as_pointer().with( + |__m: &Map, Value)>| { + __m.find(&equivalent_a.as_pointer()) + }, + )) as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - (((*first_it.borrow()) - == equivalent.as_pointer().with( - |__m: &Map, Value)>| { - __m.find(&equivalent_b.as_pointer()) - }, - )) as i32) - }, - &mut (ok), - ) { - (__tmp_24, __tmp_25) => { - (*__tmp_25) = (((*__tmp_25) as i32) & (__tmp_24 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (((*first_it.borrow()) + == equivalent.as_pointer().with( + |__m: &Map, Value)>| { + __m.find(&equivalent_b.as_pointer()) + }, + )) as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - (({ - ((*({ (*first_it.borrow()).iter_deref() }).upgrade().deref()) - .1 - .as_pointer()) - } == { (first_value).clone() }) as i32) - }, - &mut (ok), - ) { - (__tmp_26, __tmp_27) => { - (*__tmp_27) = (((*__tmp_27) as i32) & (__tmp_26 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (({ + ((*({ (*first_it.borrow()).iter_deref() }).upgrade().deref()) + .1 + .as_pointer()) + } == { (first_value).clone() }) as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - (((({ (*first_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) - == 31) - && (second.with(|__s| __s.value) == 31)) as i32) - }, - &mut (ok), - ) { - (__tmp_28, __tmp_29) => { - (*__tmp_29) = (((*__tmp_29) as i32) & (__tmp_28 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (((({ (*first_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) + == 31) + && (second.with(|__s| __s.value) == 31)) as i32)) + != 0; + ok = rhs_0 }; let mut equivalent_count: usize = 0_usize; 'loop_: for entry in IterRange::new( @@ -403,19 +313,13 @@ fn main_0() -> i32 { ok = { ((ok as i32) & ((equivalent_count == 1_usize) as i32)) != 0 }; } { - match ( - { - (!({ - let _a: Ptr = equivalent_a.as_pointer(); - operator_eq_2(_a, equivalent_b.as_pointer()) - }) as i32) - }, - &mut (ok), - ) { - (__tmp_30, __tmp_31) => { - (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (!({ + let _a: Ptr = equivalent_a.as_pointer(); + operator_eq_2(_a, equivalent_b.as_pointer()) + }) as i32)) + != 0; + ok = rhs_0 }; let later_key: Value = Rc::new(RefCell::new(Key { order: 4, @@ -430,61 +334,37 @@ fn main_0() -> i32 { != 0 }; { - match ( - { (((*equivalent.borrow()).len() == 2_usize) as i32) }, - &mut (ok), - ) { - (__tmp_32, __tmp_33) => { - (*__tmp_33) = (((*__tmp_33) as i32) & (__tmp_32 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) & (((*equivalent.borrow()).len() == 2_usize) as i32)) != 0; + ok = rhs_0 }; if reused { { - match ( - { - (((*first_it.borrow()) - == equivalent.as_pointer().with( - |__m: &Map, Value)>| { - __m.find(&equivalent_a.as_pointer()) - }, - )) as i32) - }, - &mut (ok), - ) { - (__tmp_34, __tmp_35) => { - (*__tmp_35) = (((*__tmp_35) as i32) & (__tmp_34 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (((*first_it.borrow()) + == equivalent.as_pointer().with( + |__m: &Map, Value)>| { + __m.find(&equivalent_a.as_pointer()) + }, + )) as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - (({ - ((*({ (*first_it.borrow()).iter_deref() }).upgrade().deref()) - .1 - .as_pointer()) - } == { (first_value).clone() }) as i32) - }, - &mut (ok), - ) { - (__tmp_36, __tmp_37) => { - (*__tmp_37) = (((*__tmp_37) as i32) & (__tmp_36 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (({ + ((*({ (*first_it.borrow()).iter_deref() }).upgrade().deref()) + .1 + .as_pointer()) + } == { (first_value).clone() }) as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - ((({ (*first_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) - == 31) as i32) - }, - &mut (ok), - ) { - (__tmp_38, __tmp_39) => { - (*__tmp_39) = (((*__tmp_39) as i32) & (__tmp_38 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & ((({ (*first_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) + == 31) as i32)) + != 0; + ok = rhs_0 }; } let matching_a: Value = Rc::new(RefCell::new(Key { @@ -525,61 +405,37 @@ fn main_0() -> i32 { != 0 }; { - match ( - { (((*matching.borrow()).len() == 1_usize) as i32) }, - &mut (ok), - ) { - (__tmp_40, __tmp_41) => { - (*__tmp_41) = (((*__tmp_41) as i32) & (__tmp_40 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) & (((*matching.borrow()).len() == 1_usize) as i32)) != 0; + ok = rhs_0 }; ok = { ((ok as i32) & (({ (matched).clone() } == { (matched_again).clone() }) as i32)) != 0 }; { - match ( - { - (((*matched_it.borrow()) - == matching - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&matching_b.as_pointer()) - })) as i32) - }, - &mut (ok), - ) { - (__tmp_42, __tmp_43) => { - (*__tmp_43) = (((*__tmp_43) as i32) & (__tmp_42 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (((*matched_it.borrow()) + == matching + .as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&matching_b.as_pointer()) + })) as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - (({ - ((*({ (*matched_it.borrow()).iter_deref() }).upgrade().deref()) - .1 - .as_pointer()) - } == { (matched_value).clone() }) as i32) - }, - &mut (ok), - ) { - (__tmp_44, __tmp_45) => { - (*__tmp_45) = (((*__tmp_45) as i32) & (__tmp_44 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (({ + ((*({ (*matched_it.borrow()).iter_deref() }).upgrade().deref()) + .1 + .as_pointer()) + } == { (matched_value).clone() }) as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - ((({ (*matched_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) - == 51) as i32) - }, - &mut (ok), - ) { - (__tmp_46, __tmp_47) => { - (*__tmp_47) = (((*__tmp_47) as i32) & (__tmp_46 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & ((({ (*matched_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) == 51) + as i32)) + != 0; + ok = rhs_0 }; let other: Ptr = ({ (*matching.borrow_mut()).subscript(matching_c.as_pointer(), || ::default()) }); @@ -590,60 +446,36 @@ fn main_0() -> i32 { != 0 }; { - match ( - { (((*matching.borrow()).len() == 2_usize) as i32) }, - &mut (ok), - ) { - (__tmp_48, __tmp_49) => { - (*__tmp_49) = (((*__tmp_49) as i32) & (__tmp_48 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) & (((*matching.borrow()).len() == 2_usize) as i32)) != 0; + ok = rhs_0 }; { - match ( - { - (((*matched_it.borrow()) - == matching - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&matching_a.as_pointer()) - })) as i32) - }, - &mut (ok), - ) { - (__tmp_50, __tmp_51) => { - (*__tmp_51) = (((*__tmp_51) as i32) & (__tmp_50 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (((*matched_it.borrow()) + == matching + .as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&matching_a.as_pointer()) + })) as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - (({ - ((*({ (*matched_it.borrow()).iter_deref() }).upgrade().deref()) - .1 - .as_pointer()) - } == { (matched_value).clone() }) as i32) - }, - &mut (ok), - ) { - (__tmp_52, __tmp_53) => { - (*__tmp_53) = (((*__tmp_53) as i32) & (__tmp_52 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (({ + ((*({ (*matched_it.borrow()).iter_deref() }).upgrade().deref()) + .1 + .as_pointer()) + } == { (matched_value).clone() }) as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - ((({ (*matched_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) - == 51) as i32) - }, - &mut (ok), - ) { - (__tmp_54, __tmp_55) => { - (*__tmp_55) = (((*__tmp_55) as i32) & (__tmp_54 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & ((({ (*matched_it.borrow()).iter_deref() }).with(|__s| (*__s.1.borrow()).value) == 51) + as i32)) + != 0; + ok = rhs_0 }; return if ok { 0 } else { 1 }; } diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index a0652c2b21..f64adfeced 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -295,73 +295,48 @@ fn main_0() -> i32 { let mut found : bool = (*(*result.borrow()) .0.borrow()) == m .as_pointer() .with(|__m: &Map, Value)>| __m.find(&key .as_pointer() )) ; ok = { ((ok as i32) & (found as i32)) != 0 }; { - match ( - { - (((*(*({ - (*(*result.borrow()).0.borrow()) - .iter_deref() - }) - .upgrade() - .deref()) - .0 - .borrow()) - == (*key.borrow())) - as i32) - }, - &mut (ok), - ) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as i32) - & (__tmp_6 as i32)) - != 0; - } - } + let rhs_0 = ((ok as i32) + & (((*(*({ + (*(*result.borrow()).0.borrow()) + .iter_deref() + }) + .upgrade() + .deref()) + .0 + .borrow()) + == (*key.borrow())) + as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - (((*(*({ - (*(*result.borrow()).0.borrow()) - .iter_deref() - }) - .upgrade() - .deref()) - .1 - .borrow()) - == (if hit { - (10 + (*key.borrow())) - } else { - (initial - + (!(post != 0) as i32)) - })) - as i32) - }, - &mut (ok), - ) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as i32) - & (__tmp_8 as i32)) - != 0; - } - } + let rhs_0 = ((ok as i32) + & (((*(*({ + (*(*result.borrow()).0.borrow()) + .iter_deref() + }) + .upgrade() + .deref()) + .1 + .borrow()) + == (if hit { + (10 + (*key.borrow())) + } else { + (initial + + (!(post != 0) as i32)) + })) + as i32)) + != 0; + ok = rhs_0 }; { - match ( - { - (((*m.borrow()).len() - == ((size + (!(hit) as i32)) - as usize)) - as i32) - }, - &mut (ok), - ) { - (__tmp_10, __tmp_11) => { - (*__tmp_11) = (((*__tmp_11) - as i32) - & (__tmp_10 as i32)) - != 0; - } - } + let rhs_0 = ((ok as i32) + & (((*m.borrow()).len() + == ((size + (!(hit) as i32)) + as usize)) + as i32)) + != 0; + ok = rhs_0 }; rows.prefix_inc(); } @@ -411,12 +386,12 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_12,) => { + (__tmp_6,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::copy_from({ (__tmp_12).clone() }))), + Rc::new(RefCell::new(Item::copy_from({ (__tmp_6).clone() }))), ) }); ( @@ -434,31 +409,25 @@ fn main_0() -> i32 { != 0 }; { - match ( - { - (((!(*(*hit.borrow()).1.borrow())) - && (({ (*(*hit.borrow()).0.borrow()).iter_deref() }) - .with(|__s| (*__s.1.borrow()).value) - == 10)) as i32) - }, - &mut (ok), - ) { - (__tmp_13, __tmp_14) => { - (*__tmp_14) = (((*__tmp_14) as i32) & (__tmp_13 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (((!(*(*hit.borrow()).1.borrow())) + && (({ (*(*hit.borrow()).0.borrow()).iter_deref() }) + .with(|__s| (*__s.1.borrow()).value) + == 10)) as i32)) + != 0; + ok = rhs_0 }; let move_hit: Value<( Value, Value)>>, Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_15,) => { + (__tmp_7,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_15).clone() }))), + Rc::new(RefCell::new(Item::move_from({ (__tmp_7).clone() }))), ) }); ( @@ -487,12 +456,12 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_16,) => { + (__tmp_8,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::copy_from({ (__tmp_16).clone() }))), + Rc::new(RefCell::new(Item::copy_from({ (__tmp_8).clone() }))), ) }); ( @@ -510,19 +479,13 @@ fn main_0() -> i32 { != 0 }; { - match ( - { - (((*(*copied.borrow()).1.borrow()) - && (({ (*(*copied.borrow()).0.borrow()).iter_deref() }) - .with(|__s| (*__s.1.borrow()).value) - == 20)) as i32) - }, - &mut (ok), - ) { - (__tmp_17, __tmp_18) => { - (*__tmp_18) = (((*__tmp_18) as i32) & (__tmp_17 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & (((*(*copied.borrow()).1.borrow()) + && (({ (*(*copied.borrow()).0.borrow()).iter_deref() }) + .with(|__s| (*__s.1.borrow()).value) + == 20)) as i32)) + != 0; + ok = rhs_0 }; (*key.borrow_mut()).prefix_inc(); let moved: Value<( @@ -530,12 +493,12 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_19,) => { + (__tmp_9,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_19).clone() }))), + Rc::new(RefCell::new(Item::move_from({ (__tmp_9).clone() }))), ) }); ( @@ -553,20 +516,14 @@ fn main_0() -> i32 { != 0 }; { - match ( - { - ((((*(*moved.borrow()).1.borrow()) - && (({ (*(*moved.borrow()).0.borrow()).iter_deref() }) - .with(|__s| (*__s.1.borrow()).value) - == 20)) - && ({ (*source.borrow()).value } == -1_i32)) as i32) - }, - &mut (ok), - ) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = (((*__tmp_21) as i32) & (__tmp_20 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & ((((*(*moved.borrow()).1.borrow()) + && (({ (*(*moved.borrow()).0.borrow()).iter_deref() }) + .with(|__s| (*__s.1.borrow()).value) + == 20)) + && ({ (*source.borrow()).value } == -1_i32)) as i32)) + != 0; + ok = rhs_0 }; let refs: Value, Value)>> = Rc::new(RefCell::new(Map::new())); (*key.borrow_mut()) = 0; @@ -591,11 +548,11 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ reference_5(counter.as_pointer()) }),) { - (__tmp_22,) => { + (__tmp_10,) => { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(RefItem::new_2({ (__tmp_22).clone() }, { 2 }))), + Rc::new(RefCell::new(RefItem::new_2({ (__tmp_10).clone() }, { 2 }))), ) }); ( @@ -618,11 +575,11 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ reference_5(counter.as_pointer()) }),) { - (__tmp_23,) => { + (__tmp_11,) => { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(RefItem::new_2({ (__tmp_23).clone() }, { 2 }))), + Rc::new(RefCell::new(RefItem::new_2({ (__tmp_11).clone() }, { 2 }))), ) }); ( @@ -640,21 +597,15 @@ fn main_0() -> i32 { != 0 }; { - match ( - { - (((({ (*(*ref_hit.borrow()).0.borrow()).iter_deref() }) + let rhs_0 = ((ok as i32) + & (((({ (*(*ref_hit.borrow()).0.borrow()).iter_deref() }) + .with(|__s| (*__s.1.borrow()).value) + == 5) + && (({ (*(*ref_new.borrow()).0.borrow()).iter_deref() }) .with(|__s| (*__s.1.borrow()).value) - == 5) - && (({ (*(*ref_new.borrow()).0.borrow()).iter_deref() }) - .with(|__s| (*__s.1.borrow()).value) - == 7)) as i32) - }, - &mut (ok), - ) { - (__tmp_24, __tmp_25) => { - (*__tmp_25) = (((*__tmp_25) as i32) & (__tmp_24 as i32)) != 0; - } - } + == 7)) as i32)) + != 0; + ok = rhs_0 }; (*key.borrow_mut()) = 0; made_1.with(|rc| { @@ -672,18 +623,18 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_27: Value; + let __tmp_13: Value; match ({ - __tmp_27 = Rc::new(RefCell::new(Item::new_1({ 30 }))); - __tmp_27.as_pointer() + __tmp_13 = Rc::new(RefCell::new(Item::new_1({ 30 }))); + __tmp_13.as_pointer() },) { - (__tmp_26,) => { + (__tmp_12,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_26).clone() }))), + Rc::new(RefCell::new(Item::move_from({ (__tmp_12).clone() }))), ) }); ( @@ -708,18 +659,18 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_29: Value; + let __tmp_15: Value; match ({ - __tmp_29 = Rc::new(RefCell::new(Item::new_1({ 40 }))); - __tmp_29.as_pointer() + __tmp_15 = Rc::new(RefCell::new(Item::new_1({ 40 }))); + __tmp_15.as_pointer() },) { - (__tmp_28,) => { + (__tmp_14,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_28).clone() }))), + Rc::new(RefCell::new(Item::move_from({ (__tmp_14).clone() }))), ) }); ( @@ -738,18 +689,12 @@ fn main_0() -> i32 { != 0 }; { - match ( - { - ((({ (*(*temporary_new.borrow()).0.borrow()).iter_deref() }) - .with(|__s| (*__s.1.borrow()).value) - == 40) as i32) - }, - &mut (ok), - ) { - (__tmp_30, __tmp_31) => { - (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; - } - } + let rhs_0 = ((ok as i32) + & ((({ (*(*temporary_new.borrow()).0.borrow()).iter_deref() }) + .with(|__s| (*__s.1.borrow()).value) + == 40) as i32)) + != 0; + ok = rhs_0 }; printf!( b"%d %d %d %d %d\n", diff --git a/tests/unit/out/refcount/va_arg_concat.rs b/tests/unit/out/refcount/va_arg_concat.rs index 062db46290..c39ccdc634 100644 --- a/tests/unit/out/refcount/va_arg_concat.rs +++ b/tests/unit/out/refcount/va_arg_concat.rs @@ -14,12 +14,8 @@ pub fn sum_ints_0(first: i32, __args: Box<[VaArg]>) -> i32 { (*args.borrow_mut()) = __args.decay(); let mut val: i32 = 0_i32; 'loop_: while (({ - match ({ (*args.borrow_mut()).arg::() }, &mut (val)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } - } + val = (*args.borrow_mut()).arg::(); + val }) != 0) { total += val; diff --git a/tests/unit/out/refcount/va_arg_two_passes.rs b/tests/unit/out/refcount/va_arg_two_passes.rs index 34f1245cb9..1f8cf40efd 100644 --- a/tests/unit/out/refcount/va_arg_two_passes.rs +++ b/tests/unit/out/refcount/va_arg_two_passes.rs @@ -15,24 +15,16 @@ pub fn sum_then_product_0(first: i32, __args: Box<[VaArg]>) -> i32 { (*ap.borrow_mut()) = __args.decay(); let mut val: i32 = 0_i32; 'loop_: while (({ - match ({ (*ap.borrow_mut()).arg::() }, &mut (val)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } - } + val = (*ap.borrow_mut()).arg::(); + val }) != 0) { sum += val; } (*ap.borrow_mut()) = __args.decay(); 'loop_: while (({ - match ({ (*ap.borrow_mut()).arg::() }, &mut (val)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } - } + val = (*ap.borrow_mut()).arg::(); + val }) != 0) { product *= val; diff --git a/tests/unit/out/refcount/vector_subscript_borrow.rs b/tests/unit/out/refcount/vector_subscript_borrow.rs index 5c95f96ad1..01b8b4b57a 100644 --- a/tests/unit/out/refcount/vector_subscript_borrow.rs +++ b/tests/unit/out/refcount/vector_subscript_borrow.rs @@ -34,11 +34,8 @@ fn main_0() -> i32 { } } { - match ({ 5_u32 }, &mut (items[1_usize])) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; - } - } + let rhs_0 = (items[1_usize]).wrapping_add(5_u32); + items[1_usize] = rhs_0 }; items[2_usize].postfix_inc(); assert!(((items[0_usize] == 0_u32) && (items[1_usize] == 7_u32)) && (items[2_usize] == 5_u32)); diff --git a/tests/unit/out/unsafe/anonymous-struct.rs b/tests/unit/out/unsafe/anonymous-struct.rs index 23ce4405af..c2dcdd39c8 100644 --- a/tests/unit/out/unsafe/anonymous-struct.rs +++ b/tests/unit/out/unsafe/anonymous-struct.rs @@ -90,19 +90,15 @@ unsafe fn main_0() -> i32 { s.x = 1; s.z = 2; assert!( - (match ({ 1 }, &mut (s.x)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + ({ + s.x = 1; + s.x } != 0) ); assert!( - (match ({ 2 }, &mut (s.z)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + ({ + s.z = 2; + s.z } != 0) ); return 0; diff --git a/tests/unit/out/unsafe/anonymous-struct_c.rs b/tests/unit/out/unsafe/anonymous-struct_c.rs index a773bae7af..942e68464a 100644 --- a/tests/unit/out/unsafe/anonymous-struct_c.rs +++ b/tests/unit/out/unsafe/anonymous-struct_c.rs @@ -96,19 +96,15 @@ unsafe fn main_0() -> i32 { s.x = 1; s.z = 2; assert!( - (match ({ 1 }, &mut (s.x)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + ({ + s.x = 1; + s.x } != 0) ); assert!( - (match ({ 2 }, &mut (s.z)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + ({ + s.z = 2; + s.z } != 0) ); return 0; diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 3681648ed8..ba51d76bc8 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -586,14 +586,25 @@ pub unsafe fn observe_7(mut assigned: i32, mut stored: *const i32) -> i32 { } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct GlobalRecord { +pub struct GlobalRecord_Inner { pub value: i32, } +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct GlobalRecord { + pub inner: GlobalRecord_Inner, +} pub static mut global_record_8: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { GlobalRecord { value: 10 } }); + std::cell::LazyCell::new(|| unsafe { + GlobalRecord { + inner: GlobalRecord_Inner { value: 10 }, + } + }); pub unsafe fn observe_record_9(mut assigned: i32) -> i32 { return ((assigned) - + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_8)).value)); + + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_8)) + .inner + .value)); } pub static mut targets_10: std::cell::LazyCell<[i32; 2]> = std::cell::LazyCell::new(|| unsafe { [10, 20] }); @@ -627,27 +638,17 @@ pub unsafe fn test_borrows_12() { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - observe_global_6( - match ( - { - (unsafe { - observe_7( - 0, - (&raw mut (*std::cell::LazyCell::force_mut( - &mut *&raw mut global_5, - )) as *mut i32) - .cast_const(), - ) - }) - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)), - ) { - (__tmp_56, __tmp_57) => { - (*__tmp_57) = __tmp_56; - (*__tmp_57).clone() - } - }, - ) + observe_global_6({ + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)) = (unsafe { + observe_7( + 0, + (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)) + as *mut i32) + .cast_const(), + ) + }); + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)) + }) }), ) }); @@ -659,6 +660,29 @@ pub unsafe fn test_borrows_12() { } }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_13)), + ) { + (__tmp_56, __tmp_57) => { + (*__tmp_57) = (((*__tmp_57) as f64) + (__tmp_56 as f64)) as i16; + (*__tmp_57).clone() + } + }) as i32); + (unsafe { + libc::printf( + c"%d %d\n".as_ptr() as *const libc::c_char, + (assigned), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_13)) as i32), + ) + }); + let mut aliased: i16 = 10_i16; + let mut alias: *mut i16 = (&mut aliased as *mut i16); + assigned = ((match ( + { + { + (*alias) = (-1_i32 as i16); + 0.5_f64 + } + }, + &mut (aliased), ) { (__tmp_58, __tmp_59) => { (*__tmp_59) = (((*__tmp_59) as f64) + (__tmp_58 as f64)) as i16; @@ -669,7 +693,7 @@ pub unsafe fn test_borrows_12() { libc::printf( c"%d %d\n".as_ptr() as *const libc::c_char, (assigned), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_13)) as i32), + (aliased as i32), ) }); let mut enabled: bool = (match ( @@ -708,6 +732,7 @@ pub unsafe fn test_borrows_12() { match ( { 99 }, &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_8)) + .inner .value), ) { (__tmp_62, __tmp_63) => { @@ -777,11 +802,9 @@ pub unsafe fn test_borrows_12() { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - let _assigned: i32 = match ({ 99 }, &mut (record.value)) { - (__tmp_66, __tmp_67) => { - (*__tmp_67) = __tmp_66; - (*__tmp_67).clone() - } + let _assigned: i32 = { + record.value = 99; + record.value }; let _stored: *const i32 = (&mut record.value as *mut i32).cast_const(); observe_7(_assigned, _stored) @@ -792,27 +815,47 @@ pub unsafe fn test_borrows_12() { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - let _assigned: i32 = match ({ 5 }, &mut (record.value)) { - (__tmp_68, __tmp_69) => { - (*__tmp_69) = (((*__tmp_69) as i32) + (__tmp_68 as i32)) as i32; - (*__tmp_69).clone() - } + let _assigned: i32 = { + record.value += 5; + record.value }; let _stored: *const i32 = (&mut record.value as *mut i32).cast_const(); observe_7(_assigned, _stored) }), ) }); + let mut first: Link_16 = ::default(); + first = Link_16 { + next: (&mut first as *mut Link_16), + }; + let mut second: Link_16 = Link_16 { + next: (&mut first as *mut Link_16), + }; + let selector: *mut *mut Link_16 = &mut first.next; + let mut selected: *mut Link_16 = (match ( + { (&mut second as *mut Link_16) }, + &mut ((*(*selector)).next), + ) { + (__tmp_66, __tmp_67) => { + (*__tmp_67) = __tmp_66; + (*__tmp_67).clone() + } + }); + (unsafe { + libc::printf( + c"%d %d\n".as_ptr() as *const libc::c_char, + (((selected) == (&mut second as *mut Link_16)) as i32), + (((first.next) == (&mut second as *mut Link_16)) as i32), + ) + }); let mut values: Vec = vec![10; 1_usize]; (unsafe { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - let _assigned: i32 = match ({ 99 }, &mut (values[(0_usize)])) { - (__tmp_70, __tmp_71) => { - (*__tmp_71) = __tmp_70; - (*__tmp_71).clone() - } + let _assigned: i32 = { + values[(0_usize)] = 99; + values[(0_usize)] }; let _stored: *const i32 = (&mut values[(0_usize)] as *mut i32).cast_const(); observe_7(_assigned, _stored) @@ -823,11 +866,9 @@ pub unsafe fn test_borrows_12() { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - let _assigned: i32 = match ({ 5 }, &mut (values[(0_usize)])) { - (__tmp_72, __tmp_73) => { - (*__tmp_73) = (((*__tmp_73) as i32) + (__tmp_72 as i32)) as i32; - (*__tmp_73).clone() - } + let _assigned: i32 = { + values[(0_usize)] += 5; + values[(0_usize)] }; let _stored: *const i32 = (&mut values[(0_usize)] as *mut i32).cast_const(); observe_7(_assigned, _stored) @@ -842,36 +883,41 @@ static mut flag_14: std::cell::LazyCell = std::cell::LazyCell::new(|| unsa pub struct Record_15 { pub value: i32, } -pub static mut selected_values_16: std::cell::LazyCell<[u32; 3]> = +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Link_16 { + pub next: *mut Link_16, +} +pub static mut selected_values_17: std::cell::LazyCell<[u32; 3]> = std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] pub struct IndexedBinding {} impl IndexedBinding { pub unsafe fn get_1_0(&mut self) -> *mut u32 { - return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_16)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_16))[(0) as usize]) + return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_17)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_17))[(0) as usize]) as usize]; } } -pub unsafe fn test_binding_17() { +pub unsafe fn test_binding_18() { let mut owner: IndexedBinding = ::default(); - let __decomp_18: *mut IndexedBinding = &mut owner; - let value: *mut u32 = (unsafe { IndexedBinding::get_1_0(&mut (*__decomp_18)) }); + let __decomp_19: *mut IndexedBinding = &mut owner; + let value: *mut u32 = (unsafe { IndexedBinding::get_1_0(&mut (*__decomp_19)) }); let mut result: u32 = (match ( { 1_u32 }, - &mut (*(unsafe { IndexedBinding::get_1_0(&mut (*__decomp_18)) })), + &mut (*(unsafe { IndexedBinding::get_1_0(&mut (*__decomp_19)) })), ) { - (__tmp_74, __tmp_75) => { - (*__tmp_75) = (((*__tmp_75) as u32).wrapping_add((__tmp_74 as u32))) as u32; - (*__tmp_75).clone() + (__tmp_68, __tmp_69) => { + (*__tmp_69) = (((*__tmp_69) as u32).wrapping_add((__tmp_68 as u32))) as u32; + (*__tmp_69).clone() } }); (unsafe { libc::printf( c"binding compound %u %u\n".as_ptr() as *const libc::c_char, (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_16))[(0) as usize]), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_17))[(0) as usize]), ) }); } @@ -897,9 +943,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_76, __tmp_77) => { - (*__tmp_77) = (((*__tmp_77) as u32).wrapping_add((__tmp_76 as u32))) as u32; - (*__tmp_77).clone() + (__tmp_70, __tmp_71) => { + (*__tmp_71) = (((*__tmp_71) as u32).wrapping_add((__tmp_70 as u32))) as u32; + (*__tmp_71).clone() } }); (unsafe { @@ -911,7 +957,7 @@ unsafe fn main_0() -> i32 { ) }); (unsafe { test_borrows_12() }); - (unsafe { test_binding_17() }); + (unsafe { test_binding_18() }); return 0; } pub unsafe fn __cpp2rust_init_globals() { @@ -919,5 +965,5 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const global_record_8); std::cell::LazyCell::force(&*&raw const targets_10); std::cell::LazyCell::force(&*&raw const cursor_11); - std::cell::LazyCell::force(&*&raw const selected_values_16); + std::cell::LazyCell::force(&*&raw const selected_values_17); } diff --git a/tests/unit/out/unsafe/field_pointers_malloced_struct.rs b/tests/unit/out/unsafe/field_pointers_malloced_struct.rs index 68f4736b65..6081feceef 100644 --- a/tests/unit/out/unsafe/field_pointers_malloced_struct.rs +++ b/tests/unit/out/unsafe/field_pointers_malloced_struct.rs @@ -42,11 +42,9 @@ unsafe fn main_0() -> i32 { } assert!((((*s).a) == (5)) && (((*s).c) == (1))); let mut x: i32 = (((*s).a) - + (match ({ 3 }, &mut ((*s).b)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + + ({ + (*s).b = 3; + (*s).b })); assert!(((x) == (8)) && (((*s).b) == (3))); let mut y: i32 = 0; diff --git a/tests/unit/out/unsafe/global_call_temporaries.rs b/tests/unit/out/unsafe/global_call_temporaries.rs index e9a02dcc11..b466e55114 100644 --- a/tests/unit/out/unsafe/global_call_temporaries.rs +++ b/tests/unit/out/unsafe/global_call_temporaries.rs @@ -30,70 +30,49 @@ pub static mut x_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsaf pub static mut y_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut assigned_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_4: i32; - let mut __tmp_5: i32; - (match ( - { - { - __tmp_4 = 5; - __tmp_5 = 6; - (*{ - let __a: *const _ = &mut __tmp_4; - let __b: *const _ = &mut __tmp_5; - if *__b < *__a { __b } else { __a } - }) - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut x_2)), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + let mut __tmp_2: i32; + let mut __tmp_3: i32; + ({ + (*std::cell::LazyCell::force_mut(&mut *&raw mut x_2)) = { + __tmp_2 = 5; + __tmp_3 = 6; + (*{ + let __a: *const _ = &mut __tmp_2; + let __b: *const _ = &mut __tmp_3; + if *__b < *__a { __b } else { __a } + }) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut x_2)) }) } }); pub static mut accumulated_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_8: i32; - let mut __tmp_9: i32; - (match ( - { - { - __tmp_8 = 1; - __tmp_9 = 2; - (*{ - let __a: *const _ = &mut __tmp_8; - let __b: *const _ = &mut __tmp_9; - if *__a < *__b { __b } else { __a } - }) - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut y_3)), - ) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as i32) + (__tmp_6 as i32)) as i32; - (*__tmp_7).clone() - } + let mut __tmp_4: i32; + let mut __tmp_5: i32; + ({ + (*std::cell::LazyCell::force_mut(&mut *&raw mut y_3)) += { + __tmp_4 = 1; + __tmp_5 = 2; + (*{ + let __a: *const _ = &mut __tmp_4; + let __b: *const _ = &mut __tmp_5; + if *__a < *__b { __b } else { __a } + }) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut y_3)) }) } }); pub static mut call_assigned_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_12: i32; - (match ( - { - (unsafe { - __tmp_12 = 5; - read_0(&mut __tmp_12) - }) - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut x_2)), - ) { - (__tmp_10, __tmp_11) => { - (*__tmp_11) = __tmp_10; - (*__tmp_11).clone() - } + let mut __tmp_6: i32; + ({ + (*std::cell::LazyCell::force_mut(&mut *&raw mut x_2)) = (unsafe { + __tmp_6 = 5; + read_0(&mut __tmp_6) + }); + (*std::cell::LazyCell::force_mut(&mut *&raw mut x_2)) }) } }); @@ -111,36 +90,36 @@ pub unsafe fn read_record_8(value: *const Item) -> i32 { pub static mut aggregate_selected_9: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_14: i32; - let mut __tmp_15: i32; - let mut __tmp_13: [i32; 1]; - let mut __tmp_17: i32; - let mut __tmp_18: i32; - let mut __tmp_16: Item; + let mut __tmp_8: i32; + let mut __tmp_9: i32; + let mut __tmp_7: [i32; 1]; + let mut __tmp_11: i32; + let mut __tmp_12: i32; + let mut __tmp_10: Item; ((unsafe { - __tmp_13 = [{ - __tmp_14 = 3; - __tmp_15 = 4; + __tmp_7 = [{ + __tmp_8 = 3; + __tmp_9 = 4; (*{ - let __a: *const _ = &mut __tmp_14; - let __b: *const _ = &mut __tmp_15; + let __a: *const _ = &mut __tmp_8; + let __b: *const _ = &mut __tmp_9; if *__b < *__a { __b } else { __a } }) }]; - read_array_7(&mut __tmp_13) + read_array_7(&mut __tmp_7) }) + (unsafe { - __tmp_16 = Item { + __tmp_10 = Item { value: { - __tmp_17 = 5; - __tmp_18 = 6; + __tmp_11 = 5; + __tmp_12 = 6; (*{ - let __a: *const _ = &mut __tmp_17; - let __b: *const _ = &mut __tmp_18; + let __a: *const _ = &mut __tmp_11; + let __b: *const _ = &mut __tmp_12; if *__a < *__b { __b } else { __a } }) }, }; - read_record_8(&mut __tmp_16) + read_record_8(&mut __tmp_10) })) } }); @@ -150,13 +129,13 @@ pub static mut right_11: std::cell::LazyCell = pub static mut mapped_selected_12: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_19: u64; + let mut __tmp_13: u64; (({ - __tmp_19 = ((*std::cell::LazyCell::force_mut(&mut *&raw mut right_11)) as u64); + __tmp_13 = ((*std::cell::LazyCell::force_mut(&mut *&raw mut right_11)) as u64); (*{ let __a: *const _ = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut left_10)); - let __b: *const _ = &mut __tmp_19; + let __b: *const _ = &mut __tmp_13; if *__b < *__a { __b } else { __a } }) }) as usize) @@ -167,12 +146,12 @@ pub unsafe fn get_13() -> usize { } static mut value_14: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_20: u64; + let mut __tmp_14: u64; (({ - __tmp_20 = ((*std::cell::LazyCell::force_mut(&mut *&raw mut right_11)) as u64); + __tmp_14 = ((*std::cell::LazyCell::force_mut(&mut *&raw mut right_11)) as u64); (*{ let __a: *const _ = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut left_10)); - let __b: *const _ = &mut __tmp_20; + let __b: *const _ = &mut __tmp_14; if *__a < *__b { __b } else { __a } }) }) as usize) @@ -197,36 +176,36 @@ unsafe fn main_0() -> i32 { } static mut aggregate_static_15: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __tmp_22: i32; - let mut __tmp_23: i32; - let mut __tmp_21: [i32; 1]; - let mut __tmp_25: i32; - let mut __tmp_26: i32; - let mut __tmp_24: Item; + let mut __tmp_16: i32; + let mut __tmp_17: i32; + let mut __tmp_15: [i32; 1]; + let mut __tmp_19: i32; + let mut __tmp_20: i32; + let mut __tmp_18: Item; ((unsafe { - __tmp_21 = [{ - __tmp_22 = 7; - __tmp_23 = 8; + __tmp_15 = [{ + __tmp_16 = 7; + __tmp_17 = 8; (*{ - let __a: *const _ = &mut __tmp_22; - let __b: *const _ = &mut __tmp_23; + let __a: *const _ = &mut __tmp_16; + let __b: *const _ = &mut __tmp_17; if *__a < *__b { __b } else { __a } }) }]; - read_array_7(&mut __tmp_21) + read_array_7(&mut __tmp_15) }) + (unsafe { - __tmp_24 = Item { + __tmp_18 = Item { value: { - __tmp_25 = 9; - __tmp_26 = 10; + __tmp_19 = 9; + __tmp_20 = 10; (*{ - let __a: *const _ = &mut __tmp_25; - let __b: *const _ = &mut __tmp_26; + let __a: *const _ = &mut __tmp_19; + let __b: *const _ = &mut __tmp_20; if *__b < *__a { __b } else { __a } }) }, }; - read_record_8(&mut __tmp_24) + read_record_8(&mut __tmp_18) })) } }); diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 3438895e9c..2aa3777fcd 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -94,22 +94,8 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32)) != 0; - match ( - { ((((*m.find(&a).iter_deref()).1) == (11)) as i32) }, - &mut (ok), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as i32) & (__tmp_0 as i32)) != 0; - } - }; - match ( - { ((((*m.get(&b).expect("out of range!")).1) == (20)) as i32) }, - &mut (ok), - ) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = (((*__tmp_3) as i32) & (__tmp_2 as i32)) != 0; - } - }; + ok = ((ok as i32) & ((((*m.find(&a).iter_deref()).1) == (11)) as i32)) != 0; + ok = ((ok as i32) & ((((*m.get(&b).expect("out of range!")).1) == (20)) as i32)) != 0; ok = ((ok as i32) & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32)) != 0; @@ -136,80 +122,35 @@ unsafe fn main_0() -> i32 { && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2))) && ((c.k) == (3))) as i32)) != 0; - match ({ (((m.len()) == (4_usize)) as i32) }, &mut (ok)) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) != 0; - } - }; + ok = ((ok as i32) & (((m.len()) == (4_usize)) as i32)) != 0; (*m.subscript(&(*m.begin().iter_deref()).0, || 0_i32)) += 1; - match ( - { - ((((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) - && ((*m.subscript(&a, || 0_i32)) == (12))) as i32) - }, - &mut (ok), - ) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as i32) & (__tmp_6 as i32)) != 0; - } - }; + ok = ((ok as i32) + & ((((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) + && ((*m.subscript(&a, || 0_i32)) == (12))) as i32)) + != 0; let mut first: *const Key = (&(*m.begin().iter_deref()).0 as *const Key); (*m.subscript_move(&mut Key::new({ 0 }), |__k| cpp_move_unsafe!(__k), || 0_i32)) = 0; ok = ((ok as i32) & (((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (3)) as i32)) != 0; - match ( - { (((&(*m.find(&a).iter_deref()).0 as *const Key) == (first)) as i32) }, - &mut (ok), - ) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as i32) & (__tmp_8 as i32)) != 0; - } - }; + ok = ((ok as i32) & (((&(*m.find(&a).iter_deref()).0 as *const Key) == (first)) as i32)) != 0; let mut n: UnsafeMap = m.clone(); ok = ((ok as i32) & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == ((2) + (5))) as i32)) != 0; - match ( - { ((((n.len()) == (5_usize)) && ((*n.subscript(&a, || 0_i32)) == (12))) as i32) }, - &mut (ok), - ) { - (__tmp_10, __tmp_11) => { - (*__tmp_11) = (((*__tmp_11) as i32) & (__tmp_10 as i32)) != 0; - } - }; + ok = ((ok as i32) + & ((((n.len()) == (5_usize)) && ((*n.subscript(&a, || 0_i32)) == (12))) as i32)) + != 0; m.erase(&m.find(&a)); - match ({ (((m.erase_key(&b)) == (1_usize)) as i32) }, &mut (ok)) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = (((*__tmp_13) as i32) & (__tmp_12 as i32)) != 0; - } - }; - match ({ (((m.erase_key(&b)) == (0_usize)) as i32) }, &mut (ok)) { - (__tmp_14, __tmp_15) => { - (*__tmp_15) = (((*__tmp_15) as i32) & (__tmp_14 as i32)) != 0; - } - }; - match ( - { (((m.erase_key(&(*m.begin().iter_deref()).0)) == (1_usize)) as i32) }, - &mut (ok), - ) { - (__tmp_16, __tmp_17) => { - (*__tmp_17) = (((*__tmp_17) as i32) & (__tmp_16 as i32)) != 0; - } - }; + ok = ((ok as i32) & (((m.erase_key(&b)) == (1_usize)) as i32)) != 0; + ok = ((ok as i32) & (((m.erase_key(&b)) == (0_usize)) as i32)) != 0; + ok = ((ok as i32) & (((m.erase_key(&(*m.begin().iter_deref()).0)) == (1_usize)) as i32)) != 0; ok = ((ok as i32) & ((((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (7)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (3))) as i32)) != 0; - match ( - { ((((m.len()) == (2_usize)) && ((n.len()) == (5_usize))) as i32) }, - &mut (ok), - ) { - (__tmp_18, __tmp_19) => { - (*__tmp_19) = (((*__tmp_19) as i32) & (__tmp_18 as i32)) != 0; - } - }; + ok = ((ok as i32) & ((((m.len()) == (2_usize)) && ((n.len()) == (5_usize))) as i32)) != 0; let mut sum: i32 = 0; 'loop_: for entry in IterRange::new(m.begin(), m.end()) { let entry: *const (Key, i32) = &(*entry.iter_deref()); diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index cce7d71f9f..3db4f6cd3e 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -77,19 +77,12 @@ unsafe fn main_0() -> i32 { order: 2, identity: 7, }; - match ( - { - ((unsafe { - let _a: *const Key = &distinct_a; - operator_eq_2(_a, &distinct_b) - }) as i32) - }, - &mut (ok), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as i32) & (__tmp_0 as i32)) != 0; - } - }; + ok = ((ok as i32) + & ((unsafe { + let _a: *const Key = &distinct_a; + operator_eq_2(_a, &distinct_b) + }) as i32)) + != 0; let mut distinct: UnsafeMap = UnsafeMap::new(); let a: *mut Mapped = &mut (*distinct.subscript(&distinct_a, || ::default())); (*a).value = 11; @@ -106,57 +99,20 @@ unsafe fn main_0() -> i32 { & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == (2)) as i32)) != 0; - match ({ (((distinct.len()) == (2_usize)) as i32) }, &mut (ok)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = (((*__tmp_3) as i32) & (__tmp_2 as i32)) != 0; - } - }; + ok = ((ok as i32) & (((distinct.len()) == (2_usize)) as i32)) != 0; ok = ((ok as i32) & (((a) != (b)) as i32)) != 0; ok = ((ok as i32) & (((((*a).value) == (11)) && (((*b).value) == (22))) as i32)) != 0; - match ({ ((a_it == distinct.find(&distinct_a)) as i32) }, &mut (ok)) { - (__tmp_4, __tmp_5) => { - (*__tmp_5) = (((*__tmp_5) as i32) & (__tmp_4 as i32)) != 0; - } - }; - match ({ ((b_it == distinct.find(&distinct_b)) as i32) }, &mut (ok)) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as i32) & (__tmp_6 as i32)) != 0; - } - }; - match ({ ((b_it != distinct.end()) as i32) }, &mut (ok)) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as i32) & (__tmp_8 as i32)) != 0; - } - }; - match ( - { (((&mut (*a_it.iter_deref()).1 as *mut Mapped) == (a_value)) as i32) }, - &mut (ok), - ) { - (__tmp_10, __tmp_11) => { - (*__tmp_11) = (((*__tmp_11) as i32) & (__tmp_10 as i32)) != 0; - } - }; - match ( - { ((((*a_it.iter_deref()).1.value) == (11)) as i32) }, - &mut (ok), - ) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = (((*__tmp_13) as i32) & (__tmp_12 as i32)) != 0; - } - }; - match ( - { - ((unsafe { - let _a: *const Key = &distinct_a; - operator_eq_2(_a, &distinct_b) - }) as i32) - }, - &mut (ok), - ) { - (__tmp_14, __tmp_15) => { - (*__tmp_15) = (((*__tmp_15) as i32) & (__tmp_14 as i32)) != 0; - } - }; + ok = ((ok as i32) & ((a_it == distinct.find(&distinct_a)) as i32)) != 0; + ok = ((ok as i32) & ((b_it == distinct.find(&distinct_b)) as i32)) != 0; + ok = ((ok as i32) & ((b_it != distinct.end()) as i32)) != 0; + ok = ((ok as i32) & (((&mut (*a_it.iter_deref()).1 as *mut Mapped) == (a_value)) as i32)) != 0; + ok = ((ok as i32) & ((((*a_it.iter_deref()).1.value) == (11)) as i32)) != 0; + ok = ((ok as i32) + & ((unsafe { + let _a: *const Key = &distinct_a; + operator_eq_2(_a, &distinct_b) + }) as i32)) + != 0; let mut distinct_count: usize = 0_usize; 'loop_: for entry in IterRange::new(distinct.begin(), distinct.end()) { let entry: *const (Key, Mapped) = &(*entry.iter_deref()); @@ -180,19 +136,12 @@ unsafe fn main_0() -> i32 { order: 3, identity: 9, }; - match ( - { - (!(unsafe { - let _a: *const Key = &equivalent_a; - operator_eq_2(_a, &equivalent_b) - }) as i32) - }, - &mut (ok), - ) { - (__tmp_16, __tmp_17) => { - (*__tmp_17) = (((*__tmp_17) as i32) & (__tmp_16 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (!(unsafe { + let _a: *const Key = &equivalent_a; + operator_eq_2(_a, &equivalent_b) + }) as i32)) + != 0; let mut equivalent: UnsafeMap = UnsafeMap::new(); let before_equivalent: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)); @@ -208,53 +157,19 @@ unsafe fn main_0() -> i32 { let reused: bool = ((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == ((before_equivalent) + (1))); ok = ((ok as i32) & (reused as i32)) != 0; - match ({ (((equivalent.len()) == (1_usize)) as i32) }, &mut (ok)) { - (__tmp_18, __tmp_19) => { - (*__tmp_19) = (((*__tmp_19) as i32) & (__tmp_18 as i32)) != 0; - } - }; + ok = ((ok as i32) & (((equivalent.len()) == (1_usize)) as i32)) != 0; if reused { - match ({ ((first_it != equivalent.end()) as i32) }, &mut (ok)) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = (((*__tmp_21) as i32) & (__tmp_20 as i32)) != 0; - } - }; + ok = ((ok as i32) & ((first_it != equivalent.end()) as i32)) != 0; ok = ((ok as i32) & (((first) == (second)) as i32)) != 0; - match ( - { ((first_it == equivalent.find(&equivalent_a)) as i32) }, - &mut (ok), - ) { - (__tmp_22, __tmp_23) => { - (*__tmp_23) = (((*__tmp_23) as i32) & (__tmp_22 as i32)) != 0; - } - }; - match ( - { ((first_it == equivalent.find(&equivalent_b)) as i32) }, - &mut (ok), - ) { - (__tmp_24, __tmp_25) => { - (*__tmp_25) = (((*__tmp_25) as i32) & (__tmp_24 as i32)) != 0; - } - }; - match ( - { (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32) }, - &mut (ok), - ) { - (__tmp_26, __tmp_27) => { - (*__tmp_27) = (((*__tmp_27) as i32) & (__tmp_26 as i32)) != 0; - } - }; - match ( - { - (((((*first_it.iter_deref()).1.value) == (31)) && (((*second).value) == (31))) - as i32) - }, - &mut (ok), - ) { - (__tmp_28, __tmp_29) => { - (*__tmp_29) = (((*__tmp_29) as i32) & (__tmp_28 as i32)) != 0; - } - }; + ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_a)) as i32)) != 0; + ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_b)) as i32)) != 0; + ok = ((ok as i32) + & (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32)) + != 0; + ok = ((ok as i32) + & (((((*first_it.iter_deref()).1.value) == (31)) && (((*second).value) == (31))) + as i32)) + != 0; let mut equivalent_count: usize = 0_usize; 'loop_: for entry in IterRange::new(equivalent.begin(), equivalent.end()) { let entry: *const (Key, Mapped) = &(*entry.iter_deref()); @@ -265,19 +180,12 @@ unsafe fn main_0() -> i32 { } ok = ((ok as i32) & (((equivalent_count) == (1_usize)) as i32)) != 0; } - match ( - { - (!(unsafe { - let _a: *const Key = &equivalent_a; - operator_eq_2(_a, &equivalent_b) - }) as i32) - }, - &mut (ok), - ) { - (__tmp_30, __tmp_31) => { - (*__tmp_31) = (((*__tmp_31) as i32) & (__tmp_30 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (!(unsafe { + let _a: *const Key = &equivalent_a; + operator_eq_2(_a, &equivalent_b) + }) as i32)) + != 0; let later_key: Key = Key { order: 4, identity: 10, @@ -288,36 +196,13 @@ unsafe fn main_0() -> i32 { & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == ((before_equivalent) + (2))) as i32)) != 0; - match ({ (((equivalent.len()) == (2_usize)) as i32) }, &mut (ok)) { - (__tmp_32, __tmp_33) => { - (*__tmp_33) = (((*__tmp_33) as i32) & (__tmp_32 as i32)) != 0; - } - }; + ok = ((ok as i32) & (((equivalent.len()) == (2_usize)) as i32)) != 0; if reused { - match ( - { ((first_it == equivalent.find(&equivalent_a)) as i32) }, - &mut (ok), - ) { - (__tmp_34, __tmp_35) => { - (*__tmp_35) = (((*__tmp_35) as i32) & (__tmp_34 as i32)) != 0; - } - }; - match ( - { (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32) }, - &mut (ok), - ) { - (__tmp_36, __tmp_37) => { - (*__tmp_37) = (((*__tmp_37) as i32) & (__tmp_36 as i32)) != 0; - } - }; - match ( - { ((((*first_it.iter_deref()).1.value) == (31)) as i32) }, - &mut (ok), - ) { - (__tmp_38, __tmp_39) => { - (*__tmp_39) = (((*__tmp_39) as i32) & (__tmp_38 as i32)) != 0; - } - }; + ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_a)) as i32)) != 0; + ok = ((ok as i32) + & (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32)) + != 0; + ok = ((ok as i32) & ((((*first_it.iter_deref()).1.value) == (31)) as i32)) != 0; } let matching_a: Key = Key { order: 5, @@ -348,71 +233,25 @@ unsafe fn main_0() -> i32 { & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == ((before_matching) + (1))) as i32)) != 0; - match ({ (((matching.len()) == (1_usize)) as i32) }, &mut (ok)) { - (__tmp_40, __tmp_41) => { - (*__tmp_41) = (((*__tmp_41) as i32) & (__tmp_40 as i32)) != 0; - } - }; + ok = ((ok as i32) & (((matching.len()) == (1_usize)) as i32)) != 0; ok = ((ok as i32) & (((matched) == (matched_again)) as i32)) != 0; - match ( - { ((matched_it == matching.find(&matching_b)) as i32) }, - &mut (ok), - ) { - (__tmp_42, __tmp_43) => { - (*__tmp_43) = (((*__tmp_43) as i32) & (__tmp_42 as i32)) != 0; - } - }; - match ( - { (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32) }, - &mut (ok), - ) { - (__tmp_44, __tmp_45) => { - (*__tmp_45) = (((*__tmp_45) as i32) & (__tmp_44 as i32)) != 0; - } - }; - match ( - { ((((*matched_it.iter_deref()).1.value) == (51)) as i32) }, - &mut (ok), - ) { - (__tmp_46, __tmp_47) => { - (*__tmp_47) = (((*__tmp_47) as i32) & (__tmp_46 as i32)) != 0; - } - }; + ok = ((ok as i32) & ((matched_it == matching.find(&matching_b)) as i32)) != 0; + ok = ((ok as i32) + & (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32)) + != 0; + ok = ((ok as i32) & ((((*matched_it.iter_deref()).1.value) == (51)) as i32)) != 0; let other: *mut Mapped = &mut (*matching.subscript(&matching_c, || ::default())); (*other).value = 61; ok = ((ok as i32) & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == ((before_matching) + (2))) as i32)) != 0; - match ({ (((matching.len()) == (2_usize)) as i32) }, &mut (ok)) { - (__tmp_48, __tmp_49) => { - (*__tmp_49) = (((*__tmp_49) as i32) & (__tmp_48 as i32)) != 0; - } - }; - match ( - { ((matched_it == matching.find(&matching_a)) as i32) }, - &mut (ok), - ) { - (__tmp_50, __tmp_51) => { - (*__tmp_51) = (((*__tmp_51) as i32) & (__tmp_50 as i32)) != 0; - } - }; - match ( - { (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32) }, - &mut (ok), - ) { - (__tmp_52, __tmp_53) => { - (*__tmp_53) = (((*__tmp_53) as i32) & (__tmp_52 as i32)) != 0; - } - }; - match ( - { ((((*matched_it.iter_deref()).1.value) == (51)) as i32) }, - &mut (ok), - ) { - (__tmp_54, __tmp_55) => { - (*__tmp_55) = (((*__tmp_55) as i32) & (__tmp_54 as i32)) != 0; - } - }; + ok = ((ok as i32) & (((matching.len()) == (2_usize)) as i32)) != 0; + ok = ((ok as i32) & ((matched_it == matching.find(&matching_a)) as i32)) != 0; + ok = ((ok as i32) + & (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32)) + != 0; + ok = ((ok as i32) & ((((*matched_it.iter_deref()).1.value) == (51)) as i32)) != 0; return if ok { 0 } else { 1 }; } pub unsafe fn __cpp2rust_init_globals() { diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index 1d3e9412b5..e32a166f94 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -208,53 +208,25 @@ unsafe fn main_0() -> i32 { != 0; let mut found: bool = result.0 == m.find(&key); ok = ((ok as i32) & (found as i32)) != 0; - match ( - { - ((((*result.0.iter_deref()).0) == (key)) - as i32) - }, - &mut (ok), - ) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as i32) - & (__tmp_6 as i32)) - != 0; - } - }; - match ( - { - ((((*result.0.iter_deref()).1) - == (if hit { - ((10) + (key)) - } else { - ((initial) - + (!(post != 0) as i32)) - })) - as i32) - }, - &mut (ok), - ) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as i32) - & (__tmp_8 as i32)) - != 0; - } - }; - match ( - { - (((m.len()) - == (((size) + (!(hit) as i32)) - as usize)) - as i32) - }, - &mut (ok), - ) { - (__tmp_10, __tmp_11) => { - (*__tmp_11) = (((*__tmp_11) as i32) - & (__tmp_10 as i32)) - != 0; - } - }; + ok = ((ok as i32) + & ((((*result.0.iter_deref()).0) == (key)) + as i32)) + != 0; + ok = ((ok as i32) + & ((((*result.0.iter_deref()).1) + == (if hit { + ((10) + (key)) + } else { + ((initial) + (!(post != 0) as i32)) + })) + as i32)) + != 0; + ok = ((ok as i32) + & (((m.len()) + == (((size) + (!(hit) as i32)) + as usize)) + as i32)) + != 0; rows.prefix_inc(); } post.prefix_inc(); @@ -276,23 +248,16 @@ unsafe fn main_0() -> i32 { let mut key: i32 = 0; items.try_emplace(key, || Item::new_1({ 10 })); let mut source: Item = Item::new_1({ 20 }); - (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = match ( - { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)), - ) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = __tmp_12; - (*__tmp_13).clone() - } + (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) }; let mut hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { argument_4(&mut source) }) as *mut Item),) { - (__tmp_14,) => items.try_emplace(key, || Item::copy_from({ __tmp_14 })), + (__tmp_6,) => items.try_emplace(key, || Item::copy_from({ __tmp_6 })), }; ok = ((ok as i32) & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (1)) @@ -301,17 +266,10 @@ unsafe fn main_0() -> i32 { && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) as i32)) != 0; - match ( - { (((!(hit.1)) && (((*hit.0.iter_deref()).1.value) == (10))) as i32) }, - &mut (ok), - ) { - (__tmp_15, __tmp_16) => { - (*__tmp_16) = (((*__tmp_16) as i32) & (__tmp_15 as i32)) != 0; - } - }; + ok = ((ok as i32) & (((!(hit.1)) && (((*hit.0.iter_deref()).1.value) == (10))) as i32)) != 0; let mut move_hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { argument_4(&mut source) }) as *mut Item),) { - (__tmp_17,) => items.try_emplace(key, || Item::move_from({ __tmp_17 })), + (__tmp_7,) => items.try_emplace(key, || Item::move_from({ __tmp_7 })), }; ok = ((ok as i32) & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (2)) @@ -324,7 +282,7 @@ unsafe fn main_0() -> i32 { key.prefix_inc(); let mut copied: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { argument_4(&mut source) }) as *mut Item),) { - (__tmp_18,) => items.try_emplace(key, || Item::copy_from({ __tmp_18 })), + (__tmp_8,) => items.try_emplace(key, || Item::copy_from({ __tmp_8 })), }; ok = ((ok as i32) & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (3)) @@ -333,18 +291,11 @@ unsafe fn main_0() -> i32 { && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (0))) as i32)) != 0; - match ( - { (((copied.1) && (((*copied.0.iter_deref()).1.value) == (20))) as i32) }, - &mut (ok), - ) { - (__tmp_19, __tmp_20) => { - (*__tmp_20) = (((*__tmp_20) as i32) & (__tmp_19 as i32)) != 0; - } - }; + ok = ((ok as i32) & (((copied.1) && (((*copied.0.iter_deref()).1.value) == (20))) as i32)) != 0; key.prefix_inc(); let mut moved: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = match (((unsafe { argument_4(&mut source) }) as *mut Item),) { - (__tmp_21,) => items.try_emplace(key, || Item::move_from({ __tmp_21 })), + (__tmp_9,) => items.try_emplace(key, || Item::move_from({ __tmp_9 })), }; ok = ((ok as i32) & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (4)) @@ -353,17 +304,10 @@ unsafe fn main_0() -> i32 { && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (1))) as i32)) != 0; - match ( - { - ((((moved.1) && (((*moved.0.iter_deref()).1.value) == (20))) - && ((source.value) == (-1_i32))) as i32) - }, - &mut (ok), - ) { - (__tmp_22, __tmp_23) => { - (*__tmp_23) = (((*__tmp_23) as i32) & (__tmp_22 as i32)) != 0; - } - }; + ok = ((ok as i32) + & ((((moved.1) && (((*moved.0.iter_deref()).1.value) == (20))) + && ((source.value) == (-1_i32))) as i32)) + != 0; let mut refs: UnsafeMap = UnsafeMap::new(); key = 0; let mut counter: i32 = 0; @@ -371,7 +315,7 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = 0; let mut ref_hit: (UnsafeBidirectionalIterator<(i32, RefItem)>, bool) = match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { - (__tmp_24,) => refs.try_emplace(key, || RefItem::new_2({ __tmp_24 }, { 2 })), + (__tmp_10,) => refs.try_emplace(key, || RefItem::new_2({ __tmp_10 }, { 2 })), }; ok = ((ok as i32) & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (5)) @@ -382,7 +326,7 @@ unsafe fn main_0() -> i32 { key.prefix_inc(); let mut ref_new: (UnsafeBidirectionalIterator<(i32, RefItem)>, bool) = match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { - (__tmp_25,) => refs.try_emplace(key, || RefItem::new_2({ __tmp_25 }, { 2 })), + (__tmp_11,) => refs.try_emplace(key, || RefItem::new_2({ __tmp_11 }, { 2 })), }; ok = ((ok as i32) & ((((((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (6)) @@ -390,40 +334,26 @@ unsafe fn main_0() -> i32 { && ((*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) == (1))) && (ref_new.1)) as i32)) != 0; - match ( - { - (((((*ref_hit.0.iter_deref()).1.value) == (5)) - && (((*ref_new.0.iter_deref()).1.value) == (7))) as i32) - }, - &mut (ok), - ) { - (__tmp_26, __tmp_27) => { - (*__tmp_27) = (((*__tmp_27) as i32) & (__tmp_26 as i32)) != 0; - } - }; + ok = ((ok as i32) + & (((((*ref_hit.0.iter_deref()).1.value) == (5)) + && (((*ref_new.0.iter_deref()).1.value) == (7))) as i32)) + != 0; key = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = match ( - { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)), - ) { - (__tmp_28, __tmp_29) => { - (*__tmp_29) = __tmp_28; - (*__tmp_29).clone() - } + (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) }; let mut temporary_hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { - let mut __tmp_31: Item; + let mut __tmp_13: Item; match (({ - __tmp_31 = Item::new_1({ 30 }); - &mut __tmp_31 + __tmp_13 = Item::new_1({ 30 }); + &mut __tmp_13 } as *mut Item),) { - (__tmp_30,) => items.try_emplace(key, || Item::move_from({ __tmp_30 })), + (__tmp_12,) => items.try_emplace(key, || Item::move_from({ __tmp_12 })), } }; ok = ((ok as i32) @@ -436,13 +366,13 @@ unsafe fn main_0() -> i32 { key.prefix_inc(); key.prefix_inc(); let mut temporary_new: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { - let mut __tmp_33: Item; + let mut __tmp_15: Item; match (({ - __tmp_33 = Item::new_1({ 40 }); - &mut __tmp_33 + __tmp_15 = Item::new_1({ 40 }); + &mut __tmp_15 } as *mut Item),) { - (__tmp_32,) => items.try_emplace(key, || Item::move_from({ __tmp_32 })), + (__tmp_14,) => items.try_emplace(key, || Item::move_from({ __tmp_14 })), } }; ok = ((ok as i32) @@ -451,14 +381,7 @@ unsafe fn main_0() -> i32 { && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (1))) && (temporary_new.1)) as i32)) != 0; - match ( - { ((((*temporary_new.0.iter_deref()).1.value) == (40)) as i32) }, - &mut (ok), - ) { - (__tmp_34, __tmp_35) => { - (*__tmp_35) = (((*__tmp_35) as i32) & (__tmp_34 as i32)) != 0; - } - }; + ok = ((ok as i32) & ((((*temporary_new.0.iter_deref()).1.value) == (40)) as i32)) != 0; (unsafe { libc::printf( c"%d %d %d %d %d\n".as_ptr() as *const libc::c_char, diff --git a/tests/unit/out/unsafe/swap_map_no_copy.rs b/tests/unit/out/unsafe/swap_map_no_copy.rs index 5688320e22..11750e8377 100644 --- a/tests/unit/out/unsafe/swap_map_no_copy.rs +++ b/tests/unit/out/unsafe/swap_map_no_copy.rs @@ -330,19 +330,12 @@ pub unsafe fn swapped_once_6() -> bool { let mut ok: bool = (((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (1)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_4)) == (2))) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moved_dtors_5)) == (1)); - (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) = match ( - { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut moved_dtors_5)) = 0; - (*std::cell::LazyCell::force_mut(&mut *&raw mut moved_dtors_5)) - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_4)), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_4)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut moved_dtors_5)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut moved_dtors_5)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_4)) }; return ok; } diff --git a/tests/unit/out/unsafe/va_arg_concat.rs b/tests/unit/out/unsafe/va_arg_concat.rs index 3d5ba99299..dc98f83d09 100644 --- a/tests/unit/out/unsafe/va_arg_concat.rs +++ b/tests/unit/out/unsafe/va_arg_concat.rs @@ -11,11 +11,9 @@ pub unsafe fn sum_ints_0(mut first: i32, __args: Box<[VaArg]>) -> i32 { let mut total: i32 = first; args = __args.as_ptr(); let mut val: i32 = 0_i32; - 'loop_: while ((match ({ args.arg::() }, &mut (val)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + 'loop_: while (({ + val = args.arg::(); + val }) != (0)) { total += val; diff --git a/tests/unit/out/unsafe/va_arg_two_passes.rs b/tests/unit/out/unsafe/va_arg_two_passes.rs index 29feeb5f95..67ae4375b1 100644 --- a/tests/unit/out/unsafe/va_arg_two_passes.rs +++ b/tests/unit/out/unsafe/va_arg_two_passes.rs @@ -12,21 +12,17 @@ pub unsafe fn sum_then_product_0(mut first: i32, __args: Box<[VaArg]>) -> i32 { let mut product: i32 = first; ap = __args.as_ptr(); let mut val: i32 = 0_i32; - 'loop_: while ((match ({ ap.arg::() }, &mut (val)) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = __tmp_0; - (*__tmp_1).clone() - } + 'loop_: while (({ + val = ap.arg::(); + val }) != (0)) { sum += val; } ap = __args.as_ptr(); - 'loop_: while ((match ({ ap.arg::() }, &mut (val)) { - (__tmp_2, __tmp_3) => { - (*__tmp_3) = __tmp_2; - (*__tmp_3).clone() - } + 'loop_: while (({ + val = ap.arg::(); + val }) != (0)) { product *= val; diff --git a/tests/unit/out/unsafe/vector_subscript_borrow.rs b/tests/unit/out/unsafe/vector_subscript_borrow.rs index 2642c116a0..34ffb4636b 100644 --- a/tests/unit/out/unsafe/vector_subscript_borrow.rs +++ b/tests/unit/out/unsafe/vector_subscript_borrow.rs @@ -29,11 +29,7 @@ unsafe fn main_0() -> i32 { i.prefix_inc(); } } - match ({ 5_u32 }, &mut (items[(1_usize)])) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; - } - }; + items[(1_usize)] = (items[(1_usize)]).wrapping_add(5_u32); items[(2_usize)].postfix_inc(); assert!( (((items[(0_usize)]) == (0_u32)) && ((items[(1_usize)]) == (7_u32))) From cfe7719988919690da0f2b0076775d72953a4c5c Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Thu, 26 Nov 2026 03:04:23 +0000 Subject: [PATCH 06/25] Limit assignment alias analysis to the current function Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 15 +- cpp2rust/converter/converter.h | 3 + cpp2rust/converter/models/boxed_vars.cpp | 7 +- cpp2rust/converter/models/boxed_vars.h | 1 + .../converter/models/converter_refcount.cpp | 20 +- tests/unit/assignment_single_eval.cpp | 47 +++ .../out/refcount/assignment_single_eval.rs | 289 +++++++++++++++++- .../unit/out/unsafe/assignment_single_eval.rs | 255 +++++++++++++++- 8 files changed, 623 insertions(+), 14 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 3d10776f0e..89a11e168b 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -4990,11 +4990,20 @@ bool Converter::NeedsAssignmentBinding( if (!rhs_effects) { return false; } + if (!(var->isLocalVarDecl() || clang::isa(var)) || + IsGlobalVar(var) || !curr_function_) { + return true; + } if (!GetAllVars(rhs).contains(var)) { - if (!boxed_vars_) { - boxed_vars_ = std::make_shared(ctx_); + auto *vars = boxed_vars_.get(); + if (!vars) { + auto &cached = assignment_vars_[curr_function_]; + if (!cached) { + cached = std::make_shared(ctx_, curr_function_); + } + vars = cached.get(); } - if (!boxed_vars_->contains(var)) { + if (!vars->contains(var)) { return false; } } diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 983b010078..f7e95e4964 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -1053,6 +1053,9 @@ class Converter : public clang::RecursiveASTVisitor { std::string *rs_code_; clang::ASTContext &ctx_; std::shared_ptr boxed_vars_; + std::unordered_map> + assignment_vars_; std::unique_ptr mangle_context_; clang::FunctionDecl *curr_function_ = nullptr; clang::Expr *return_value_ = nullptr; diff --git a/cpp2rust/converter/models/boxed_vars.cpp b/cpp2rust/converter/models/boxed_vars.cpp index 42f1b130a6..dd89521f32 100644 --- a/cpp2rust/converter/models/boxed_vars.cpp +++ b/cpp2rust/converter/models/boxed_vars.cpp @@ -490,9 +490,12 @@ class AddressTakenVisitor }; } // namespace -BoxedVars::BoxedVars(clang::ASTContext &ctx) : ctx_(ctx) { +BoxedVars::BoxedVars(clang::ASTContext &ctx) + : BoxedVars(ctx, ctx.getTranslationUnitDecl()) {} + +BoxedVars::BoxedVars(clang::ASTContext &ctx, clang::Decl *scope) : ctx_(ctx) { AddressTakenVisitor(ctx, address_taken_, range_iterators_) - .TraverseDecl(ctx.getTranslationUnitDecl()); + .TraverseDecl(scope); } bool BoxedVars::contains(const clang::VarDecl *decl) const { diff --git a/cpp2rust/converter/models/boxed_vars.h b/cpp2rust/converter/models/boxed_vars.h index ba92d82528..d2576b5e45 100644 --- a/cpp2rust/converter/models/boxed_vars.h +++ b/cpp2rust/converter/models/boxed_vars.h @@ -22,6 +22,7 @@ namespace cpp2rust { class BoxedVars { public: explicit BoxedVars(clang::ASTContext &ctx); + BoxedVars(clang::ASTContext &ctx, clang::Decl *scope); bool contains(const clang::VarDecl *decl) const; diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index d2468bd469..056bc3863c 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -2499,7 +2499,17 @@ void ConverterRefCount::ConvertAssignment( auto left = NewTempName(); auto rhs_value = ConvertFreshRValue( rhs, compound ? std::nullopt : std::optional(lhs->getType())); - auto lhs_value = ConvertLValue(lhs); + std::string lhs_value; + auto *subscript = + clang::dyn_cast(lhs->IgnoreParenImpCasts()); + if (subscript && !IsPointerSubscript(subscript) && !IsUnboxedPlace(lhs)) { + // Resolve the index before borrowing the array, as it may read the same + // storage. The pointer keeps the selected element, not an active borrow. + auto ptr = ConvertFreshPointer(lhs); + pending_deref_.set(std::move(ptr), /*fresh=*/true); + } else { + lhs_value = ConvertLValue(lhs); + } auto read = std::format("(*{})", left); auto value = compound ? ConvertCompoundAssignValue(compound, read, right) : right; @@ -2507,8 +2517,12 @@ void ConverterRefCount::ConvertAssignment( // after the right operand, keeping its temporaries alive through the write. StrCat("match ({ ", rhs_value, " }, "); bool through_pointer = !pending_deref_.empty(); - StrCat(through_pointer ? "&" : "&mut "); - { + if (subscript && !IsPointerSubscript(subscript) && !IsUnboxedPlace(lhs)) { + // End incidental index borrows before with_mut takes the write borrow. + StrCat("{ let ", left, token::kAssign, pending_deref_.take(), + token::kSemiColon, left, "}"); + } else { + StrCat(through_pointer ? "&" : "&mut "); PushParen paren(*this); StrCat(through_pointer ? pending_deref_.take() : lhs_value); } diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index 0b615b7fc4..af15d8dfb3 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -131,6 +131,48 @@ void test_binding() { std::printf("binding compound %u %u\n", result, selected_values[0]); } +unsigned initializer_target = 10; +unsigned mutate_initializer() { + initializer_target = 20; + return 1; +} +unsigned initializer_result = (initializer_target += mutate_initializer()); + +void test_alias_scopes(short parameter) { + short *p = ¶meter; + short result = (parameter += (*p = -1, 0.5)); + std::printf("parameter %d %d\n", int(result), int(parameter)); + short local = 10; + auto mutate = [&local]() { + local = -1; + return 0.5; + }; + result = (local += mutate()); + std::printf("capture %d %d\n", int(result), int(local)); + short addressed = 10; + auto address = [&addressed]() { return &addressed; }; + result = (addressed += (*address() = -1, 0.5)); + std::printf("lambda address %d %d\n", int(result), int(addressed)); + std::printf("initializer %u %u\n", initializer_result, initializer_target); +} + +template void test_boxed_array() { + T a[3] = {0, 20, 30}; + T *p = a; + int i = 0; + T result = (a[a[i++]] += 1); + std::printf("boxed compound %d %d %d %d\n", i, int(result), int(a[0]), + int(*p)); + a[0] = 0; + i = 0; + result = (a[a[i++]] = 1); + std::printf("boxed simple %d %d %d %d\n", i, int(result), int(a[0]), int(*p)); + static T saved[3] = {0, 20, 30}; + result = (saved[saved[0]] += 1); + std::printf("static array %d %d\n", int(result), int(saved[0])); +} +unsigned global_array[3] = {0, 20, 30}; + int main() { test(); test(); @@ -144,5 +186,10 @@ int main() { std::printf("array reference %d %u %u\n", i, result, values[0]); test_borrows(); test_binding(); + test_alias_scopes(10); + test_boxed_array(); + test_boxed_array(); + unsigned global_result = (global_array[global_array[0]] += 1); + std::printf("global array %u %u\n", global_result, global_array[0]); return 0; } diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 239607dd9e..2ffca5c48c 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -830,6 +830,259 @@ pub fn test_binding_18() { }) ); } +thread_local!( + pub static initializer_target_20: Value = Rc::new(RefCell::new(10_u32)); +); +pub fn mutate_initializer_21() -> u32 { + initializer_target_20.with(|rc| *rc.borrow_mut() = 20_u32); + return 1_u32; +} +thread_local!( + pub static initializer_result_22: Value = Rc::new(RefCell::new( + ({ + let __tmp_67 = ({ mutate_initializer_21() }); + { + let rhs_0 = ((initializer_target_20.with(|rc| *rc.borrow()) as u32) + .wrapping_add((__tmp_67 as u32))) as u32; + { + let __rhs = rhs_0; + initializer_target_20.with(|rc| *rc.borrow_mut() = __rhs) + }; + initializer_target_20.with(|rc| *rc.borrow()) + } + }), + )); +); +pub fn test_alias_scopes_23(parameter: i16) { + let parameter: Value = Rc::new(RefCell::new(parameter)); + let mut p: Ptr = (parameter.as_pointer()); + let mut result: i16 = ({ + match ( + { + { + p.write((-1_i32 as i16)); + 0.5_f64 + } + }, + &mut (*parameter.borrow_mut()), + ) { + (__tmp_68, __tmp_69) => { + (*__tmp_69) = (((*__tmp_69) as f64) + (__tmp_68 as f64)) as i16; + (*__tmp_69).clone() + } + } + }); + printf!( + b"parameter %d %d\n", + (result as i32), + ((*parameter.borrow()) as i32) + ); + let local: Value = Rc::new(RefCell::new(10_i16)); + let mutate: Value f64>> = Rc::new(RefCell::new(lambda!( + { + let local: Ptr = local.as_pointer(); + }, + || -> f64 { + local.write((-1_i32 as i16)); + return 0.5_f64; + } + ))); + result = ({ + match ( + { ({ (*mutate.borrow()).call() }).clone() }, + &mut (*local.borrow_mut()), + ) { + (__tmp_70, __tmp_71) => { + (*__tmp_71) = (((*__tmp_71) as f64) + (__tmp_70 as f64)) as i16; + (*__tmp_71).clone() + } + } + }); + printf!( + b"capture %d %d\n", + (result as i32), + ((*local.borrow()) as i32) + ); + let addressed: Value = Rc::new(RefCell::new(10_i16)); + let address: Value Ptr>> = Rc::new(RefCell::new(lambda!( + { + let addressed: Ptr = addressed.as_pointer(); + }, + || -> Ptr { + return (addressed).clone(); + } + ))); + result = ({ + match ( + { + { + ({ (*address.borrow()).call() }).write((-1_i32 as i16)); + 0.5_f64 + } + }, + &mut (*addressed.borrow_mut()), + ) { + (__tmp_72, __tmp_73) => { + (*__tmp_73) = (((*__tmp_73) as f64) + (__tmp_72 as f64)) as i16; + (*__tmp_73).clone() + } + } + }); + printf!( + b"lambda address %d %d\n", + (result as i32), + ((*addressed.borrow()) as i32) + ); + printf!( + b"initializer %u %u\n", + initializer_result_22.with(|rc| *rc.borrow()), + initializer_target_20.with(|rc| *rc.borrow()) + ); +} +pub fn test_boxed_array_24() { + let a: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); + let mut p: Ptr = a.decay(); + let mut i: i32 = 0; + let mut result: u32 = ({ + match ({ 1_u32 }, { + let __tmp_75 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_75 + }) { + (__tmp_74, __tmp_75) => __tmp_75.with_mut(|__tmp_75| { + (*__tmp_75) = (((*__tmp_75) as u32).wrapping_add((__tmp_74 as u32))) as u32; + (*__tmp_75).clone() + }), + } + }); + printf!( + b"boxed compound %d %d %d %d\n", + i, + (result as i32), + ((*a.borrow())[(0) as usize] as i32), + ((p.read()) as i32) + ); + (*a.borrow_mut())[(0) as usize] = 0_u32; + i = 0; + result = ({ + match ({ 1_u32 }, { + let __tmp_77 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_77 + }) { + (__tmp_76, __tmp_77) => __tmp_77.with_mut(|__tmp_77| { + (*__tmp_77) = __tmp_76; + (*__tmp_77).clone() + }), + } + }); + printf!( + b"boxed simple %d %d %d %d\n", + i, + (result as i32), + ((*a.borrow())[(0) as usize] as i32), + ((p.read()) as i32) + ); + result = ({ + match ({ 1_u32 }, { + let __tmp_79 = saved_25.with(|v| v.decay()).offset( + ({ + let __idx0 = (0) as usize; + saved_25.with(|rc| rc.borrow()[__idx0]) + }), + ); + __tmp_79 + }) { + (__tmp_78, __tmp_79) => __tmp_79.with_mut(|__tmp_79| { + (*__tmp_79) = (((*__tmp_79) as u32).wrapping_add((__tmp_78 as u32))) as u32; + (*__tmp_79).clone() + }), + } + }); + printf!( + b"static array %d %d\n", + (result as i32), + (({ + let __idx0 = (0) as usize; + saved_25.with(|rc| rc.borrow()[__idx0]) + }) as i32) + ); +} +pub fn test_boxed_array_26() { + let a: Value> = Rc::new(RefCell::new(Box::new([0_i16, 20_i16, 30_i16]))); + let mut p: Ptr = a.decay(); + let mut i: i32 = 0; + let mut result: i16 = ({ + match ({ 1 }, { + let __tmp_81 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_81 + }) { + (__tmp_80, __tmp_81) => __tmp_81.with_mut(|__tmp_81| { + (*__tmp_81) = (((*__tmp_81) as i32) + (__tmp_80 as i32)) as i16; + (*__tmp_81).clone() + }), + } + }); + printf!( + b"boxed compound %d %d %d %d\n", + i, + (result as i32), + ((*a.borrow())[(0) as usize] as i32), + ((p.read()) as i32) + ); + (*a.borrow_mut())[(0) as usize] = 0_i16; + i = 0; + result = ({ + match ({ 1_i16 }, { + let __tmp_83 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_83 + }) { + (__tmp_82, __tmp_83) => __tmp_83.with_mut(|__tmp_83| { + (*__tmp_83) = __tmp_82; + (*__tmp_83).clone() + }), + } + }); + printf!( + b"boxed simple %d %d %d %d\n", + i, + (result as i32), + ((*a.borrow())[(0) as usize] as i32), + ((p.read()) as i32) + ); + result = ({ + match ({ 1 }, { + let __tmp_85 = saved_27.with(|v| v.decay()).offset( + ({ + let __idx0 = (0) as usize; + saved_27.with(|rc| rc.borrow()[__idx0]) + }), + ); + __tmp_85 + }) { + (__tmp_84, __tmp_85) => __tmp_85.with_mut(|__tmp_85| { + (*__tmp_85) = (((*__tmp_85) as i32) + (__tmp_84 as i32)) as i16; + (*__tmp_85).clone() + }), + } + }); + printf!( + b"static array %d %d\n", + (result as i32), + (({ + let __idx0 = (0) as usize; + saved_27.with(|rc| rc.borrow()[__idx0]) + }) as i32) + ); +} +thread_local!( + static saved_25: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); +); +thread_local!( + static saved_27: Value> = Rc::new(RefCell::new(Box::new([0_i16, 20_i16, 30_i16]))); +); +thread_local!( + pub static global_array_28: Value> = + Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); +); pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -854,9 +1107,9 @@ fn main_0() -> i32 { 0 )), ) { - (__tmp_67, __tmp_68) => __tmp_68.with_mut(|__tmp_68| { - (*__tmp_68) = (((*__tmp_68) as u32).wrapping_add((__tmp_67 as u32))) as u32; - (*__tmp_68).clone() + (__tmp_86, __tmp_87) => __tmp_87.with_mut(|__tmp_87| { + (*__tmp_87) = (((*__tmp_87) as u32).wrapping_add((__tmp_86 as u32))) as u32; + (*__tmp_87).clone() }), } }); @@ -868,6 +1121,33 @@ fn main_0() -> i32 { ); ({ test_borrows_12() }); ({ test_binding_18() }); + ({ test_alias_scopes_23(10_i16) }); + ({ test_boxed_array_24() }); + ({ test_boxed_array_26() }); + let mut global_result: u32 = ({ + match ({ 1_u32 }, { + let __tmp_89 = global_array_28.with(|v| v.decay()).offset( + ({ + let __idx0 = (0) as usize; + global_array_28.with(|rc| rc.borrow()[__idx0]) + }), + ); + __tmp_89 + }) { + (__tmp_88, __tmp_89) => __tmp_89.with_mut(|__tmp_89| { + (*__tmp_89) = (((*__tmp_89) as u32).wrapping_add((__tmp_88 as u32))) as u32; + (*__tmp_89).clone() + }), + } + }); + printf!( + b"global array %u %u\n", + global_result, + ({ + let __idx0 = (0) as usize; + global_array_28.with(|rc| rc.borrow()[__idx0]) + }) + ); return 0; } pub trait IndexedBindingImpl { @@ -889,4 +1169,7 @@ pub fn __cpp2rust_init_globals() { let _ = targets_10.with(|_| ()); let _ = cursor_11.with(|_| ()); let _ = selected_values_17.with(|_| ()); + let _ = initializer_target_20.with(|_| ()); + let _ = initializer_result_22.with(|_| ()); + let _ = global_array_28.with(|_| ()); } diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index ba51d76bc8..127a9826c9 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -921,6 +921,231 @@ pub unsafe fn test_binding_18() { ) }); } +pub static mut initializer_target_20: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 10_u32 }); +pub unsafe fn mutate_initializer_21() -> u32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_20)) = 20_u32; + return 1_u32; +} +pub static mut initializer_result_22: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { + (match ( + { (unsafe { mutate_initializer_21() }) }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_20)), + ) { + (__tmp_70, __tmp_71) => { + (*__tmp_71) = (((*__tmp_71) as u32).wrapping_add((__tmp_70 as u32))) as u32; + (*__tmp_71).clone() + } + }) + }); +pub unsafe fn test_alias_scopes_23(mut parameter: i16) { + let mut p: *mut i16 = (&mut parameter as *mut i16); + let mut result: i16 = (match ( + { + { + (*p) = (-1_i32 as i16); + 0.5_f64 + } + }, + &mut (parameter), + ) { + (__tmp_72, __tmp_73) => { + (*__tmp_73) = (((*__tmp_73) as f64) + (__tmp_72 as f64)) as i16; + (*__tmp_73).clone() + } + }); + (unsafe { + libc::printf( + c"parameter %d %d\n".as_ptr() as *const libc::c_char, + (result as i32), + (parameter as i32), + ) + }); + let mut local: i16 = 10_i16; + let mut mutate: FnPtr f64> = lambda_unsafe!( + { + let local: *mut i16 = &mut local; + }, + || -> f64 { + (*local) = (-1_i32 as i16); + return 0.5_f64; + } + ); + result = (match ({ (unsafe { mutate.call() }).clone() }, &mut (local)) { + (__tmp_74, __tmp_75) => { + (*__tmp_75) = (((*__tmp_75) as f64) + (__tmp_74 as f64)) as i16; + (*__tmp_75).clone() + } + }); + (unsafe { + libc::printf( + c"capture %d %d\n".as_ptr() as *const libc::c_char, + (result as i32), + (local as i32), + ) + }); + let mut addressed: i16 = 10_i16; + let mut address: FnPtr *mut i16> = lambda_unsafe!( + { + let addressed: *mut i16 = &mut addressed; + }, + || -> *mut i16 { + return (addressed); + } + ); + result = (match ( + { + { + (*(unsafe { address.call() })) = (-1_i32 as i16); + 0.5_f64 + } + }, + &mut (addressed), + ) { + (__tmp_76, __tmp_77) => { + (*__tmp_77) = (((*__tmp_77) as f64) + (__tmp_76 as f64)) as i16; + (*__tmp_77).clone() + } + }); + (unsafe { + libc::printf( + c"lambda address %d %d\n".as_ptr() as *const libc::c_char, + (result as i32), + (addressed as i32), + ) + }); + (unsafe { + libc::printf( + c"initializer %u %u\n".as_ptr() as *const libc::c_char, + (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_result_22)), + (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_20)), + ) + }); +} +pub unsafe fn test_boxed_array_24() { + let mut a: [u32; 3] = [0_u32, 20_u32, 30_u32]; + let mut p: *mut u32 = a.as_mut_ptr(); + let mut i: i32 = 0; + let mut result: u32 = (match ( + { 1_u32 }, + &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), + ) { + (__tmp_78, __tmp_79) => { + (*__tmp_79) = (((*__tmp_79) as u32).wrapping_add((__tmp_78 as u32))) as u32; + (*__tmp_79).clone() + } + }); + (unsafe { + libc::printf( + c"boxed compound %d %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (result as i32), + (a[(0) as usize] as i32), + ((*p) as i32), + ) + }); + a[(0) as usize] = 0_u32; + i = 0; + result = (match ( + { 1_u32 }, + &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), + ) { + (__tmp_80, __tmp_81) => { + (*__tmp_81) = __tmp_80; + (*__tmp_81).clone() + } + }); + (unsafe { + libc::printf( + c"boxed simple %d %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (result as i32), + (a[(0) as usize] as i32), + ((*p) as i32), + ) + }); + result = (match ( + { 1_u32 }, + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_25)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_25))[(0) as usize]) as usize]), + ) { + (__tmp_82, __tmp_83) => { + (*__tmp_83) = (((*__tmp_83) as u32).wrapping_add((__tmp_82 as u32))) as u32; + (*__tmp_83).clone() + } + }); + (unsafe { + libc::printf( + c"static array %d %d\n".as_ptr() as *const libc::c_char, + (result as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_25))[(0) as usize] as i32), + ) + }); +} +pub unsafe fn test_boxed_array_26() { + let mut a: [i16; 3] = [0_i16, 20_i16, 30_i16]; + let mut p: *mut i16 = a.as_mut_ptr(); + let mut i: i32 = 0; + let mut result: i16 = (match ({ 1 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize])) { + (__tmp_84, __tmp_85) => { + (*__tmp_85) = (((*__tmp_85) as i32) + (__tmp_84 as i32)) as i16; + (*__tmp_85).clone() + } + }); + (unsafe { + libc::printf( + c"boxed compound %d %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (result as i32), + (a[(0) as usize] as i32), + ((*p) as i32), + ) + }); + a[(0) as usize] = 0_i16; + i = 0; + result = (match ( + { 1_i16 }, + &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), + ) { + (__tmp_86, __tmp_87) => { + (*__tmp_87) = __tmp_86; + (*__tmp_87).clone() + } + }); + (unsafe { + libc::printf( + c"boxed simple %d %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (result as i32), + (a[(0) as usize] as i32), + ((*p) as i32), + ) + }); + result = (match ( + { 1 }, + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_27)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_27))[(0) as usize]) as usize]), + ) { + (__tmp_88, __tmp_89) => { + (*__tmp_89) = (((*__tmp_89) as i32) + (__tmp_88 as i32)) as i16; + (*__tmp_89).clone() + } + }); + (unsafe { + libc::printf( + c"static array %d %d\n".as_ptr() as *const libc::c_char, + (result as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_27))[(0) as usize] as i32), + ) + }); +} +static mut saved_25: std::cell::LazyCell<[u32; 3]> = + std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); +static mut saved_27: std::cell::LazyCell<[i16; 3]> = + std::cell::LazyCell::new(|| unsafe { [0_i16, 20_i16, 30_i16] }); +pub static mut global_array_28: std::cell::LazyCell<[u32; 3]> = + std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -943,9 +1168,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_70, __tmp_71) => { - (*__tmp_71) = (((*__tmp_71) as u32).wrapping_add((__tmp_70 as u32))) as u32; - (*__tmp_71).clone() + (__tmp_90, __tmp_91) => { + (*__tmp_91) = (((*__tmp_91) as u32).wrapping_add((__tmp_90 as u32))) as u32; + (*__tmp_91).clone() } }); (unsafe { @@ -958,6 +1183,27 @@ unsafe fn main_0() -> i32 { }); (unsafe { test_borrows_12() }); (unsafe { test_binding_18() }); + (unsafe { test_alias_scopes_23(10_i16) }); + (unsafe { test_boxed_array_24() }); + (unsafe { test_boxed_array_26() }); + let mut global_result: u32 = (match ( + { 1_u32 }, + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_28)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_28))[(0) as usize]) + as usize]), + ) { + (__tmp_92, __tmp_93) => { + (*__tmp_93) = (((*__tmp_93) as u32).wrapping_add((__tmp_92 as u32))) as u32; + (*__tmp_93).clone() + } + }); + (unsafe { + libc::printf( + c"global array %u %u\n".as_ptr() as *const libc::c_char, + (global_result), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_28))[(0) as usize]), + ) + }); return 0; } pub unsafe fn __cpp2rust_init_globals() { @@ -966,4 +1212,7 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const targets_10); std::cell::LazyCell::force(&*&raw const cursor_11); std::cell::LazyCell::force(&*&raw const selected_values_17); + std::cell::LazyCell::force(&*&raw const initializer_target_20); + std::cell::LazyCell::force(&*&raw const initializer_result_22); + std::cell::LazyCell::force(&*&raw const global_array_28); } From be3c309b6ba607ca51ad0a160120522925f3da28 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Thu, 26 Nov 2026 03:20:56 +0000 Subject: [PATCH 07/25] Keep the requested alias scope witnesses focused Signed-off-by: Perfloop Agent --- tests/unit/assignment_single_eval.cpp | 4 - .../out/refcount/assignment_single_eval.rs | 106 +++++++----------- .../unit/out/unsafe/assignment_single_eval.rs | 78 ++++--------- 3 files changed, 62 insertions(+), 126 deletions(-) diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index af15d8dfb3..e4c67cd2cb 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -149,10 +149,6 @@ void test_alias_scopes(short parameter) { }; result = (local += mutate()); std::printf("capture %d %d\n", int(result), int(local)); - short addressed = 10; - auto address = [&addressed]() { return &addressed; }; - result = (addressed += (*address() = -1, 0.5)); - std::printf("lambda address %d %d\n", int(result), int(addressed)); std::printf("initializer %u %u\n", initializer_result, initializer_target); } diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 2ffca5c48c..f6f2797c66 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -903,36 +903,6 @@ pub fn test_alias_scopes_23(parameter: i16) { (result as i32), ((*local.borrow()) as i32) ); - let addressed: Value = Rc::new(RefCell::new(10_i16)); - let address: Value Ptr>> = Rc::new(RefCell::new(lambda!( - { - let addressed: Ptr = addressed.as_pointer(); - }, - || -> Ptr { - return (addressed).clone(); - } - ))); - result = ({ - match ( - { - { - ({ (*address.borrow()).call() }).write((-1_i32 as i16)); - 0.5_f64 - } - }, - &mut (*addressed.borrow_mut()), - ) { - (__tmp_72, __tmp_73) => { - (*__tmp_73) = (((*__tmp_73) as f64) + (__tmp_72 as f64)) as i16; - (*__tmp_73).clone() - } - } - }); - printf!( - b"lambda address %d %d\n", - (result as i32), - ((*addressed.borrow()) as i32) - ); printf!( b"initializer %u %u\n", initializer_result_22.with(|rc| *rc.borrow()), @@ -945,12 +915,12 @@ pub fn test_boxed_array_24() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_75 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_75 + let __tmp_73 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_73 }) { - (__tmp_74, __tmp_75) => __tmp_75.with_mut(|__tmp_75| { - (*__tmp_75) = (((*__tmp_75) as u32).wrapping_add((__tmp_74 as u32))) as u32; - (*__tmp_75).clone() + (__tmp_72, __tmp_73) => __tmp_73.with_mut(|__tmp_73| { + (*__tmp_73) = (((*__tmp_73) as u32).wrapping_add((__tmp_72 as u32))) as u32; + (*__tmp_73).clone() }), } }); @@ -965,12 +935,12 @@ pub fn test_boxed_array_24() { i = 0; result = ({ match ({ 1_u32 }, { - let __tmp_77 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_77 + let __tmp_75 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_75 }) { - (__tmp_76, __tmp_77) => __tmp_77.with_mut(|__tmp_77| { - (*__tmp_77) = __tmp_76; - (*__tmp_77).clone() + (__tmp_74, __tmp_75) => __tmp_75.with_mut(|__tmp_75| { + (*__tmp_75) = __tmp_74; + (*__tmp_75).clone() }), } }); @@ -983,17 +953,17 @@ pub fn test_boxed_array_24() { ); result = ({ match ({ 1_u32 }, { - let __tmp_79 = saved_25.with(|v| v.decay()).offset( + let __tmp_77 = saved_25.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; saved_25.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_79 + __tmp_77 }) { - (__tmp_78, __tmp_79) => __tmp_79.with_mut(|__tmp_79| { - (*__tmp_79) = (((*__tmp_79) as u32).wrapping_add((__tmp_78 as u32))) as u32; - (*__tmp_79).clone() + (__tmp_76, __tmp_77) => __tmp_77.with_mut(|__tmp_77| { + (*__tmp_77) = (((*__tmp_77) as u32).wrapping_add((__tmp_76 as u32))) as u32; + (*__tmp_77).clone() }), } }); @@ -1012,12 +982,12 @@ pub fn test_boxed_array_26() { let mut i: i32 = 0; let mut result: i16 = ({ match ({ 1 }, { - let __tmp_81 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_81 + let __tmp_79 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_79 }) { - (__tmp_80, __tmp_81) => __tmp_81.with_mut(|__tmp_81| { - (*__tmp_81) = (((*__tmp_81) as i32) + (__tmp_80 as i32)) as i16; - (*__tmp_81).clone() + (__tmp_78, __tmp_79) => __tmp_79.with_mut(|__tmp_79| { + (*__tmp_79) = (((*__tmp_79) as i32) + (__tmp_78 as i32)) as i16; + (*__tmp_79).clone() }), } }); @@ -1032,12 +1002,12 @@ pub fn test_boxed_array_26() { i = 0; result = ({ match ({ 1_i16 }, { - let __tmp_83 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_83 + let __tmp_81 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_81 }) { - (__tmp_82, __tmp_83) => __tmp_83.with_mut(|__tmp_83| { - (*__tmp_83) = __tmp_82; - (*__tmp_83).clone() + (__tmp_80, __tmp_81) => __tmp_81.with_mut(|__tmp_81| { + (*__tmp_81) = __tmp_80; + (*__tmp_81).clone() }), } }); @@ -1050,17 +1020,17 @@ pub fn test_boxed_array_26() { ); result = ({ match ({ 1 }, { - let __tmp_85 = saved_27.with(|v| v.decay()).offset( + let __tmp_83 = saved_27.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; saved_27.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_85 + __tmp_83 }) { - (__tmp_84, __tmp_85) => __tmp_85.with_mut(|__tmp_85| { - (*__tmp_85) = (((*__tmp_85) as i32) + (__tmp_84 as i32)) as i16; - (*__tmp_85).clone() + (__tmp_82, __tmp_83) => __tmp_83.with_mut(|__tmp_83| { + (*__tmp_83) = (((*__tmp_83) as i32) + (__tmp_82 as i32)) as i16; + (*__tmp_83).clone() }), } }); @@ -1107,9 +1077,9 @@ fn main_0() -> i32 { 0 )), ) { - (__tmp_86, __tmp_87) => __tmp_87.with_mut(|__tmp_87| { - (*__tmp_87) = (((*__tmp_87) as u32).wrapping_add((__tmp_86 as u32))) as u32; - (*__tmp_87).clone() + (__tmp_84, __tmp_85) => __tmp_85.with_mut(|__tmp_85| { + (*__tmp_85) = (((*__tmp_85) as u32).wrapping_add((__tmp_84 as u32))) as u32; + (*__tmp_85).clone() }), } }); @@ -1126,17 +1096,17 @@ fn main_0() -> i32 { ({ test_boxed_array_26() }); let mut global_result: u32 = ({ match ({ 1_u32 }, { - let __tmp_89 = global_array_28.with(|v| v.decay()).offset( + let __tmp_87 = global_array_28.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; global_array_28.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_89 + __tmp_87 }) { - (__tmp_88, __tmp_89) => __tmp_89.with_mut(|__tmp_89| { - (*__tmp_89) = (((*__tmp_89) as u32).wrapping_add((__tmp_88 as u32))) as u32; - (*__tmp_89).clone() + (__tmp_86, __tmp_87) => __tmp_87.with_mut(|__tmp_87| { + (*__tmp_87) = (((*__tmp_87) as u32).wrapping_add((__tmp_86 as u32))) as u32; + (*__tmp_87).clone() }), } }); diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 127a9826c9..98abb5de21 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -985,36 +985,6 @@ pub unsafe fn test_alias_scopes_23(mut parameter: i16) { (local as i32), ) }); - let mut addressed: i16 = 10_i16; - let mut address: FnPtr *mut i16> = lambda_unsafe!( - { - let addressed: *mut i16 = &mut addressed; - }, - || -> *mut i16 { - return (addressed); - } - ); - result = (match ( - { - { - (*(unsafe { address.call() })) = (-1_i32 as i16); - 0.5_f64 - } - }, - &mut (addressed), - ) { - (__tmp_76, __tmp_77) => { - (*__tmp_77) = (((*__tmp_77) as f64) + (__tmp_76 as f64)) as i16; - (*__tmp_77).clone() - } - }); - (unsafe { - libc::printf( - c"lambda address %d %d\n".as_ptr() as *const libc::c_char, - (result as i32), - (addressed as i32), - ) - }); (unsafe { libc::printf( c"initializer %u %u\n".as_ptr() as *const libc::c_char, @@ -1031,9 +1001,9 @@ pub unsafe fn test_boxed_array_24() { { 1_u32 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), ) { - (__tmp_78, __tmp_79) => { - (*__tmp_79) = (((*__tmp_79) as u32).wrapping_add((__tmp_78 as u32))) as u32; - (*__tmp_79).clone() + (__tmp_76, __tmp_77) => { + (*__tmp_77) = (((*__tmp_77) as u32).wrapping_add((__tmp_76 as u32))) as u32; + (*__tmp_77).clone() } }); (unsafe { @@ -1051,9 +1021,9 @@ pub unsafe fn test_boxed_array_24() { { 1_u32 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), ) { - (__tmp_80, __tmp_81) => { - (*__tmp_81) = __tmp_80; - (*__tmp_81).clone() + (__tmp_78, __tmp_79) => { + (*__tmp_79) = __tmp_78; + (*__tmp_79).clone() } }); (unsafe { @@ -1070,9 +1040,9 @@ pub unsafe fn test_boxed_array_24() { &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_25)) [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_25))[(0) as usize]) as usize]), ) { - (__tmp_82, __tmp_83) => { - (*__tmp_83) = (((*__tmp_83) as u32).wrapping_add((__tmp_82 as u32))) as u32; - (*__tmp_83).clone() + (__tmp_80, __tmp_81) => { + (*__tmp_81) = (((*__tmp_81) as u32).wrapping_add((__tmp_80 as u32))) as u32; + (*__tmp_81).clone() } }); (unsafe { @@ -1088,9 +1058,9 @@ pub unsafe fn test_boxed_array_26() { let mut p: *mut i16 = a.as_mut_ptr(); let mut i: i32 = 0; let mut result: i16 = (match ({ 1 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize])) { - (__tmp_84, __tmp_85) => { - (*__tmp_85) = (((*__tmp_85) as i32) + (__tmp_84 as i32)) as i16; - (*__tmp_85).clone() + (__tmp_82, __tmp_83) => { + (*__tmp_83) = (((*__tmp_83) as i32) + (__tmp_82 as i32)) as i16; + (*__tmp_83).clone() } }); (unsafe { @@ -1108,9 +1078,9 @@ pub unsafe fn test_boxed_array_26() { { 1_i16 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), ) { - (__tmp_86, __tmp_87) => { - (*__tmp_87) = __tmp_86; - (*__tmp_87).clone() + (__tmp_84, __tmp_85) => { + (*__tmp_85) = __tmp_84; + (*__tmp_85).clone() } }); (unsafe { @@ -1127,9 +1097,9 @@ pub unsafe fn test_boxed_array_26() { &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_27)) [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_27))[(0) as usize]) as usize]), ) { - (__tmp_88, __tmp_89) => { - (*__tmp_89) = (((*__tmp_89) as i32) + (__tmp_88 as i32)) as i16; - (*__tmp_89).clone() + (__tmp_86, __tmp_87) => { + (*__tmp_87) = (((*__tmp_87) as i32) + (__tmp_86 as i32)) as i16; + (*__tmp_87).clone() } }); (unsafe { @@ -1168,9 +1138,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_90, __tmp_91) => { - (*__tmp_91) = (((*__tmp_91) as u32).wrapping_add((__tmp_90 as u32))) as u32; - (*__tmp_91).clone() + (__tmp_88, __tmp_89) => { + (*__tmp_89) = (((*__tmp_89) as u32).wrapping_add((__tmp_88 as u32))) as u32; + (*__tmp_89).clone() } }); (unsafe { @@ -1192,9 +1162,9 @@ unsafe fn main_0() -> i32 { [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_28))[(0) as usize]) as usize]), ) { - (__tmp_92, __tmp_93) => { - (*__tmp_93) = (((*__tmp_93) as u32).wrapping_add((__tmp_92 as u32))) as u32; - (*__tmp_93).clone() + (__tmp_90, __tmp_91) => { + (*__tmp_91) = (((*__tmp_91) as u32).wrapping_add((__tmp_90 as u32))) as u32; + (*__tmp_91).clone() } }); (unsafe { From d4302a149b3cf41bacad411bd210c2bb83599571 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Thu, 26 Nov 2026 04:29:31 +0000 Subject: [PATCH 08/25] Check unsafe assignment aliases within the current function Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 126 +++++++++++++++++++++-- cpp2rust/converter/converter.h | 2 +- cpp2rust/converter/models/boxed_vars.cpp | 7 +- cpp2rust/converter/models/boxed_vars.h | 1 - 4 files changed, 119 insertions(+), 17 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 89a11e168b..517ca73c93 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -4970,6 +4970,100 @@ void Converter::ConvertArraySubscript(clang::Expr *base, clang::Expr *idx, } } +namespace { +// A local can be reread across an effectful RHS only if none of its uses can +// escape its storage. Unknown lvalue uses are conservatively address-taking. +void FindAssignmentAliases(const clang::Stmt *stmt, + std::unordered_set &vars, + bool value_use = false, bool discarded_use = false) { + if (!stmt) { + return; + } + if (const auto *ref = clang::dyn_cast(stmt)) { + if (!value_use) { + if (auto *var = clang::dyn_cast(ref->getDecl())) { + vars.insert(var); + } + } + return; + } + if (const auto *paren = clang::dyn_cast(stmt)) { + FindAssignmentAliases(paren->getSubExpr(), vars, value_use, discarded_use); + return; + } + if (const auto *cleanups = clang::dyn_cast(stmt)) { + FindAssignmentAliases(cleanups->getSubExpr(), vars, value_use, + discarded_use); + return; + } + if (const auto *cast = clang::dyn_cast(stmt)) { + FindAssignmentAliases(cast->getSubExpr(), vars, + cast->getCastKind() == clang::CK_LValueToRValue || + cast->getCastKind() == clang::CK_ToVoid); + return; + } + if (const auto *binary = clang::dyn_cast(stmt)) { + FindAssignmentAliases( + binary->getLHS(), vars, + binary->isAssignmentOp() && + (value_use || discarded_use || binary->isPRValue()), + binary->isCommaOp()); + FindAssignmentAliases(binary->getRHS(), vars, + binary->isCommaOp() && value_use, + binary->isCommaOp() && discarded_use); + return; + } + if (const auto *unary = clang::dyn_cast(stmt)) { + FindAssignmentAliases(unary->getSubExpr(), vars, + unary->isIncrementDecrementOp() && + (value_use || discarded_use || + unary->isPostfix() || unary->isPRValue())); + return; + } + if (const auto *lambda = clang::dyn_cast(stmt)) { + for (const auto &capture : lambda->captures()) { + if (capture.capturesVariable()) { + vars.insert(clang::dyn_cast(capture.getCapturedVar())); + } + } + } + if (const auto *opaque = clang::dyn_cast(stmt)) { + if (opaque->getSourceExpr()) { + FindAssignmentAliases(opaque->getSourceExpr(), vars); + } else { + vars.insert(nullptr); + } + return; + } + // These extensions may keep captures or yield an lvalue from a body. Bind + // all targets rather than assuming their statement children cannot alias. + if (clang::isa(stmt)) { + vars.insert(nullptr); + } + for (const auto *child : stmt->children()) { + bool discarded = clang::isa(stmt); + if (const auto *branch = clang::dyn_cast(stmt)) { + discarded = child == branch->getThen() || child == branch->getElse(); + } else if (const auto *loop = clang::dyn_cast(stmt)) { + discarded = child == loop->getInit() || child == loop->getInc() || + child == loop->getBody(); + } else if (const auto *loop = clang::dyn_cast(stmt)) { + discarded = child == loop->getBody(); + } else if (const auto *loop = clang::dyn_cast(stmt)) { + discarded = child == loop->getBody(); + } else if (const auto *loop = + clang::dyn_cast(stmt)) { + discarded = child == loop->getBody(); + } else if (const auto *label = clang::dyn_cast(stmt)) { + discarded = child == label->getSubStmt(); + } else if (const auto *label = clang::dyn_cast(stmt)) { + discarded = child == label->getSubStmt(); + } + FindAssignmentAliases(child, vars, /*value_use=*/false, discarded); + } +} +} // namespace + bool Converter::NeedsAssignmentBinding( const clang::Expr *lhs, const clang::Expr *rhs, const clang::CompoundAssignOperator *compound) { @@ -4994,18 +5088,30 @@ bool Converter::NeedsAssignmentBinding( IsGlobalVar(var) || !curr_function_) { return true; } - if (!GetAllVars(rhs).contains(var)) { - auto *vars = boxed_vars_.get(); - if (!vars) { - auto &cached = assignment_vars_[curr_function_]; - if (!cached) { - cached = std::make_shared(ctx_, curr_function_); - } - vars = cached.get(); - } - if (!vars->contains(var)) { + auto refers_to_var = [&](auto &&self, const clang::Stmt *stmt) -> bool { + if (!stmt) { return false; } + if (const auto *ref = clang::dyn_cast(stmt); + ref && ref->getDecl() == var) { + return true; + } + return std::ranges::any_of(stmt->children(), [&](const auto *child) { + return self(self, child); + }); + }; + if (!refers_to_var(refers_to_var, rhs)) { + if (boxed_vars_) { + return boxed_vars_->contains(var); + } + if (!var->getType()->isScalarType() || var->isInitCapture()) { + return true; + } + auto [entry, inserted] = assignment_vars_.try_emplace(curr_function_); + if (inserted) { + FindAssignmentAliases(curr_function_->getBody(), entry->second); + } + return entry->second.contains(nullptr) || entry->second.contains(var); } return true; } diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index f7e95e4964..c34e08dca8 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -1054,7 +1054,7 @@ class Converter : public clang::RecursiveASTVisitor { clang::ASTContext &ctx_; std::shared_ptr boxed_vars_; std::unordered_map> + std::unordered_set> assignment_vars_; std::unique_ptr mangle_context_; clang::FunctionDecl *curr_function_ = nullptr; diff --git a/cpp2rust/converter/models/boxed_vars.cpp b/cpp2rust/converter/models/boxed_vars.cpp index dd89521f32..42f1b130a6 100644 --- a/cpp2rust/converter/models/boxed_vars.cpp +++ b/cpp2rust/converter/models/boxed_vars.cpp @@ -490,12 +490,9 @@ class AddressTakenVisitor }; } // namespace -BoxedVars::BoxedVars(clang::ASTContext &ctx) - : BoxedVars(ctx, ctx.getTranslationUnitDecl()) {} - -BoxedVars::BoxedVars(clang::ASTContext &ctx, clang::Decl *scope) : ctx_(ctx) { +BoxedVars::BoxedVars(clang::ASTContext &ctx) : ctx_(ctx) { AddressTakenVisitor(ctx, address_taken_, range_iterators_) - .TraverseDecl(scope); + .TraverseDecl(ctx.getTranslationUnitDecl()); } bool BoxedVars::contains(const clang::VarDecl *decl) const { diff --git a/cpp2rust/converter/models/boxed_vars.h b/cpp2rust/converter/models/boxed_vars.h index d2576b5e45..ba92d82528 100644 --- a/cpp2rust/converter/models/boxed_vars.h +++ b/cpp2rust/converter/models/boxed_vars.h @@ -22,7 +22,6 @@ namespace cpp2rust { class BoxedVars { public: explicit BoxedVars(clang::ASTContext &ctx); - BoxedVars(clang::ASTContext &ctx, clang::Decl *scope); bool contains(const clang::VarDecl *decl) const; From 240f0913565193656512fd6b8ac4efc22e4fb1d1 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Thu, 26 Nov 2026 05:35:34 +0000 Subject: [PATCH 09/25] Resolve boxed array member targets before borrowing Signed-off-by: Perfloop Agent --- .../converter/models/converter_refcount.cpp | 16 +- tests/unit/assignment_single_eval.cpp | 37 ++ .../out/refcount/assignment_single_eval.rs | 381 +++++++++++++++++- .../unit/out/unsafe/assignment_single_eval.rs | 269 ++++++++++++- 4 files changed, 685 insertions(+), 18 deletions(-) diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 056bc3863c..45623492b8 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -2500,9 +2500,17 @@ void ConverterRefCount::ConvertAssignment( auto rhs_value = ConvertFreshRValue( rhs, compound ? std::nullopt : std::optional(lhs->getType())); std::string lhs_value; - auto *subscript = - clang::dyn_cast(lhs->IgnoreParenImpCasts()); - if (subscript && !IsPointerSubscript(subscript) && !IsUnboxedPlace(lhs)) { + auto *base = lhs->IgnoreParenImpCasts(); + while (auto *member = clang::dyn_cast(base)) { + if (member->isArrow()) { + break; + } + base = member->getBase()->IgnoreParenImpCasts(); + } + auto *subscript = clang::dyn_cast(base); + bool boxed_array = + subscript && !IsPointerSubscript(subscript) && !IsUnboxedPlace(base); + if (boxed_array) { // Resolve the index before borrowing the array, as it may read the same // storage. The pointer keeps the selected element, not an active borrow. auto ptr = ConvertFreshPointer(lhs); @@ -2517,7 +2525,7 @@ void ConverterRefCount::ConvertAssignment( // after the right operand, keeping its temporaries alive through the write. StrCat("match ({ ", rhs_value, " }, "); bool through_pointer = !pending_deref_.empty(); - if (subscript && !IsPointerSubscript(subscript) && !IsUnboxedPlace(lhs)) { + if (boxed_array) { // End incidental index borrows before with_mut takes the write borrow. StrCat("{ let ", left, token::kAssign, pending_deref_.take(), token::kSemiColon, left, "}"); diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index e4c67cd2cb..1d7fa80a56 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -169,7 +169,44 @@ template void test_boxed_array() { } unsigned global_array[3] = {0, 20, 30}; +struct IndexedMember { + int key; + unsigned value; + short promoted; +}; +IndexedMember global_members[2] = {{0, 10, 10}, {1, 20, 20}}; + +#define TEST_MEMBERS(array) \ + int i = 0; \ + unsigned result = (array[array[i++].key].value += 1); \ + std::printf("member unsigned %d %u %u %u\n", i, result, array[0].value, \ + array[1].value); \ + i = 0; \ + array[array[i++].key].promoted += 1; \ + std::printf("member promoted %d %d %d\n", i, int(array[0].promoted), \ + int(array[1].promoted)); \ + i = 0; \ + result = (array[array[i++].key].value = 99); \ + std::printf("member simple %d %u %u %u\n", i, result, array[0].value, \ + array[1].value) + +void test_local_members() { + IndexedMember a[2] = {{0, 10, 10}, {1, 20, 20}}; + IndexedMember *p = a; + TEST_MEMBERS(a); + std::printf("member alias %u\n", p->value); +} +void test_global_members() { TEST_MEMBERS(global_members); } +void test_static_members() { + static IndexedMember a[2] = {{0, 10, 10}, {1, 20, 20}}; + TEST_MEMBERS(a); +} +#undef TEST_MEMBERS + int main() { + test_local_members(); + test_global_members(); + test_static_members(); test(); test(); test(); diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index f6f2797c66..bc556d8b1d 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -1053,11 +1053,375 @@ thread_local!( pub static global_array_28: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); ); +#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(12)] +pub struct IndexedMember { + #[offset(0)] + pub key: i32, + #[offset(4)] + pub value: u32, + #[offset(8)] + pub promoted: i16, +} +thread_local!( + pub static global_members_29: Value> = Rc::new(RefCell::new(Box::new([ + IndexedMember { + key: 0, + value: 10_u32, + promoted: 10_i16, + }, + IndexedMember { + key: 1, + value: 20_u32, + promoted: 20_i16, + }, + ]))); +); +pub fn test_local_members_30() { + let a: Value> = Rc::new(RefCell::new(Box::new([ + IndexedMember { + key: 0, + value: 10_u32, + promoted: 10_i16, + }, + IndexedMember { + key: 1, + value: 20_u32, + promoted: 20_i16, + }, + ]))); + let mut p: Ptr = a.decay(); + let mut i: i32 = 0; + let mut result: u32 = ({ + match ({ 1_u32 }, { + let __tmp_85 = field_ptr!( + a.decay() + .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), + value + ); + __tmp_85 + }) { + (__tmp_84, __tmp_85) => __tmp_85.with_mut(|__tmp_85| { + (*__tmp_85) = (((*__tmp_85) as u32).wrapping_add((__tmp_84 as u32))) as u32; + (*__tmp_85).clone() + }), + } + }); + printf!( + b"member unsigned %d %u %u %u\n", + i, + result, + { (*a.borrow())[(0) as usize].value }, + { (*a.borrow())[(1) as usize].value } + ); + i = 0; + { + match ({ 1 }, { + let __tmp_87 = field_ptr!( + a.decay() + .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), + promoted + ); + __tmp_87 + }) { + (__tmp_86, __tmp_87) => __tmp_87.with_mut(|__tmp_87| { + (*__tmp_87) = (((*__tmp_87) as i32) + (__tmp_86 as i32)) as i16; + }), + } + }; + printf!( + b"member promoted %d %d %d\n", + i, + ({ (*a.borrow())[(0) as usize].promoted } as i32), + ({ (*a.borrow())[(1) as usize].promoted } as i32) + ); + i = 0; + result = ({ + match ({ 99_u32 }, { + let __tmp_89 = field_ptr!( + a.decay() + .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), + value + ); + __tmp_89 + }) { + (__tmp_88, __tmp_89) => __tmp_89.with_mut(|__tmp_89| { + (*__tmp_89) = __tmp_88; + (*__tmp_89).clone() + }), + } + }); + printf!( + b"member simple %d %u %u %u\n", + i, + result, + { (*a.borrow())[(0) as usize].value }, + { (*a.borrow())[(1) as usize].value } + ); + printf!(b"member alias %u\n", p.with(|__s| __s.value)); +} +pub fn test_global_members_31() { + let mut i: i32 = 0; + let mut result: u32 = ({ + match ({ 1_u32 }, { + let __tmp_91 = field_ptr!( + global_members_29.with(|v| v.decay()).offset({ + ({ + let __idx0 = (i.postfix_inc()) as usize; + global_members_29.with(|rc| rc.borrow()[__idx0]) + }) + .key + }), + value + ); + __tmp_91 + }) { + (__tmp_90, __tmp_91) => __tmp_91.with_mut(|__tmp_91| { + (*__tmp_91) = (((*__tmp_91) as u32).wrapping_add((__tmp_90 as u32))) as u32; + (*__tmp_91).clone() + }), + } + }); + printf!( + b"member unsigned %d %u %u %u\n", + i, + result, + { + ({ + let __idx0 = (0) as usize; + global_members_29.with(|rc| rc.borrow()[__idx0]) + }) + .value + }, + { + ({ + let __idx0 = (1) as usize; + global_members_29.with(|rc| rc.borrow()[__idx0]) + }) + .value + } + ); + i = 0; + { + match ({ 1 }, { + let __tmp_93 = field_ptr!( + global_members_29.with(|v| v.decay()).offset({ + ({ + let __idx0 = (i.postfix_inc()) as usize; + global_members_29.with(|rc| rc.borrow()[__idx0]) + }) + .key + }), + promoted + ); + __tmp_93 + }) { + (__tmp_92, __tmp_93) => __tmp_93.with_mut(|__tmp_93| { + (*__tmp_93) = (((*__tmp_93) as i32) + (__tmp_92 as i32)) as i16; + }), + } + }; + printf!( + b"member promoted %d %d %d\n", + i, + ({ + ({ + let __idx0 = (0) as usize; + global_members_29.with(|rc| rc.borrow()[__idx0]) + }) + .promoted + } as i32), + ({ + ({ + let __idx0 = (1) as usize; + global_members_29.with(|rc| rc.borrow()[__idx0]) + }) + .promoted + } as i32) + ); + i = 0; + result = ({ + match ({ 99_u32 }, { + let __tmp_95 = field_ptr!( + global_members_29.with(|v| v.decay()).offset({ + ({ + let __idx0 = (i.postfix_inc()) as usize; + global_members_29.with(|rc| rc.borrow()[__idx0]) + }) + .key + }), + value + ); + __tmp_95 + }) { + (__tmp_94, __tmp_95) => __tmp_95.with_mut(|__tmp_95| { + (*__tmp_95) = __tmp_94; + (*__tmp_95).clone() + }), + } + }); + printf!( + b"member simple %d %u %u %u\n", + i, + result, + { + ({ + let __idx0 = (0) as usize; + global_members_29.with(|rc| rc.borrow()[__idx0]) + }) + .value + }, + { + ({ + let __idx0 = (1) as usize; + global_members_29.with(|rc| rc.borrow()[__idx0]) + }) + .value + } + ); +} +pub fn test_static_members_32() { + let mut i: i32 = 0; + let mut result: u32 = ({ + match ({ 1_u32 }, { + let __tmp_97 = field_ptr!( + a_33.with(|v| v.decay()).offset({ + ({ + let __idx0 = (i.postfix_inc()) as usize; + a_33.with(|rc| rc.borrow()[__idx0]) + }) + .key + }), + value + ); + __tmp_97 + }) { + (__tmp_96, __tmp_97) => __tmp_97.with_mut(|__tmp_97| { + (*__tmp_97) = (((*__tmp_97) as u32).wrapping_add((__tmp_96 as u32))) as u32; + (*__tmp_97).clone() + }), + } + }); + printf!( + b"member unsigned %d %u %u %u\n", + i, + result, + { + ({ + let __idx0 = (0) as usize; + a_33.with(|rc| rc.borrow()[__idx0]) + }) + .value + }, + { + ({ + let __idx0 = (1) as usize; + a_33.with(|rc| rc.borrow()[__idx0]) + }) + .value + } + ); + i = 0; + { + match ({ 1 }, { + let __tmp_99 = field_ptr!( + a_33.with(|v| v.decay()).offset({ + ({ + let __idx0 = (i.postfix_inc()) as usize; + a_33.with(|rc| rc.borrow()[__idx0]) + }) + .key + }), + promoted + ); + __tmp_99 + }) { + (__tmp_98, __tmp_99) => __tmp_99.with_mut(|__tmp_99| { + (*__tmp_99) = (((*__tmp_99) as i32) + (__tmp_98 as i32)) as i16; + }), + } + }; + printf!( + b"member promoted %d %d %d\n", + i, + ({ + ({ + let __idx0 = (0) as usize; + a_33.with(|rc| rc.borrow()[__idx0]) + }) + .promoted + } as i32), + ({ + ({ + let __idx0 = (1) as usize; + a_33.with(|rc| rc.borrow()[__idx0]) + }) + .promoted + } as i32) + ); + i = 0; + result = ({ + match ({ 99_u32 }, { + let __tmp_101 = field_ptr!( + a_33.with(|v| v.decay()).offset({ + ({ + let __idx0 = (i.postfix_inc()) as usize; + a_33.with(|rc| rc.borrow()[__idx0]) + }) + .key + }), + value + ); + __tmp_101 + }) { + (__tmp_100, __tmp_101) => __tmp_101.with_mut(|__tmp_101| { + (*__tmp_101) = __tmp_100; + (*__tmp_101).clone() + }), + } + }); + printf!( + b"member simple %d %u %u %u\n", + i, + result, + { + ({ + let __idx0 = (0) as usize; + a_33.with(|rc| rc.borrow()[__idx0]) + }) + .value + }, + { + ({ + let __idx0 = (1) as usize; + a_33.with(|rc| rc.borrow()[__idx0]) + }) + .value + } + ); +} +thread_local!( + static a_33: Value> = Rc::new(RefCell::new(Box::new([ + IndexedMember { + key: 0, + value: 10_u32, + promoted: 10_i16, + }, + IndexedMember { + key: 1, + value: 20_u32, + promoted: 20_i16, + }, + ]))); +); pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { + ({ test_local_members_30() }); + ({ test_global_members_31() }); + ({ test_static_members_32() }); ({ test_0() }); ({ test_1() }); ({ test_2() }); @@ -1077,9 +1441,9 @@ fn main_0() -> i32 { 0 )), ) { - (__tmp_84, __tmp_85) => __tmp_85.with_mut(|__tmp_85| { - (*__tmp_85) = (((*__tmp_85) as u32).wrapping_add((__tmp_84 as u32))) as u32; - (*__tmp_85).clone() + (__tmp_102, __tmp_103) => __tmp_103.with_mut(|__tmp_103| { + (*__tmp_103) = (((*__tmp_103) as u32).wrapping_add((__tmp_102 as u32))) as u32; + (*__tmp_103).clone() }), } }); @@ -1096,17 +1460,17 @@ fn main_0() -> i32 { ({ test_boxed_array_26() }); let mut global_result: u32 = ({ match ({ 1_u32 }, { - let __tmp_87 = global_array_28.with(|v| v.decay()).offset( + let __tmp_105 = global_array_28.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; global_array_28.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_87 + __tmp_105 }) { - (__tmp_86, __tmp_87) => __tmp_87.with_mut(|__tmp_87| { - (*__tmp_87) = (((*__tmp_87) as u32).wrapping_add((__tmp_86 as u32))) as u32; - (*__tmp_87).clone() + (__tmp_104, __tmp_105) => __tmp_105.with_mut(|__tmp_105| { + (*__tmp_105) = (((*__tmp_105) as u32).wrapping_add((__tmp_104 as u32))) as u32; + (*__tmp_105).clone() }), } }); @@ -1142,4 +1506,5 @@ pub fn __cpp2rust_init_globals() { let _ = initializer_target_20.with(|_| ()); let _ = initializer_result_22.with(|_| ()); let _ = global_array_28.with(|_| ()); + let _ = global_members_29.with(|_| ()); } diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 98abb5de21..6ae5680ab2 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -1116,6 +1116,259 @@ static mut saved_27: std::cell::LazyCell<[i16; 3]> = std::cell::LazyCell::new(|| unsafe { [0_i16, 20_i16, 30_i16] }); pub static mut global_array_28: std::cell::LazyCell<[u32; 3]> = std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct IndexedMember { + pub key: i32, + pub value: u32, + pub promoted: i16, +} +pub static mut global_members_29: std::cell::LazyCell<[IndexedMember; 2]> = + std::cell::LazyCell::new(|| unsafe { + [ + IndexedMember { + key: 0, + value: 10_u32, + promoted: 10_i16, + }, + IndexedMember { + key: 1, + value: 20_u32, + promoted: 20_i16, + }, + ] + }); +pub unsafe fn test_local_members_30() { + let mut a: [IndexedMember; 2] = [ + IndexedMember { + key: 0, + value: 10_u32, + promoted: 10_i16, + }, + IndexedMember { + key: 1, + value: 20_u32, + promoted: 20_i16, + }, + ]; + let mut p: *mut IndexedMember = a.as_mut_ptr(); + let mut i: i32 = 0; + let mut result: u32 = (match ( + { 1_u32 }, + &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].value), + ) { + (__tmp_88, __tmp_89) => { + (*__tmp_89) = (((*__tmp_89) as u32).wrapping_add((__tmp_88 as u32))) as u32; + (*__tmp_89).clone() + } + }); + (unsafe { + libc::printf( + c"member unsigned %d %u %u %u\n".as_ptr() as *const libc::c_char, + (i), + (result), + (a[(0) as usize].value), + (a[(1) as usize].value), + ) + }); + i = 0; + match ( + { 1 }, + &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].promoted), + ) { + (__tmp_90, __tmp_91) => { + (*__tmp_91) = (((*__tmp_91) as i32) + (__tmp_90 as i32)) as i16; + } + }; + (unsafe { + libc::printf( + c"member promoted %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (a[(0) as usize].promoted as i32), + (a[(1) as usize].promoted as i32), + ) + }); + i = 0; + result = (match ( + { 99_u32 }, + &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].value), + ) { + (__tmp_92, __tmp_93) => { + (*__tmp_93) = __tmp_92; + (*__tmp_93).clone() + } + }); + (unsafe { + libc::printf( + c"member simple %d %u %u %u\n".as_ptr() as *const libc::c_char, + (i), + (result), + (a[(0) as usize].value), + (a[(1) as usize].value), + ) + }); + (unsafe { + libc::printf( + c"member alias %u\n".as_ptr() as *const libc::c_char, + ((*p).value), + ) + }); +} +pub unsafe fn test_global_members_31() { + let mut i: i32 = 0; + let mut result: u32 = (match ( + { 1_u32 }, + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29)) + [(i.postfix_inc()) as usize] + .key) as usize] + .value), + ) { + (__tmp_94, __tmp_95) => { + (*__tmp_95) = (((*__tmp_95) as u32).wrapping_add((__tmp_94 as u32))) as u32; + (*__tmp_95).clone() + } + }); + (unsafe { + libc::printf( + c"member unsigned %d %u %u %u\n".as_ptr() as *const libc::c_char, + (i), + (result), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29))[(0) as usize] + .value), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29))[(1) as usize] + .value), + ) + }); + i = 0; + match ( + { 1 }, + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29)) + [(i.postfix_inc()) as usize] + .key) as usize] + .promoted), + ) { + (__tmp_96, __tmp_97) => { + (*__tmp_97) = (((*__tmp_97) as i32) + (__tmp_96 as i32)) as i16; + } + }; + (unsafe { + libc::printf( + c"member promoted %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29))[(0) as usize] + .promoted as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29))[(1) as usize] + .promoted as i32), + ) + }); + i = 0; + result = (match ( + { 99_u32 }, + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29)) + [(i.postfix_inc()) as usize] + .key) as usize] + .value), + ) { + (__tmp_98, __tmp_99) => { + (*__tmp_99) = __tmp_98; + (*__tmp_99).clone() + } + }); + (unsafe { + libc::printf( + c"member simple %d %u %u %u\n".as_ptr() as *const libc::c_char, + (i), + (result), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29))[(0) as usize] + .value), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29))[(1) as usize] + .value), + ) + }); +} +pub unsafe fn test_static_members_32() { + let mut i: i32 = 0; + let mut result: u32 = (match ( + { 1_u32 }, + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(i.postfix_inc()) as usize] + .key) as usize] + .value), + ) { + (__tmp_100, __tmp_101) => { + (*__tmp_101) = (((*__tmp_101) as u32).wrapping_add((__tmp_100 as u32))) as u32; + (*__tmp_101).clone() + } + }); + (unsafe { + libc::printf( + c"member unsigned %d %u %u %u\n".as_ptr() as *const libc::c_char, + (i), + (result), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(0) as usize].value), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(1) as usize].value), + ) + }); + i = 0; + match ( + { 1 }, + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(i.postfix_inc()) as usize] + .key) as usize] + .promoted), + ) { + (__tmp_102, __tmp_103) => { + (*__tmp_103) = (((*__tmp_103) as i32) + (__tmp_102 as i32)) as i16; + } + }; + (unsafe { + libc::printf( + c"member promoted %d %d %d\n".as_ptr() as *const libc::c_char, + (i), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(0) as usize].promoted as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(1) as usize].promoted as i32), + ) + }); + i = 0; + result = (match ( + { 99_u32 }, + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(i.postfix_inc()) as usize] + .key) as usize] + .value), + ) { + (__tmp_104, __tmp_105) => { + (*__tmp_105) = __tmp_104; + (*__tmp_105).clone() + } + }); + (unsafe { + libc::printf( + c"member simple %d %u %u %u\n".as_ptr() as *const libc::c_char, + (i), + (result), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(0) as usize].value), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(1) as usize].value), + ) + }); +} +static mut a_33: std::cell::LazyCell<[IndexedMember; 2]> = std::cell::LazyCell::new(|| unsafe { + [ + IndexedMember { + key: 0, + value: 10_u32, + promoted: 10_i16, + }, + IndexedMember { + key: 1, + value: 20_u32, + promoted: 20_i16, + }, + ] +}); pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -1123,6 +1376,9 @@ pub fn main() { } } unsafe fn main_0() -> i32 { + (unsafe { test_local_members_30() }); + (unsafe { test_global_members_31() }); + (unsafe { test_static_members_32() }); (unsafe { test_0() }); (unsafe { test_1() }); (unsafe { test_2() }); @@ -1138,9 +1394,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_88, __tmp_89) => { - (*__tmp_89) = (((*__tmp_89) as u32).wrapping_add((__tmp_88 as u32))) as u32; - (*__tmp_89).clone() + (__tmp_106, __tmp_107) => { + (*__tmp_107) = (((*__tmp_107) as u32).wrapping_add((__tmp_106 as u32))) as u32; + (*__tmp_107).clone() } }); (unsafe { @@ -1162,9 +1418,9 @@ unsafe fn main_0() -> i32 { [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_28))[(0) as usize]) as usize]), ) { - (__tmp_90, __tmp_91) => { - (*__tmp_91) = (((*__tmp_91) as u32).wrapping_add((__tmp_90 as u32))) as u32; - (*__tmp_91).clone() + (__tmp_108, __tmp_109) => { + (*__tmp_109) = (((*__tmp_109) as u32).wrapping_add((__tmp_108 as u32))) as u32; + (*__tmp_109).clone() } }); (unsafe { @@ -1185,4 +1441,5 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const initializer_target_20); std::cell::LazyCell::force(&*&raw const initializer_result_22); std::cell::LazyCell::force(&*&raw const global_array_28); + std::cell::LazyCell::force(&*&raw const global_members_29); } From 635cae3930efcb98096ca677c9f97e95ddcdb380 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Fri, 27 Nov 2026 19:36:09 +0000 Subject: [PATCH 10/25] Keep fixed array assignments on compact lowering Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 21 ++++ .../converter/models/converter_refcount.cpp | 13 ++- tests/unit/assignment_single_eval.cpp | 5 + .../out/refcount/assignment_single_eval.rs | 110 ++++++++++++------ .../unit/out/unsafe/assignment_single_eval.rs | 92 +++++++++------ 5 files changed, 173 insertions(+), 68 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 517ca73c93..9273efa737 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -5116,6 +5116,27 @@ bool Converter::NeedsAssignmentBinding( return true; } if (!rhs_effects) { + // Fixed array elements, including their fields, still select the same + // storage after the write. Keep their compact lowering too. + const auto *base = target; + while (const auto *member = clang::dyn_cast(base)) { + if (member->isArrow()) { + break; + } + base = member->getBase()->IgnoreParenImpCasts(); + } + if (const auto *subscript = + clang::dyn_cast(base); + subscript && subscript->getIdx()->isIntegerConstantExpr(ctx_) && + !lhs->HasSideEffects(ctx_)) { + const auto *array = clang::dyn_cast( + subscript->getBase()->IgnoreParenImpCasts()); + const auto *decl = + array ? clang::dyn_cast(array->getDecl()) : nullptr; + if (decl && !decl->isImplicit() && decl->getType()->isArrayType()) { + return false; + } + } if (const auto *member = clang::dyn_cast(target)) { const auto *base = clang::dyn_cast( member->getBase()->IgnoreParenImpCasts()); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 45623492b8..0af9780721 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -2508,8 +2508,17 @@ void ConverterRefCount::ConvertAssignment( base = member->getBase()->IgnoreParenImpCasts(); } auto *subscript = clang::dyn_cast(base); - bool boxed_array = - subscript && !IsPointerSubscript(subscript) && !IsUnboxedPlace(base); + const auto *array = subscript + ? clang::dyn_cast( + subscript->getBase()->IgnoreParenImpCasts()) + : nullptr; + const auto *decl = + array ? clang::dyn_cast(array->getDecl()) : nullptr; + bool fixed_index = subscript && decl && !decl->isImplicit() && + decl->getType()->isArrayType() && + subscript->getIdx()->isIntegerConstantExpr(ctx_); + bool boxed_array = subscript && !IsPointerSubscript(subscript) && + !IsUnboxedPlace(base) && !fixed_index; if (boxed_array) { // Resolve the index before borrowing the array, as it may read the same // storage. The pointer keeps the selected element, not an active borrow. diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index 1d7fa80a56..429b16c490 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -168,6 +168,7 @@ template void test_boxed_array() { std::printf("static array %d %d\n", int(result), int(saved[0])); } unsigned global_array[3] = {0, 20, 30}; +unsigned global_rows[2][2] = {{0, 10}, {20, 30}}; struct IndexedMember { int key; @@ -224,5 +225,9 @@ int main() { test_boxed_array(); unsigned global_result = (global_array[global_array[0]] += 1); std::printf("global array %u %u\n", global_result, global_array[0]); + i = 0; + result = (global_rows[global_rows[i++][0]][0] += 1); + std::printf("nested array %d %u %u %u\n", i, result, global_rows[0][0], + global_rows[1][0]); return 0; } diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index bc556d8b1d..48c11f2d82 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -1053,6 +1053,12 @@ thread_local!( pub static global_array_28: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); ); +thread_local!( + pub static global_rows_29: Value]>> = Rc::new(RefCell::new(Box::new([ + Box::new([0_u32, 10_u32]), + Box::new([20_u32, 30_u32]), + ]))); +); #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(12)] pub struct IndexedMember { @@ -1064,7 +1070,7 @@ pub struct IndexedMember { pub promoted: i16, } thread_local!( - pub static global_members_29: Value> = Rc::new(RefCell::new(Box::new([ + pub static global_members_30: Value> = Rc::new(RefCell::new(Box::new([ IndexedMember { key: 0, value: 10_u32, @@ -1077,7 +1083,7 @@ thread_local!( }, ]))); ); -pub fn test_local_members_30() { +pub fn test_local_members_31() { let a: Value> = Rc::new(RefCell::new(Box::new([ IndexedMember { key: 0, @@ -1160,15 +1166,15 @@ pub fn test_local_members_30() { ); printf!(b"member alias %u\n", p.with(|__s| __s.value)); } -pub fn test_global_members_31() { +pub fn test_global_members_32() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { let __tmp_91 = field_ptr!( - global_members_29.with(|v| v.decay()).offset({ + global_members_30.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - global_members_29.with(|rc| rc.borrow()[__idx0]) + global_members_30.with(|rc| rc.borrow()[__idx0]) }) .key }), @@ -1189,14 +1195,14 @@ pub fn test_global_members_31() { { ({ let __idx0 = (0) as usize; - global_members_29.with(|rc| rc.borrow()[__idx0]) + global_members_30.with(|rc| rc.borrow()[__idx0]) }) .value }, { ({ let __idx0 = (1) as usize; - global_members_29.with(|rc| rc.borrow()[__idx0]) + global_members_30.with(|rc| rc.borrow()[__idx0]) }) .value } @@ -1205,10 +1211,10 @@ pub fn test_global_members_31() { { match ({ 1 }, { let __tmp_93 = field_ptr!( - global_members_29.with(|v| v.decay()).offset({ + global_members_30.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - global_members_29.with(|rc| rc.borrow()[__idx0]) + global_members_30.with(|rc| rc.borrow()[__idx0]) }) .key }), @@ -1227,14 +1233,14 @@ pub fn test_global_members_31() { ({ ({ let __idx0 = (0) as usize; - global_members_29.with(|rc| rc.borrow()[__idx0]) + global_members_30.with(|rc| rc.borrow()[__idx0]) }) .promoted } as i32), ({ ({ let __idx0 = (1) as usize; - global_members_29.with(|rc| rc.borrow()[__idx0]) + global_members_30.with(|rc| rc.borrow()[__idx0]) }) .promoted } as i32) @@ -1243,10 +1249,10 @@ pub fn test_global_members_31() { result = ({ match ({ 99_u32 }, { let __tmp_95 = field_ptr!( - global_members_29.with(|v| v.decay()).offset({ + global_members_30.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - global_members_29.with(|rc| rc.borrow()[__idx0]) + global_members_30.with(|rc| rc.borrow()[__idx0]) }) .key }), @@ -1267,28 +1273,28 @@ pub fn test_global_members_31() { { ({ let __idx0 = (0) as usize; - global_members_29.with(|rc| rc.borrow()[__idx0]) + global_members_30.with(|rc| rc.borrow()[__idx0]) }) .value }, { ({ let __idx0 = (1) as usize; - global_members_29.with(|rc| rc.borrow()[__idx0]) + global_members_30.with(|rc| rc.borrow()[__idx0]) }) .value } ); } -pub fn test_static_members_32() { +pub fn test_static_members_33() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { let __tmp_97 = field_ptr!( - a_33.with(|v| v.decay()).offset({ + a_34.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - a_33.with(|rc| rc.borrow()[__idx0]) + a_34.with(|rc| rc.borrow()[__idx0]) }) .key }), @@ -1309,14 +1315,14 @@ pub fn test_static_members_32() { { ({ let __idx0 = (0) as usize; - a_33.with(|rc| rc.borrow()[__idx0]) + a_34.with(|rc| rc.borrow()[__idx0]) }) .value }, { ({ let __idx0 = (1) as usize; - a_33.with(|rc| rc.borrow()[__idx0]) + a_34.with(|rc| rc.borrow()[__idx0]) }) .value } @@ -1325,10 +1331,10 @@ pub fn test_static_members_32() { { match ({ 1 }, { let __tmp_99 = field_ptr!( - a_33.with(|v| v.decay()).offset({ + a_34.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - a_33.with(|rc| rc.borrow()[__idx0]) + a_34.with(|rc| rc.borrow()[__idx0]) }) .key }), @@ -1347,14 +1353,14 @@ pub fn test_static_members_32() { ({ ({ let __idx0 = (0) as usize; - a_33.with(|rc| rc.borrow()[__idx0]) + a_34.with(|rc| rc.borrow()[__idx0]) }) .promoted } as i32), ({ ({ let __idx0 = (1) as usize; - a_33.with(|rc| rc.borrow()[__idx0]) + a_34.with(|rc| rc.borrow()[__idx0]) }) .promoted } as i32) @@ -1363,10 +1369,10 @@ pub fn test_static_members_32() { result = ({ match ({ 99_u32 }, { let __tmp_101 = field_ptr!( - a_33.with(|v| v.decay()).offset({ + a_34.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - a_33.with(|rc| rc.borrow()[__idx0]) + a_34.with(|rc| rc.borrow()[__idx0]) }) .key }), @@ -1387,21 +1393,21 @@ pub fn test_static_members_32() { { ({ let __idx0 = (0) as usize; - a_33.with(|rc| rc.borrow()[__idx0]) + a_34.with(|rc| rc.borrow()[__idx0]) }) .value }, { ({ let __idx0 = (1) as usize; - a_33.with(|rc| rc.borrow()[__idx0]) + a_34.with(|rc| rc.borrow()[__idx0]) }) .value } ); } thread_local!( - static a_33: Value> = Rc::new(RefCell::new(Box::new([ + static a_34: Value> = Rc::new(RefCell::new(Box::new([ IndexedMember { key: 0, value: 10_u32, @@ -1419,9 +1425,9 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ test_local_members_30() }); - ({ test_global_members_31() }); - ({ test_static_members_32() }); + ({ test_local_members_31() }); + ({ test_global_members_32() }); + ({ test_static_members_33() }); ({ test_0() }); ({ test_1() }); ({ test_2() }); @@ -1482,6 +1488,43 @@ fn main_0() -> i32 { global_array_28.with(|rc| rc.borrow()[__idx0]) }) ); + i = 0; + result = ({ + match ({ 1_u32 }, { + let __tmp_107 = global_rows_29 + .with(|v| v.decay()) + .offset( + ({ + let __idx0 = (i.postfix_inc()) as usize; + let __idx1 = (0) as usize; + global_rows_29.with(|rc| rc.borrow()[__idx0][__idx1]) + }), + ) + .decay() + .offset(0); + __tmp_107 + }) { + (__tmp_106, __tmp_107) => __tmp_107.with_mut(|__tmp_107| { + (*__tmp_107) = (((*__tmp_107) as u32).wrapping_add((__tmp_106 as u32))) as u32; + (*__tmp_107).clone() + }), + } + }); + printf!( + b"nested array %d %u %u %u\n", + i, + result, + ({ + let __idx0 = (0) as usize; + let __idx1 = (0) as usize; + global_rows_29.with(|rc| rc.borrow()[__idx0][__idx1]) + }), + ({ + let __idx0 = (1) as usize; + let __idx1 = (0) as usize; + global_rows_29.with(|rc| rc.borrow()[__idx0][__idx1]) + }) + ); return 0; } pub trait IndexedBindingImpl { @@ -1506,5 +1549,6 @@ pub fn __cpp2rust_init_globals() { let _ = initializer_target_20.with(|_| ()); let _ = initializer_result_22.with(|_| ()); let _ = global_array_28.with(|_| ()); - let _ = global_members_29.with(|_| ()); + let _ = global_rows_29.with(|_| ()); + let _ = global_members_30.with(|_| ()); } diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 6ae5680ab2..b3fd171082 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -1116,6 +1116,8 @@ static mut saved_27: std::cell::LazyCell<[i16; 3]> = std::cell::LazyCell::new(|| unsafe { [0_i16, 20_i16, 30_i16] }); pub static mut global_array_28: std::cell::LazyCell<[u32; 3]> = std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); +pub static mut global_rows_29: std::cell::LazyCell<[[u32; 2]; 2]> = + std::cell::LazyCell::new(|| unsafe { [[0_u32, 10_u32], [20_u32, 30_u32]] }); #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] pub struct IndexedMember { @@ -1123,7 +1125,7 @@ pub struct IndexedMember { pub value: u32, pub promoted: i16, } -pub static mut global_members_29: std::cell::LazyCell<[IndexedMember; 2]> = +pub static mut global_members_30: std::cell::LazyCell<[IndexedMember; 2]> = std::cell::LazyCell::new(|| unsafe { [ IndexedMember { @@ -1138,7 +1140,7 @@ pub static mut global_members_29: std::cell::LazyCell<[IndexedMember; 2]> = }, ] }); -pub unsafe fn test_local_members_30() { +pub unsafe fn test_local_members_31() { let mut a: [IndexedMember; 2] = [ IndexedMember { key: 0, @@ -1214,12 +1216,12 @@ pub unsafe fn test_local_members_30() { ) }); } -pub unsafe fn test_global_members_31() { +pub unsafe fn test_global_members_32() { let mut i: i32 = 0; let mut result: u32 = (match ( { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29)) + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30)) [(i.postfix_inc()) as usize] .key) as usize] .value), @@ -1234,17 +1236,17 @@ pub unsafe fn test_global_members_31() { c"member unsigned %d %u %u %u\n".as_ptr() as *const libc::c_char, (i), (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29))[(0) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30))[(0) as usize] .value), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29))[(1) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30))[(1) as usize] .value), ) }); i = 0; match ( { 1 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29)) + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30)) [(i.postfix_inc()) as usize] .key) as usize] .promoted), @@ -1257,17 +1259,17 @@ pub unsafe fn test_global_members_31() { libc::printf( c"member promoted %d %d %d\n".as_ptr() as *const libc::c_char, (i), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29))[(0) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30))[(0) as usize] .promoted as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29))[(1) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30))[(1) as usize] .promoted as i32), ) }); i = 0; result = (match ( { 99_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29)) + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30)) [(i.postfix_inc()) as usize] .key) as usize] .value), @@ -1282,19 +1284,19 @@ pub unsafe fn test_global_members_31() { c"member simple %d %u %u %u\n".as_ptr() as *const libc::c_char, (i), (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29))[(0) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30))[(0) as usize] .value), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_29))[(1) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30))[(1) as usize] .value), ) }); } -pub unsafe fn test_static_members_32() { +pub unsafe fn test_static_members_33() { let mut i: i32 = 0; let mut result: u32 = (match ( { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(i.postfix_inc()) as usize] + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(i.postfix_inc()) as usize] .key) as usize] .value), ) { @@ -1308,15 +1310,15 @@ pub unsafe fn test_static_members_32() { c"member unsigned %d %u %u %u\n".as_ptr() as *const libc::c_char, (i), (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(0) as usize].value), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(1) as usize].value), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(0) as usize].value), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(1) as usize].value), ) }); i = 0; match ( { 1 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(i.postfix_inc()) as usize] + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(i.postfix_inc()) as usize] .key) as usize] .promoted), ) { @@ -1328,15 +1330,15 @@ pub unsafe fn test_static_members_32() { libc::printf( c"member promoted %d %d %d\n".as_ptr() as *const libc::c_char, (i), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(0) as usize].promoted as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(1) as usize].promoted as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(0) as usize].promoted as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(1) as usize].promoted as i32), ) }); i = 0; result = (match ( { 99_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(i.postfix_inc()) as usize] + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(i.postfix_inc()) as usize] .key) as usize] .value), ) { @@ -1350,12 +1352,12 @@ pub unsafe fn test_static_members_32() { c"member simple %d %u %u %u\n".as_ptr() as *const libc::c_char, (i), (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(0) as usize].value), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_33))[(1) as usize].value), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(0) as usize].value), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(1) as usize].value), ) }); } -static mut a_33: std::cell::LazyCell<[IndexedMember; 2]> = std::cell::LazyCell::new(|| unsafe { +static mut a_34: std::cell::LazyCell<[IndexedMember; 2]> = std::cell::LazyCell::new(|| unsafe { [ IndexedMember { key: 0, @@ -1376,9 +1378,9 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { test_local_members_30() }); - (unsafe { test_global_members_31() }); - (unsafe { test_static_members_32() }); + (unsafe { test_local_members_31() }); + (unsafe { test_global_members_32() }); + (unsafe { test_static_members_33() }); (unsafe { test_0() }); (unsafe { test_1() }); (unsafe { test_2() }); @@ -1430,6 +1432,29 @@ unsafe fn main_0() -> i32 { ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_28))[(0) as usize]), ) }); + i = 0; + result = (match ( + { 1_u32 }, + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_29)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_29)) + [(i.postfix_inc()) as usize][(0) as usize]) as usize][(0) as usize]), + ) { + (__tmp_110, __tmp_111) => { + (*__tmp_111) = (((*__tmp_111) as u32).wrapping_add((__tmp_110 as u32))) as u32; + (*__tmp_111).clone() + } + }); + (unsafe { + libc::printf( + c"nested array %d %u %u %u\n".as_ptr() as *const libc::c_char, + (i), + (result), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_29))[(0) as usize] + [(0) as usize]), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_29))[(1) as usize] + [(0) as usize]), + ) + }); return 0; } pub unsafe fn __cpp2rust_init_globals() { @@ -1441,5 +1466,6 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const initializer_target_20); std::cell::LazyCell::force(&*&raw const initializer_result_22); std::cell::LazyCell::force(&*&raw const global_array_28); - std::cell::LazyCell::force(&*&raw const global_members_29); + std::cell::LazyCell::force(&*&raw const global_rows_29); + std::cell::LazyCell::force(&*&raw const global_members_30); } From 69feb51d4515a24973d6cdbe52960bd5944df3d3 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Fri, 27 Nov 2026 21:05:09 +0000 Subject: [PATCH 11/25] Keep independent assignment indices on compact lowering Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 66 ++++++++++++- tests/unit/assignment_single_eval.cpp | 17 ++++ .../out/refcount/assignment_single_eval.rs | 92 ++++++++++++++++--- .../unit/out/unsafe/assignment_single_eval.rs | 84 +++++++++++++++-- 4 files changed, 232 insertions(+), 27 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 9273efa737..16707be5f0 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -5127,14 +5127,70 @@ bool Converter::NeedsAssignmentBinding( } if (const auto *subscript = clang::dyn_cast(base); - subscript && subscript->getIdx()->isIntegerConstantExpr(ctx_) && - !lhs->HasSideEffects(ctx_)) { - const auto *array = clang::dyn_cast( - subscript->getBase()->IgnoreParenImpCasts()); + subscript && !lhs->HasSideEffects(ctx_)) { + const auto *root = subscript->getBase()->IgnoreParenImpCasts(); + while (const auto *row = + clang::dyn_cast(root)) { + root = row->getBase()->IgnoreParenImpCasts(); + } + const auto *array = clang::dyn_cast(root); const auto *decl = array ? clang::dyn_cast(array->getDecl()) : nullptr; if (decl && !decl->isImplicit() && decl->getType()->isArrayType()) { - return false; + // An index made from independent by-value variables cannot change when + // this array element is stored. References and indirect reads can. + auto stable_index = [&](auto &&self, const clang::Expr *expr) -> bool { + if (expr->isIntegerConstantExpr(ctx_)) { + return true; + } + expr = expr->IgnoreParenImpCasts(); + if (const auto *ref = clang::dyn_cast(expr)) { + const auto *index = clang::dyn_cast(ref->getDecl()); + return index && index != decl && !index->isImplicit() && + !index->getType()->isReferenceType(); + } + if (const auto *member = clang::dyn_cast(expr)) { + return !member->isArrow() && + !member->getMemberDecl()->getType()->isReferenceType() && + self(self, member->getBase()); + } + if (const auto *element = + clang::dyn_cast(expr)) { + return element->getBase() + ->IgnoreParenImpCasts() + ->getType() + ->isArrayType() && + self(self, element->getBase()) && + self(self, element->getIdx()); + } + if (const auto *binary = clang::dyn_cast(expr); + binary && binary->isPtrMemOp()) { + return false; + } + if (clang::isa(expr) || + (clang::isa(expr) && + clang::cast(expr)->getOpcode() != + clang::UO_Deref)) { + return std::ranges::all_of( + expr->children(), [&](const auto *child) { + const auto *value = + clang::dyn_cast_or_null(child); + return value && self(self, value); + }); + } + return false; + }; + bool stable = true; + for (const auto *element = subscript; element;) { + stable &= stable_index(stable_index, element->getIdx()); + const auto *base = element->getBase()->IgnoreParenImpCasts(); + stable &= base->getType()->isArrayType(); + element = clang::dyn_cast(base); + } + if (stable) { + return false; + } } } if (const auto *member = clang::dyn_cast(target)) { diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index 429b16c490..caed751bb6 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -205,6 +205,23 @@ void test_static_members() { #undef TEST_MEMBERS int main() { + int a[2] = {10, 20}; + int index = 1; + int value = (a[index] = 99); + std::printf("stable index %d %d %d %d\n", index, value, a[0], a[1]); + value = (a[index - 1] = 42); + std::printf("stable arithmetic %d %d %d\n", value, a[0], a[1]); + struct Index { + int value; + } selector{1}; + value = (a[selector.value] = 88); + int rows[2][2] = {{1, 2}, {3, 4}}; + int row_value = (rows[index][index] = 55); + std::printf("stable composite %d %d %d\n", value, a[1], row_value); + int &alias = a[0]; + alias = 0; + value = (a[alias] = 1); + std::printf("aliased index %d %d %d\n", value, a[0], a[1]); test_local_members(); test_global_members(); test_static_members(); diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 48c11f2d82..e7a3605464 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -1425,6 +1425,66 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { + let a: Value> = Rc::new(RefCell::new(Box::new([10, 20]))); + let mut index: i32 = 1; + let mut value: i32 = ({ + (*a.borrow_mut())[(index) as usize] = 99; + (*a.borrow())[(index) as usize] + }); + printf!( + b"stable index %d %d %d %d\n", + index, + value, + (*a.borrow())[(0) as usize], + (*a.borrow())[(1) as usize] + ); + value = ({ + (*a.borrow_mut())[(index - 1) as usize] = 42; + (*a.borrow())[(index - 1) as usize] + }); + printf!( + b"stable arithmetic %d %d %d\n", + value, + (*a.borrow())[(0) as usize], + (*a.borrow())[(1) as usize] + ); + let mut selector: Index_35 = Index_35 { value: 1 }; + value = ({ + (*a.borrow_mut())[(selector.value) as usize] = 88; + (*a.borrow())[(selector.value) as usize] + }); + let rows: Value]>> = + Rc::new(RefCell::new(Box::new([Box::new([1, 2]), Box::new([3, 4])]))); + let mut row_value: i32 = ({ + (*rows.borrow_mut())[(index) as usize][(index) as usize] = 55; + (*rows.borrow())[(index) as usize][(index) as usize] + }); + printf!( + b"stable composite %d %d %d\n", + value, + (*a.borrow())[(1) as usize], + row_value + ); + let alias: Ptr = a.decay().offset(0); + alias.write(0); + let __rhs = ({ + match ({ 1 }, { + let __tmp_103 = a.decay().offset((alias.read())); + __tmp_103 + }) { + (__tmp_102, __tmp_103) => __tmp_103.with_mut(|__tmp_103| { + (*__tmp_103) = __tmp_102; + (*__tmp_103).clone() + }), + } + }); + value = __rhs; + printf!( + b"aliased index %d %d %d\n", + value, + (*a.borrow())[(0) as usize], + (*a.borrow())[(1) as usize] + ); ({ test_local_members_31() }); ({ test_global_members_32() }); ({ test_static_members_33() }); @@ -1447,9 +1507,9 @@ fn main_0() -> i32 { 0 )), ) { - (__tmp_102, __tmp_103) => __tmp_103.with_mut(|__tmp_103| { - (*__tmp_103) = (((*__tmp_103) as u32).wrapping_add((__tmp_102 as u32))) as u32; - (*__tmp_103).clone() + (__tmp_104, __tmp_105) => __tmp_105.with_mut(|__tmp_105| { + (*__tmp_105) = (((*__tmp_105) as u32).wrapping_add((__tmp_104 as u32))) as u32; + (*__tmp_105).clone() }), } }); @@ -1466,17 +1526,17 @@ fn main_0() -> i32 { ({ test_boxed_array_26() }); let mut global_result: u32 = ({ match ({ 1_u32 }, { - let __tmp_105 = global_array_28.with(|v| v.decay()).offset( + let __tmp_107 = global_array_28.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; global_array_28.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_105 + __tmp_107 }) { - (__tmp_104, __tmp_105) => __tmp_105.with_mut(|__tmp_105| { - (*__tmp_105) = (((*__tmp_105) as u32).wrapping_add((__tmp_104 as u32))) as u32; - (*__tmp_105).clone() + (__tmp_106, __tmp_107) => __tmp_107.with_mut(|__tmp_107| { + (*__tmp_107) = (((*__tmp_107) as u32).wrapping_add((__tmp_106 as u32))) as u32; + (*__tmp_107).clone() }), } }); @@ -1491,7 +1551,7 @@ fn main_0() -> i32 { i = 0; result = ({ match ({ 1_u32 }, { - let __tmp_107 = global_rows_29 + let __tmp_109 = global_rows_29 .with(|v| v.decay()) .offset( ({ @@ -1502,11 +1562,11 @@ fn main_0() -> i32 { ) .decay() .offset(0); - __tmp_107 + __tmp_109 }) { - (__tmp_106, __tmp_107) => __tmp_107.with_mut(|__tmp_107| { - (*__tmp_107) = (((*__tmp_107) as u32).wrapping_add((__tmp_106 as u32))) as u32; - (*__tmp_107).clone() + (__tmp_108, __tmp_109) => __tmp_109.with_mut(|__tmp_109| { + (*__tmp_109) = (((*__tmp_109) as u32).wrapping_add((__tmp_108 as u32))) as u32; + (*__tmp_109).clone() }), } }); @@ -1527,6 +1587,12 @@ fn main_0() -> i32 { ); return 0; } +#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(4)] +pub struct Index_35 { + #[offset(0)] + pub value: i32, +} pub trait IndexedBindingImpl { fn get_1_0(&self) -> Ptr; } diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index b3fd171082..020e314976 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -1378,6 +1378,67 @@ pub fn main() { } } unsafe fn main_0() -> i32 { + let mut a: [i32; 2] = [10, 20]; + let mut index: i32 = 1; + let mut value: i32 = ({ + a[(index) as usize] = 99; + a[(index) as usize] + }); + (unsafe { + libc::printf( + c"stable index %d %d %d %d\n".as_ptr() as *const libc::c_char, + (index), + (value), + (a[(0) as usize]), + (a[(1) as usize]), + ) + }); + value = ({ + a[((index) - (1)) as usize] = 42; + a[((index) - (1)) as usize] + }); + (unsafe { + libc::printf( + c"stable arithmetic %d %d %d\n".as_ptr() as *const libc::c_char, + (value), + (a[(0) as usize]), + (a[(1) as usize]), + ) + }); + let mut selector: Index_35 = Index_35 { value: 1 }; + value = ({ + a[(selector.value) as usize] = 88; + a[(selector.value) as usize] + }); + let mut rows: [[i32; 2]; 2] = [[1, 2], [3, 4]]; + let mut row_value: i32 = ({ + rows[(index) as usize][(index) as usize] = 55; + rows[(index) as usize][(index) as usize] + }); + (unsafe { + libc::printf( + c"stable composite %d %d %d\n".as_ptr() as *const libc::c_char, + (value), + (a[(1) as usize]), + (row_value), + ) + }); + let alias: *mut i32 = &mut a[(0) as usize]; + (*alias) = 0; + value = (match ({ 1 }, &mut (a[(*alias) as usize])) { + (__tmp_106, __tmp_107) => { + (*__tmp_107) = __tmp_106; + (*__tmp_107).clone() + } + }); + (unsafe { + libc::printf( + c"aliased index %d %d %d\n".as_ptr() as *const libc::c_char, + (value), + (a[(0) as usize]), + (a[(1) as usize]), + ) + }); (unsafe { test_local_members_31() }); (unsafe { test_global_members_32() }); (unsafe { test_static_members_33() }); @@ -1396,9 +1457,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_106, __tmp_107) => { - (*__tmp_107) = (((*__tmp_107) as u32).wrapping_add((__tmp_106 as u32))) as u32; - (*__tmp_107).clone() + (__tmp_108, __tmp_109) => { + (*__tmp_109) = (((*__tmp_109) as u32).wrapping_add((__tmp_108 as u32))) as u32; + (*__tmp_109).clone() } }); (unsafe { @@ -1420,9 +1481,9 @@ unsafe fn main_0() -> i32 { [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_28))[(0) as usize]) as usize]), ) { - (__tmp_108, __tmp_109) => { - (*__tmp_109) = (((*__tmp_109) as u32).wrapping_add((__tmp_108 as u32))) as u32; - (*__tmp_109).clone() + (__tmp_110, __tmp_111) => { + (*__tmp_111) = (((*__tmp_111) as u32).wrapping_add((__tmp_110 as u32))) as u32; + (*__tmp_111).clone() } }); (unsafe { @@ -1439,9 +1500,9 @@ unsafe fn main_0() -> i32 { [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_29)) [(i.postfix_inc()) as usize][(0) as usize]) as usize][(0) as usize]), ) { - (__tmp_110, __tmp_111) => { - (*__tmp_111) = (((*__tmp_111) as u32).wrapping_add((__tmp_110 as u32))) as u32; - (*__tmp_111).clone() + (__tmp_112, __tmp_113) => { + (*__tmp_113) = (((*__tmp_113) as u32).wrapping_add((__tmp_112 as u32))) as u32; + (*__tmp_113).clone() } }); (unsafe { @@ -1457,6 +1518,11 @@ unsafe fn main_0() -> i32 { }); return 0; } +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Index_35 { + pub value: i32, +} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const global_5); std::cell::LazyCell::force(&*&raw const global_record_8); From f57cc0bcc575591c366a462c03b35305ae055717 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Fri, 27 Nov 2026 22:05:34 +0000 Subject: [PATCH 12/25] Preserve compact lowering for independent indirect targets Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 62 +++- .../converter/models/converter_refcount.cpp | 10 +- tests/unit/assignment_single_eval.cpp | 18 ++ .../out/refcount/assignment_single_eval.rs | 291 +++++++++++------- .../unit/out/unsafe/assignment_single_eval.rs | 231 +++++++++----- 5 files changed, 396 insertions(+), 216 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 16707be5f0..546f4bf876 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -5071,6 +5071,19 @@ bool Converter::NeedsAssignmentBinding( const auto *ref = clang::dyn_cast(target); const auto *var = ref ? clang::dyn_cast(ref->getDecl()) : nullptr; + auto may_alias = [&](const clang::VarDecl *decl) { + if (boxed_vars_) { + return boxed_vars_->contains(decl); + } + if (!decl->getType()->isScalarType() || decl->isInitCapture()) { + return true; + } + auto [entry, inserted] = assignment_vars_.try_emplace(curr_function_); + if (inserted) { + FindAssignmentAliases(curr_function_->getBody(), entry->second); + } + return entry->second.contains(nullptr) || entry->second.contains(decl); + }; bool rhs_effects = rhs->HasSideEffects(ctx_); if (var && !var->isImplicit()) { // A variable's storage never changes. Only compound assignments can read @@ -5101,17 +5114,7 @@ bool Converter::NeedsAssignmentBinding( }); }; if (!refers_to_var(refers_to_var, rhs)) { - if (boxed_vars_) { - return boxed_vars_->contains(var); - } - if (!var->getType()->isScalarType() || var->isInitCapture()) { - return true; - } - auto [entry, inserted] = assignment_vars_.try_emplace(curr_function_); - if (inserted) { - FindAssignmentAliases(curr_function_->getBody(), entry->second); - } - return entry->second.contains(nullptr) || entry->second.contains(var); + return may_alias(var); } return true; } @@ -5212,6 +5215,43 @@ bool Converter::NeedsAssignmentBinding( call->getArg(1)->isIntegerConstantExpr(ctx_)) { return false; } + // Indirect places can also be reread when all values used to select them + // are local scalars that no pointer can modify. Reference bindings do not + // rebind, but reading through a reference is not an isolated scalar read. + auto stable_reads = [&](auto &&self, const clang::Stmt *stmt) -> bool { + if (const auto *expr = clang::dyn_cast(stmt); + expr && expr->isIntegerConstantExpr(ctx_)) { + return true; + } + if (clang::isa(stmt)) { + return false; + } + if (const auto *ref = clang::dyn_cast(stmt)) { + const auto *decl = clang::dyn_cast(ref->getDecl()); + if (!decl || decl->isImplicit()) { + return false; + } + } + if (const auto *cast = clang::dyn_cast(stmt); + cast && cast->getCastKind() == clang::CK_LValueToRValue) { + const auto *ref = clang::dyn_cast( + cast->getSubExpr()->IgnoreParenImpCasts()); + const auto *read = + ref ? clang::dyn_cast(ref->getDecl()) : nullptr; + return read && !read->isImplicit() && curr_function_ && + read->getDeclContext() == curr_function_ && + (read->isLocalVarDecl() || + clang::isa(read)) && + !IsGlobalVar(read) && !read->isInitCapture() && + read->getType()->isScalarType() && !may_alias(read); + } + return std::ranges::all_of(stmt->children(), [&](const auto *child) { + return !child || self(self, child); + }); + }; + if (!lhs->HasSideEffects(ctx_) && stable_reads(stable_reads, lhs)) { + return false; + } } if (lhs->HasSideEffects(ctx_) || rhs_effects) { return true; diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 0af9780721..bb8845b7ff 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -2517,9 +2517,11 @@ void ConverterRefCount::ConvertAssignment( bool fixed_index = subscript && decl && !decl->isImplicit() && decl->getType()->isArrayType() && subscript->getIdx()->isIntegerConstantExpr(ctx_); - bool boxed_array = subscript && !IsPointerSubscript(subscript) && - !IsUnboxedPlace(base) && !fixed_index; - if (boxed_array) { + bool staged_subscript = + subscript && !fixed_index && + ((!IsPointerSubscript(subscript) && !IsUnboxedPlace(base)) || + (IsPointerSubscript(subscript) && ReadsMemory(subscript->getIdx()))); + if (staged_subscript) { // Resolve the index before borrowing the array, as it may read the same // storage. The pointer keeps the selected element, not an active borrow. auto ptr = ConvertFreshPointer(lhs); @@ -2534,7 +2536,7 @@ void ConverterRefCount::ConvertAssignment( // after the right operand, keeping its temporaries alive through the write. StrCat("match ({ ", rhs_value, " }, "); bool through_pointer = !pending_deref_.empty(); - if (boxed_array) { + if (staged_subscript) { // End incidental index borrows before with_mut takes the write borrow. StrCat("{ let ", left, token::kAssign, pending_deref_.take(), token::kSemiColon, left, "}"); diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index caed751bb6..5ae177bf47 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -222,6 +222,24 @@ int main() { alias = 0; value = (a[alias] = 1); std::printf("aliased index %d %d %d\n", value, a[0], a[1]); + int *pointer = a; + int (&reference)[2] = a; + value = (pointer[index] = 66); + int reference_value = (reference[index] = 77); + int deref_value = (*pointer = 55); + std::printf("stable indirect %d %d %d %d %d\n", value, reference_value, + deref_value, a[0], a[1]); + int self_index = 0; + int *self = &self_index; + value = (self[self_index] = 1); + std::printf("aliased indirect %d %d\n", value, self_index); + int captured_index = 0; + int *captured_pointer = &captured_index; + auto assign_captured = [&] { + return (captured_pointer[captured_index] = 10000); + }; + value = assign_captured(); + std::printf("captured indirect %d %d\n", value, captured_index); test_local_members(); test_global_members(); test_static_members(); diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index e7a3605464..57fc61c261 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -659,27 +659,20 @@ pub fn test_borrows_12() { b"%d\n", ({ observe_record_9({ - match ( - { 99 }, - &mut ((*global_record_8.with(Value::clone).borrow_mut()) - .inner - .value), - ) { - (__tmp_60, __tmp_61) => { - (*__tmp_61) = __tmp_60; - (*__tmp_61).clone() - } - } + (*global_record_8.with(Value::clone).borrow_mut()) + .inner + .value = 99; + { global_record_8.with(|rc| *rc.borrow()).inner.value } }) }) ); let mut shifted: Ptr = ({ - let __tmp_62 = { + let __tmp_60 = { cursor_11 .with(|rc| *rc.borrow_mut() = targets_10.with(|v| v.decay()).offset((1) as isize)); 1 }; - cursor_11.with(|rc| *rc.borrow_mut() -= (__tmp_62 as isize)); + cursor_11.with(|rc| *rc.borrow_mut() -= (__tmp_60 as isize)); (*cursor_11.with(Value::clone).borrow()).clone() }); printf!( @@ -748,9 +741,9 @@ pub fn test_borrows_12() { { (second.as_pointer()) }, &(field!((selector.read()), next)), ) { - (__tmp_63, __tmp_64) => __tmp_64.with_mut(|__tmp_64| { - (*__tmp_64) = __tmp_63; - (*__tmp_64).clone() + (__tmp_61, __tmp_62) => __tmp_62.with_mut(|__tmp_62| { + (*__tmp_62) = __tmp_61; + (*__tmp_62).clone() }), } }); @@ -815,9 +808,9 @@ pub fn test_binding_18() { let value: Ptr = ({ IndexedBindingImpl::get_1_0(&__decomp_19) }); let mut result: u32 = ({ match ({ 1_u32 }, &({ IndexedBindingImpl::get_1_0(&__decomp_19) })) { - (__tmp_65, __tmp_66) => __tmp_66.with_mut(|__tmp_66| { - (*__tmp_66) = (((*__tmp_66) as u32).wrapping_add((__tmp_65 as u32))) as u32; - (*__tmp_66).clone() + (__tmp_63, __tmp_64) => __tmp_64.with_mut(|__tmp_64| { + (*__tmp_64) = (((*__tmp_64) as u32).wrapping_add((__tmp_63 as u32))) as u32; + (*__tmp_64).clone() }), } }); @@ -840,10 +833,10 @@ pub fn mutate_initializer_21() -> u32 { thread_local!( pub static initializer_result_22: Value = Rc::new(RefCell::new( ({ - let __tmp_67 = ({ mutate_initializer_21() }); + let __tmp_65 = ({ mutate_initializer_21() }); { let rhs_0 = ((initializer_target_20.with(|rc| *rc.borrow()) as u32) - .wrapping_add((__tmp_67 as u32))) as u32; + .wrapping_add((__tmp_65 as u32))) as u32; { let __rhs = rhs_0; initializer_target_20.with(|rc| *rc.borrow_mut() = __rhs) @@ -866,9 +859,9 @@ pub fn test_alias_scopes_23(parameter: i16) { }, &mut (*parameter.borrow_mut()), ) { - (__tmp_68, __tmp_69) => { - (*__tmp_69) = (((*__tmp_69) as f64) + (__tmp_68 as f64)) as i16; - (*__tmp_69).clone() + (__tmp_66, __tmp_67) => { + (*__tmp_67) = (((*__tmp_67) as f64) + (__tmp_66 as f64)) as i16; + (*__tmp_67).clone() } } }); @@ -892,9 +885,9 @@ pub fn test_alias_scopes_23(parameter: i16) { { ({ (*mutate.borrow()).call() }).clone() }, &mut (*local.borrow_mut()), ) { - (__tmp_70, __tmp_71) => { - (*__tmp_71) = (((*__tmp_71) as f64) + (__tmp_70 as f64)) as i16; - (*__tmp_71).clone() + (__tmp_68, __tmp_69) => { + (*__tmp_69) = (((*__tmp_69) as f64) + (__tmp_68 as f64)) as i16; + (*__tmp_69).clone() } } }); @@ -915,12 +908,12 @@ pub fn test_boxed_array_24() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_73 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_73 + let __tmp_71 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_71 }) { - (__tmp_72, __tmp_73) => __tmp_73.with_mut(|__tmp_73| { - (*__tmp_73) = (((*__tmp_73) as u32).wrapping_add((__tmp_72 as u32))) as u32; - (*__tmp_73).clone() + (__tmp_70, __tmp_71) => __tmp_71.with_mut(|__tmp_71| { + (*__tmp_71) = (((*__tmp_71) as u32).wrapping_add((__tmp_70 as u32))) as u32; + (*__tmp_71).clone() }), } }); @@ -935,12 +928,12 @@ pub fn test_boxed_array_24() { i = 0; result = ({ match ({ 1_u32 }, { - let __tmp_75 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_75 + let __tmp_73 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_73 }) { - (__tmp_74, __tmp_75) => __tmp_75.with_mut(|__tmp_75| { - (*__tmp_75) = __tmp_74; - (*__tmp_75).clone() + (__tmp_72, __tmp_73) => __tmp_73.with_mut(|__tmp_73| { + (*__tmp_73) = __tmp_72; + (*__tmp_73).clone() }), } }); @@ -953,17 +946,17 @@ pub fn test_boxed_array_24() { ); result = ({ match ({ 1_u32 }, { - let __tmp_77 = saved_25.with(|v| v.decay()).offset( + let __tmp_75 = saved_25.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; saved_25.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_77 + __tmp_75 }) { - (__tmp_76, __tmp_77) => __tmp_77.with_mut(|__tmp_77| { - (*__tmp_77) = (((*__tmp_77) as u32).wrapping_add((__tmp_76 as u32))) as u32; - (*__tmp_77).clone() + (__tmp_74, __tmp_75) => __tmp_75.with_mut(|__tmp_75| { + (*__tmp_75) = (((*__tmp_75) as u32).wrapping_add((__tmp_74 as u32))) as u32; + (*__tmp_75).clone() }), } }); @@ -982,12 +975,12 @@ pub fn test_boxed_array_26() { let mut i: i32 = 0; let mut result: i16 = ({ match ({ 1 }, { - let __tmp_79 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_79 + let __tmp_77 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_77 }) { - (__tmp_78, __tmp_79) => __tmp_79.with_mut(|__tmp_79| { - (*__tmp_79) = (((*__tmp_79) as i32) + (__tmp_78 as i32)) as i16; - (*__tmp_79).clone() + (__tmp_76, __tmp_77) => __tmp_77.with_mut(|__tmp_77| { + (*__tmp_77) = (((*__tmp_77) as i32) + (__tmp_76 as i32)) as i16; + (*__tmp_77).clone() }), } }); @@ -1002,12 +995,12 @@ pub fn test_boxed_array_26() { i = 0; result = ({ match ({ 1_i16 }, { - let __tmp_81 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_81 + let __tmp_79 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_79 }) { - (__tmp_80, __tmp_81) => __tmp_81.with_mut(|__tmp_81| { - (*__tmp_81) = __tmp_80; - (*__tmp_81).clone() + (__tmp_78, __tmp_79) => __tmp_79.with_mut(|__tmp_79| { + (*__tmp_79) = __tmp_78; + (*__tmp_79).clone() }), } }); @@ -1020,17 +1013,17 @@ pub fn test_boxed_array_26() { ); result = ({ match ({ 1 }, { - let __tmp_83 = saved_27.with(|v| v.decay()).offset( + let __tmp_81 = saved_27.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; saved_27.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_83 + __tmp_81 }) { - (__tmp_82, __tmp_83) => __tmp_83.with_mut(|__tmp_83| { - (*__tmp_83) = (((*__tmp_83) as i32) + (__tmp_82 as i32)) as i16; - (*__tmp_83).clone() + (__tmp_80, __tmp_81) => __tmp_81.with_mut(|__tmp_81| { + (*__tmp_81) = (((*__tmp_81) as i32) + (__tmp_80 as i32)) as i16; + (*__tmp_81).clone() }), } }); @@ -1100,16 +1093,16 @@ pub fn test_local_members_31() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_85 = field_ptr!( + let __tmp_83 = field_ptr!( a.decay() .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), value ); - __tmp_85 + __tmp_83 }) { - (__tmp_84, __tmp_85) => __tmp_85.with_mut(|__tmp_85| { - (*__tmp_85) = (((*__tmp_85) as u32).wrapping_add((__tmp_84 as u32))) as u32; - (*__tmp_85).clone() + (__tmp_82, __tmp_83) => __tmp_83.with_mut(|__tmp_83| { + (*__tmp_83) = (((*__tmp_83) as u32).wrapping_add((__tmp_82 as u32))) as u32; + (*__tmp_83).clone() }), } }); @@ -1123,15 +1116,15 @@ pub fn test_local_members_31() { i = 0; { match ({ 1 }, { - let __tmp_87 = field_ptr!( + let __tmp_85 = field_ptr!( a.decay() .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), promoted ); - __tmp_87 + __tmp_85 }) { - (__tmp_86, __tmp_87) => __tmp_87.with_mut(|__tmp_87| { - (*__tmp_87) = (((*__tmp_87) as i32) + (__tmp_86 as i32)) as i16; + (__tmp_84, __tmp_85) => __tmp_85.with_mut(|__tmp_85| { + (*__tmp_85) = (((*__tmp_85) as i32) + (__tmp_84 as i32)) as i16; }), } }; @@ -1144,16 +1137,16 @@ pub fn test_local_members_31() { i = 0; result = ({ match ({ 99_u32 }, { - let __tmp_89 = field_ptr!( + let __tmp_87 = field_ptr!( a.decay() .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), value ); - __tmp_89 + __tmp_87 }) { - (__tmp_88, __tmp_89) => __tmp_89.with_mut(|__tmp_89| { - (*__tmp_89) = __tmp_88; - (*__tmp_89).clone() + (__tmp_86, __tmp_87) => __tmp_87.with_mut(|__tmp_87| { + (*__tmp_87) = __tmp_86; + (*__tmp_87).clone() }), } }); @@ -1170,7 +1163,7 @@ pub fn test_global_members_32() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_91 = field_ptr!( + let __tmp_89 = field_ptr!( global_members_30.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; @@ -1180,11 +1173,11 @@ pub fn test_global_members_32() { }), value ); - __tmp_91 + __tmp_89 }) { - (__tmp_90, __tmp_91) => __tmp_91.with_mut(|__tmp_91| { - (*__tmp_91) = (((*__tmp_91) as u32).wrapping_add((__tmp_90 as u32))) as u32; - (*__tmp_91).clone() + (__tmp_88, __tmp_89) => __tmp_89.with_mut(|__tmp_89| { + (*__tmp_89) = (((*__tmp_89) as u32).wrapping_add((__tmp_88 as u32))) as u32; + (*__tmp_89).clone() }), } }); @@ -1210,7 +1203,7 @@ pub fn test_global_members_32() { i = 0; { match ({ 1 }, { - let __tmp_93 = field_ptr!( + let __tmp_91 = field_ptr!( global_members_30.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; @@ -1220,10 +1213,10 @@ pub fn test_global_members_32() { }), promoted ); - __tmp_93 + __tmp_91 }) { - (__tmp_92, __tmp_93) => __tmp_93.with_mut(|__tmp_93| { - (*__tmp_93) = (((*__tmp_93) as i32) + (__tmp_92 as i32)) as i16; + (__tmp_90, __tmp_91) => __tmp_91.with_mut(|__tmp_91| { + (*__tmp_91) = (((*__tmp_91) as i32) + (__tmp_90 as i32)) as i16; }), } }; @@ -1248,7 +1241,7 @@ pub fn test_global_members_32() { i = 0; result = ({ match ({ 99_u32 }, { - let __tmp_95 = field_ptr!( + let __tmp_93 = field_ptr!( global_members_30.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; @@ -1258,11 +1251,11 @@ pub fn test_global_members_32() { }), value ); - __tmp_95 + __tmp_93 }) { - (__tmp_94, __tmp_95) => __tmp_95.with_mut(|__tmp_95| { - (*__tmp_95) = __tmp_94; - (*__tmp_95).clone() + (__tmp_92, __tmp_93) => __tmp_93.with_mut(|__tmp_93| { + (*__tmp_93) = __tmp_92; + (*__tmp_93).clone() }), } }); @@ -1290,7 +1283,7 @@ pub fn test_static_members_33() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_97 = field_ptr!( + let __tmp_95 = field_ptr!( a_34.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; @@ -1300,11 +1293,11 @@ pub fn test_static_members_33() { }), value ); - __tmp_97 + __tmp_95 }) { - (__tmp_96, __tmp_97) => __tmp_97.with_mut(|__tmp_97| { - (*__tmp_97) = (((*__tmp_97) as u32).wrapping_add((__tmp_96 as u32))) as u32; - (*__tmp_97).clone() + (__tmp_94, __tmp_95) => __tmp_95.with_mut(|__tmp_95| { + (*__tmp_95) = (((*__tmp_95) as u32).wrapping_add((__tmp_94 as u32))) as u32; + (*__tmp_95).clone() }), } }); @@ -1330,7 +1323,7 @@ pub fn test_static_members_33() { i = 0; { match ({ 1 }, { - let __tmp_99 = field_ptr!( + let __tmp_97 = field_ptr!( a_34.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; @@ -1340,10 +1333,10 @@ pub fn test_static_members_33() { }), promoted ); - __tmp_99 + __tmp_97 }) { - (__tmp_98, __tmp_99) => __tmp_99.with_mut(|__tmp_99| { - (*__tmp_99) = (((*__tmp_99) as i32) + (__tmp_98 as i32)) as i16; + (__tmp_96, __tmp_97) => __tmp_97.with_mut(|__tmp_97| { + (*__tmp_97) = (((*__tmp_97) as i32) + (__tmp_96 as i32)) as i16; }), } }; @@ -1368,7 +1361,7 @@ pub fn test_static_members_33() { i = 0; result = ({ match ({ 99_u32 }, { - let __tmp_101 = field_ptr!( + let __tmp_99 = field_ptr!( a_34.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; @@ -1378,11 +1371,11 @@ pub fn test_static_members_33() { }), value ); - __tmp_101 + __tmp_99 }) { - (__tmp_100, __tmp_101) => __tmp_101.with_mut(|__tmp_101| { - (*__tmp_101) = __tmp_100; - (*__tmp_101).clone() + (__tmp_98, __tmp_99) => __tmp_99.with_mut(|__tmp_99| { + (*__tmp_99) = __tmp_98; + (*__tmp_99).clone() }), } }); @@ -1469,7 +1462,50 @@ fn main_0() -> i32 { alias.write(0); let __rhs = ({ match ({ 1 }, { - let __tmp_103 = a.decay().offset((alias.read())); + let __tmp_101 = a.decay().offset((alias.read())); + __tmp_101 + }) { + (__tmp_100, __tmp_101) => __tmp_101.with_mut(|__tmp_101| { + (*__tmp_101) = __tmp_100; + (*__tmp_101).clone() + }), + } + }); + value = __rhs; + printf!( + b"aliased index %d %d %d\n", + value, + (*a.borrow())[(0) as usize], + (*a.borrow())[(1) as usize] + ); + let mut pointer: Ptr = a.decay(); + let reference: Ptr = a.decay(); + let __rhs = ({ + elem!(pointer, index).write(66); + (elem!(pointer, index).read()) + }); + value = __rhs; + let mut reference_value: i32 = ({ + elem!(reference, index).write(77); + (elem!(reference, index).read()) + }); + let mut deref_value: i32 = ({ + pointer.write(55); + (pointer.read()) + }); + printf!( + b"stable indirect %d %d %d %d %d\n", + value, + reference_value, + deref_value, + (*a.borrow())[(0) as usize], + (*a.borrow())[(1) as usize] + ); + let self_index: Value = Rc::new(RefCell::new(0)); + let mut self_: Ptr = (self_index.as_pointer()); + let __rhs = ({ + match ({ 1 }, { + let __tmp_103 = self_.offset((*self_index.borrow()) as isize); __tmp_103 }) { (__tmp_102, __tmp_103) => __tmp_103.with_mut(|__tmp_103| { @@ -1479,11 +1515,34 @@ fn main_0() -> i32 { } }); value = __rhs; + printf!(b"aliased indirect %d %d\n", value, (*self_index.borrow())); + let captured_index: Value = Rc::new(RefCell::new(0)); + let captured_pointer: Value> = Rc::new(RefCell::new((captured_index.as_pointer()))); + let assign_captured: Value i32>> = Rc::new(RefCell::new(lambda!( + { + let captured_pointer: Ptr> = captured_pointer.as_pointer(); + let captured_index: Ptr = captured_index.as_pointer(); + }, + || -> i32 { + return ({ + match ({ 10000 }, { + let __tmp_105 = + (captured_pointer.read()).offset((captured_index.read()) as isize); + __tmp_105 + }) { + (__tmp_104, __tmp_105) => __tmp_105.with_mut(|__tmp_105| { + (*__tmp_105) = __tmp_104; + (*__tmp_105).clone() + }), + } + }); + } + ))); + value = ({ (*assign_captured.borrow()).call() }).clone(); printf!( - b"aliased index %d %d %d\n", + b"captured indirect %d %d\n", value, - (*a.borrow())[(0) as usize], - (*a.borrow())[(1) as usize] + (*captured_index.borrow()) ); ({ test_local_members_31() }); ({ test_global_members_32() }); @@ -1507,9 +1566,9 @@ fn main_0() -> i32 { 0 )), ) { - (__tmp_104, __tmp_105) => __tmp_105.with_mut(|__tmp_105| { - (*__tmp_105) = (((*__tmp_105) as u32).wrapping_add((__tmp_104 as u32))) as u32; - (*__tmp_105).clone() + (__tmp_106, __tmp_107) => __tmp_107.with_mut(|__tmp_107| { + (*__tmp_107) = (((*__tmp_107) as u32).wrapping_add((__tmp_106 as u32))) as u32; + (*__tmp_107).clone() }), } }); @@ -1526,17 +1585,17 @@ fn main_0() -> i32 { ({ test_boxed_array_26() }); let mut global_result: u32 = ({ match ({ 1_u32 }, { - let __tmp_107 = global_array_28.with(|v| v.decay()).offset( + let __tmp_109 = global_array_28.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; global_array_28.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_107 + __tmp_109 }) { - (__tmp_106, __tmp_107) => __tmp_107.with_mut(|__tmp_107| { - (*__tmp_107) = (((*__tmp_107) as u32).wrapping_add((__tmp_106 as u32))) as u32; - (*__tmp_107).clone() + (__tmp_108, __tmp_109) => __tmp_109.with_mut(|__tmp_109| { + (*__tmp_109) = (((*__tmp_109) as u32).wrapping_add((__tmp_108 as u32))) as u32; + (*__tmp_109).clone() }), } }); @@ -1551,7 +1610,7 @@ fn main_0() -> i32 { i = 0; result = ({ match ({ 1_u32 }, { - let __tmp_109 = global_rows_29 + let __tmp_111 = global_rows_29 .with(|v| v.decay()) .offset( ({ @@ -1562,11 +1621,11 @@ fn main_0() -> i32 { ) .decay() .offset(0); - __tmp_109 + __tmp_111 }) { - (__tmp_108, __tmp_109) => __tmp_109.with_mut(|__tmp_109| { - (*__tmp_109) = (((*__tmp_109) as u32).wrapping_add((__tmp_108 as u32))) as u32; - (*__tmp_109).clone() + (__tmp_110, __tmp_111) => __tmp_111.with_mut(|__tmp_111| { + (*__tmp_111) = (((*__tmp_111) as u32).wrapping_add((__tmp_110 as u32))) as u32; + (*__tmp_111).clone() }), } }); diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 020e314976..fada23ee2e 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -728,19 +728,14 @@ pub unsafe fn test_borrows_12() { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - observe_record_9( - match ( - { 99 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_8)) - .inner - .value), - ) { - (__tmp_62, __tmp_63) => { - (*__tmp_63) = __tmp_62; - (*__tmp_63).clone() - } - }, - ) + observe_record_9({ + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_8)) + .inner + .value = 99; + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_8)) + .inner + .value + }) }), ) }); @@ -756,9 +751,9 @@ pub unsafe fn test_borrows_12() { }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_11)), ) { - (__tmp_64, __tmp_65) => { - (*__tmp_65) = (*__tmp_65).offset(-(__tmp_64 as isize)); - (*__tmp_65).clone() + (__tmp_62, __tmp_63) => { + (*__tmp_63) = (*__tmp_63).offset(-(__tmp_62 as isize)); + (*__tmp_63).clone() } }); (unsafe { @@ -836,9 +831,9 @@ pub unsafe fn test_borrows_12() { { (&mut second as *mut Link_16) }, &mut ((*(*selector)).next), ) { - (__tmp_66, __tmp_67) => { - (*__tmp_67) = __tmp_66; - (*__tmp_67).clone() + (__tmp_64, __tmp_65) => { + (*__tmp_65) = __tmp_64; + (*__tmp_65).clone() } }); (unsafe { @@ -908,9 +903,9 @@ pub unsafe fn test_binding_18() { { 1_u32 }, &mut (*(unsafe { IndexedBinding::get_1_0(&mut (*__decomp_19)) })), ) { - (__tmp_68, __tmp_69) => { - (*__tmp_69) = (((*__tmp_69) as u32).wrapping_add((__tmp_68 as u32))) as u32; - (*__tmp_69).clone() + (__tmp_66, __tmp_67) => { + (*__tmp_67) = (((*__tmp_67) as u32).wrapping_add((__tmp_66 as u32))) as u32; + (*__tmp_67).clone() } }); (unsafe { @@ -933,9 +928,9 @@ pub static mut initializer_result_22: std::cell::LazyCell = { (unsafe { mutate_initializer_21() }) }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_20)), ) { - (__tmp_70, __tmp_71) => { - (*__tmp_71) = (((*__tmp_71) as u32).wrapping_add((__tmp_70 as u32))) as u32; - (*__tmp_71).clone() + (__tmp_68, __tmp_69) => { + (*__tmp_69) = (((*__tmp_69) as u32).wrapping_add((__tmp_68 as u32))) as u32; + (*__tmp_69).clone() } }) }); @@ -950,9 +945,9 @@ pub unsafe fn test_alias_scopes_23(mut parameter: i16) { }, &mut (parameter), ) { - (__tmp_72, __tmp_73) => { - (*__tmp_73) = (((*__tmp_73) as f64) + (__tmp_72 as f64)) as i16; - (*__tmp_73).clone() + (__tmp_70, __tmp_71) => { + (*__tmp_71) = (((*__tmp_71) as f64) + (__tmp_70 as f64)) as i16; + (*__tmp_71).clone() } }); (unsafe { @@ -973,9 +968,9 @@ pub unsafe fn test_alias_scopes_23(mut parameter: i16) { } ); result = (match ({ (unsafe { mutate.call() }).clone() }, &mut (local)) { - (__tmp_74, __tmp_75) => { - (*__tmp_75) = (((*__tmp_75) as f64) + (__tmp_74 as f64)) as i16; - (*__tmp_75).clone() + (__tmp_72, __tmp_73) => { + (*__tmp_73) = (((*__tmp_73) as f64) + (__tmp_72 as f64)) as i16; + (*__tmp_73).clone() } }); (unsafe { @@ -1001,9 +996,9 @@ pub unsafe fn test_boxed_array_24() { { 1_u32 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), ) { - (__tmp_76, __tmp_77) => { - (*__tmp_77) = (((*__tmp_77) as u32).wrapping_add((__tmp_76 as u32))) as u32; - (*__tmp_77).clone() + (__tmp_74, __tmp_75) => { + (*__tmp_75) = (((*__tmp_75) as u32).wrapping_add((__tmp_74 as u32))) as u32; + (*__tmp_75).clone() } }); (unsafe { @@ -1021,9 +1016,9 @@ pub unsafe fn test_boxed_array_24() { { 1_u32 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), ) { - (__tmp_78, __tmp_79) => { - (*__tmp_79) = __tmp_78; - (*__tmp_79).clone() + (__tmp_76, __tmp_77) => { + (*__tmp_77) = __tmp_76; + (*__tmp_77).clone() } }); (unsafe { @@ -1040,9 +1035,9 @@ pub unsafe fn test_boxed_array_24() { &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_25)) [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_25))[(0) as usize]) as usize]), ) { - (__tmp_80, __tmp_81) => { - (*__tmp_81) = (((*__tmp_81) as u32).wrapping_add((__tmp_80 as u32))) as u32; - (*__tmp_81).clone() + (__tmp_78, __tmp_79) => { + (*__tmp_79) = (((*__tmp_79) as u32).wrapping_add((__tmp_78 as u32))) as u32; + (*__tmp_79).clone() } }); (unsafe { @@ -1058,9 +1053,9 @@ pub unsafe fn test_boxed_array_26() { let mut p: *mut i16 = a.as_mut_ptr(); let mut i: i32 = 0; let mut result: i16 = (match ({ 1 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize])) { - (__tmp_82, __tmp_83) => { - (*__tmp_83) = (((*__tmp_83) as i32) + (__tmp_82 as i32)) as i16; - (*__tmp_83).clone() + (__tmp_80, __tmp_81) => { + (*__tmp_81) = (((*__tmp_81) as i32) + (__tmp_80 as i32)) as i16; + (*__tmp_81).clone() } }); (unsafe { @@ -1078,9 +1073,9 @@ pub unsafe fn test_boxed_array_26() { { 1_i16 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), ) { - (__tmp_84, __tmp_85) => { - (*__tmp_85) = __tmp_84; - (*__tmp_85).clone() + (__tmp_82, __tmp_83) => { + (*__tmp_83) = __tmp_82; + (*__tmp_83).clone() } }); (unsafe { @@ -1097,9 +1092,9 @@ pub unsafe fn test_boxed_array_26() { &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_27)) [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_27))[(0) as usize]) as usize]), ) { - (__tmp_86, __tmp_87) => { - (*__tmp_87) = (((*__tmp_87) as i32) + (__tmp_86 as i32)) as i16; - (*__tmp_87).clone() + (__tmp_84, __tmp_85) => { + (*__tmp_85) = (((*__tmp_85) as i32) + (__tmp_84 as i32)) as i16; + (*__tmp_85).clone() } }); (unsafe { @@ -1159,9 +1154,9 @@ pub unsafe fn test_local_members_31() { { 1_u32 }, &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].value), ) { - (__tmp_88, __tmp_89) => { - (*__tmp_89) = (((*__tmp_89) as u32).wrapping_add((__tmp_88 as u32))) as u32; - (*__tmp_89).clone() + (__tmp_86, __tmp_87) => { + (*__tmp_87) = (((*__tmp_87) as u32).wrapping_add((__tmp_86 as u32))) as u32; + (*__tmp_87).clone() } }); (unsafe { @@ -1178,8 +1173,8 @@ pub unsafe fn test_local_members_31() { { 1 }, &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].promoted), ) { - (__tmp_90, __tmp_91) => { - (*__tmp_91) = (((*__tmp_91) as i32) + (__tmp_90 as i32)) as i16; + (__tmp_88, __tmp_89) => { + (*__tmp_89) = (((*__tmp_89) as i32) + (__tmp_88 as i32)) as i16; } }; (unsafe { @@ -1195,9 +1190,9 @@ pub unsafe fn test_local_members_31() { { 99_u32 }, &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].value), ) { - (__tmp_92, __tmp_93) => { - (*__tmp_93) = __tmp_92; - (*__tmp_93).clone() + (__tmp_90, __tmp_91) => { + (*__tmp_91) = __tmp_90; + (*__tmp_91).clone() } }); (unsafe { @@ -1226,9 +1221,9 @@ pub unsafe fn test_global_members_32() { .key) as usize] .value), ) { - (__tmp_94, __tmp_95) => { - (*__tmp_95) = (((*__tmp_95) as u32).wrapping_add((__tmp_94 as u32))) as u32; - (*__tmp_95).clone() + (__tmp_92, __tmp_93) => { + (*__tmp_93) = (((*__tmp_93) as u32).wrapping_add((__tmp_92 as u32))) as u32; + (*__tmp_93).clone() } }); (unsafe { @@ -1251,8 +1246,8 @@ pub unsafe fn test_global_members_32() { .key) as usize] .promoted), ) { - (__tmp_96, __tmp_97) => { - (*__tmp_97) = (((*__tmp_97) as i32) + (__tmp_96 as i32)) as i16; + (__tmp_94, __tmp_95) => { + (*__tmp_95) = (((*__tmp_95) as i32) + (__tmp_94 as i32)) as i16; } }; (unsafe { @@ -1274,9 +1269,9 @@ pub unsafe fn test_global_members_32() { .key) as usize] .value), ) { - (__tmp_98, __tmp_99) => { - (*__tmp_99) = __tmp_98; - (*__tmp_99).clone() + (__tmp_96, __tmp_97) => { + (*__tmp_97) = __tmp_96; + (*__tmp_97).clone() } }); (unsafe { @@ -1300,9 +1295,9 @@ pub unsafe fn test_static_members_33() { .key) as usize] .value), ) { - (__tmp_100, __tmp_101) => { - (*__tmp_101) = (((*__tmp_101) as u32).wrapping_add((__tmp_100 as u32))) as u32; - (*__tmp_101).clone() + (__tmp_98, __tmp_99) => { + (*__tmp_99) = (((*__tmp_99) as u32).wrapping_add((__tmp_98 as u32))) as u32; + (*__tmp_99).clone() } }); (unsafe { @@ -1322,8 +1317,8 @@ pub unsafe fn test_static_members_33() { .key) as usize] .promoted), ) { - (__tmp_102, __tmp_103) => { - (*__tmp_103) = (((*__tmp_103) as i32) + (__tmp_102 as i32)) as i16; + (__tmp_100, __tmp_101) => { + (*__tmp_101) = (((*__tmp_101) as i32) + (__tmp_100 as i32)) as i16; } }; (unsafe { @@ -1342,9 +1337,9 @@ pub unsafe fn test_static_members_33() { .key) as usize] .value), ) { - (__tmp_104, __tmp_105) => { - (*__tmp_105) = __tmp_104; - (*__tmp_105).clone() + (__tmp_102, __tmp_103) => { + (*__tmp_103) = __tmp_102; + (*__tmp_103).clone() } }); (unsafe { @@ -1426,9 +1421,9 @@ unsafe fn main_0() -> i32 { let alias: *mut i32 = &mut a[(0) as usize]; (*alias) = 0; value = (match ({ 1 }, &mut (a[(*alias) as usize])) { - (__tmp_106, __tmp_107) => { - (*__tmp_107) = __tmp_106; - (*__tmp_107).clone() + (__tmp_104, __tmp_105) => { + (*__tmp_105) = __tmp_104; + (*__tmp_105).clone() } }); (unsafe { @@ -1439,6 +1434,72 @@ unsafe fn main_0() -> i32 { (a[(1) as usize]), ) }); + let mut pointer: *mut i32 = a.as_mut_ptr(); + let reference: *mut [i32; 2] = &mut a; + value = ({ + (*pointer.offset((index) as isize)) = 66; + (*pointer.offset((index) as isize)) + }); + let mut reference_value: i32 = ({ + (*reference)[(index) as usize] = 77; + (*reference)[(index) as usize] + }); + let mut deref_value: i32 = ({ + (*pointer) = 55; + (*pointer) + }); + (unsafe { + libc::printf( + c"stable indirect %d %d %d %d %d\n".as_ptr() as *const libc::c_char, + (value), + (reference_value), + (deref_value), + (a[(0) as usize]), + (a[(1) as usize]), + ) + }); + let mut self_index: i32 = 0; + let mut self_: *mut i32 = (&mut self_index as *mut i32); + value = (match ({ 1 }, &mut (*self_.offset((self_index) as isize))) { + (__tmp_106, __tmp_107) => { + (*__tmp_107) = __tmp_106; + (*__tmp_107).clone() + } + }); + (unsafe { + libc::printf( + c"aliased indirect %d %d\n".as_ptr() as *const libc::c_char, + (value), + (self_index), + ) + }); + let mut captured_index: i32 = 0; + let mut captured_pointer: *mut i32 = (&mut captured_index as *mut i32); + let mut assign_captured: FnPtr i32> = lambda_unsafe!( + { + let captured_pointer: *mut *mut i32 = &mut captured_pointer; + let captured_index: *mut i32 = &mut captured_index; + }, + || -> i32 { + return (match ( + { 10000 }, + &mut (*(*captured_pointer).offset((*captured_index) as isize)), + ) { + (__tmp_108, __tmp_109) => { + (*__tmp_109) = __tmp_108; + (*__tmp_109).clone() + } + }); + } + ); + value = (unsafe { assign_captured.call() }).clone(); + (unsafe { + libc::printf( + c"captured indirect %d %d\n".as_ptr() as *const libc::c_char, + (value), + (captured_index), + ) + }); (unsafe { test_local_members_31() }); (unsafe { test_global_members_32() }); (unsafe { test_static_members_33() }); @@ -1457,9 +1518,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_108, __tmp_109) => { - (*__tmp_109) = (((*__tmp_109) as u32).wrapping_add((__tmp_108 as u32))) as u32; - (*__tmp_109).clone() + (__tmp_110, __tmp_111) => { + (*__tmp_111) = (((*__tmp_111) as u32).wrapping_add((__tmp_110 as u32))) as u32; + (*__tmp_111).clone() } }); (unsafe { @@ -1481,9 +1542,9 @@ unsafe fn main_0() -> i32 { [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_28))[(0) as usize]) as usize]), ) { - (__tmp_110, __tmp_111) => { - (*__tmp_111) = (((*__tmp_111) as u32).wrapping_add((__tmp_110 as u32))) as u32; - (*__tmp_111).clone() + (__tmp_112, __tmp_113) => { + (*__tmp_113) = (((*__tmp_113) as u32).wrapping_add((__tmp_112 as u32))) as u32; + (*__tmp_113).clone() } }); (unsafe { @@ -1500,9 +1561,9 @@ unsafe fn main_0() -> i32 { [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_29)) [(i.postfix_inc()) as usize][(0) as usize]) as usize][(0) as usize]), ) { - (__tmp_112, __tmp_113) => { - (*__tmp_113) = (((*__tmp_113) as u32).wrapping_add((__tmp_112 as u32))) as u32; - (*__tmp_113).clone() + (__tmp_114, __tmp_115) => { + (*__tmp_115) = (((*__tmp_115) as u32).wrapping_add((__tmp_114 as u32))) as u32; + (*__tmp_115).clone() } }); (unsafe { From f4f9079884824a4d4f44236109cd2f186aad40b7 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Fri, 27 Nov 2026 23:00:24 +0000 Subject: [PATCH 13/25] Recognize independent fields and array elements in selectors Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 90 +++++++++++- tests/unit/assignment_single_eval.cpp | 18 +++ .../out/refcount/assignment_single_eval.rs | 130 ++++++++++++++---- .../unit/out/unsafe/assignment_single_eval.rs | 102 ++++++++++++-- 4 files changed, 295 insertions(+), 45 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 546f4bf876..9e28aa2f35 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -5002,6 +5002,17 @@ void FindAssignmentAliases(const clang::Stmt *stmt, cast->getCastKind() == clang::CK_ToVoid); return; } + if (const auto *expr = clang::dyn_cast(stmt); + expr && clang::isa(expr)) { + if (const auto *object = GetEnclosingObject(expr)) { + if (const auto *element = + clang::dyn_cast(expr)) { + FindAssignmentAliases(element->getIdx(), vars); + } + FindAssignmentAliases(object, vars, value_use, discarded_use); + return; + } + } if (const auto *binary = clang::dyn_cast(stmt)) { FindAssignmentAliases( binary->getLHS(), vars, @@ -5071,11 +5082,12 @@ bool Converter::NeedsAssignmentBinding( const auto *ref = clang::dyn_cast(target); const auto *var = ref ? clang::dyn_cast(ref->getDecl()) : nullptr; - auto may_alias = [&](const clang::VarDecl *decl) { + auto may_alias = [&](const clang::VarDecl *decl, bool aggregate = false) { if (boxed_vars_) { return boxed_vars_->contains(decl); } - if (!decl->getType()->isScalarType() || decl->isInitCapture()) { + if ((!aggregate && !decl->getType()->isScalarType()) || + decl->isInitCapture()) { return true; } auto [entry, inserted] = assignment_vars_.try_emplace(curr_function_); @@ -5215,9 +5227,46 @@ bool Converter::NeedsAssignmentBinding( call->getArg(1)->isIntegerConstantExpr(ctx_)) { return false; } + auto storage_root = [](const clang::Expr *expr) { + expr = expr->IgnoreParenImpCasts(); + while (const auto *object = GetEnclosingObject(expr)) { + if (const auto *member = clang::dyn_cast(expr); + member && member->getMemberDecl()->getType()->isReferenceType()) { + break; + } + expr = object->IgnoreParenImpCasts(); + } + return expr; + }; + const auto *written_root = + clang::dyn_cast(storage_root(target)); + auto disjoint_members = [&](const clang::Expr *read) { + for (auto *left = target; left;) { + if (const auto *member = clang::dyn_cast(left)) { + for (auto *right = read; right;) { + if (const auto *other = clang::dyn_cast(right); + other && member->getMemberDecl() != other->getMemberDecl() && + member->getMemberDecl()->getDeclContext() == + other->getMemberDecl()->getDeclContext()) { + return true; + } + right = GetEnclosingObject(right); + if (right) { + right = right->IgnoreParenImpCasts(); + } + } + } + left = GetEnclosingObject(left); + if (left) { + left = left->IgnoreParenImpCasts(); + } + } + return false; + }; // Indirect places can also be reread when all values used to select them - // are local scalars that no pointer can modify. Reference bindings do not - // rebind, but reading through a reference is not an isolated scalar read. + // belong to local storage that no pointer can modify. Reference bindings do + // not rebind, but reading through a reference is not an isolated scalar + // read. auto stable_reads = [&](auto &&self, const clang::Stmt *stmt) -> bool { if (const auto *expr = clang::dyn_cast(stmt); expr && expr->isIntegerConstantExpr(ctx_)) { @@ -5234,8 +5283,32 @@ bool Converter::NeedsAssignmentBinding( } if (const auto *cast = clang::dyn_cast(stmt); cast && cast->getCastKind() == clang::CK_LValueToRValue) { - const auto *ref = clang::dyn_cast( - cast->getSubExpr()->IgnoreParenImpCasts()); + const auto *place = cast->getSubExpr()->IgnoreParenImpCasts(); + if (const auto *root = + clang::dyn_cast(storage_root(place)); + root && written_root && + root->getDecl() == written_root->getDecl() && + !disjoint_members(place)) { + return false; + } + while ( + clang::isa(place)) { + if (const auto *member = clang::dyn_cast(place); + member && member->getMemberDecl()->getType()->isReferenceType()) { + return false; + } + if (const auto *element = + clang::dyn_cast(place); + element && !self(self, element->getIdx())) { + return false; + } + const auto *object = GetEnclosingObject(place); + if (!object) { + return false; + } + place = object->IgnoreParenImpCasts(); + } + const auto *ref = clang::dyn_cast(place); const auto *read = ref ? clang::dyn_cast(ref->getDecl()) : nullptr; return read && !read->isImplicit() && curr_function_ && @@ -5243,7 +5316,10 @@ bool Converter::NeedsAssignmentBinding( (read->isLocalVarDecl() || clang::isa(read)) && !IsGlobalVar(read) && !read->isInitCapture() && - read->getType()->isScalarType() && !may_alias(read); + !read->getType()->isReferenceType() && + (read->getType()->isScalarType() || + read->getType().isTrivialType(ctx_)) && + !may_alias(read, /*aggregate=*/true); } return std::ranges::all_of(stmt->children(), [&](const auto *child) { return !child || self(self, child); diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index 5ae177bf47..f9602a067f 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -229,6 +229,24 @@ int main() { int deref_value = (*pointer = 55); std::printf("stable indirect %d %d %d %d %d\n", value, reference_value, deref_value, a[0], a[1]); + int indices[2] = {1, 0}; + value = (pointer[selector.value] = 55); + reference_value = (reference[indices[0]] = 44); + deref_value = (*(pointer + selector.value) = 33); + std::printf("aggregate selectors %d %d %d %d\n", value, reference_value, + deref_value, a[1]); + struct Owner { + int values[2]; + int index; + } owner{{0, 20}, 0}; + value = (owner.values[owner.values[0]] = 1); + reference_value = (owner.values[owner.index] = 11); + std::printf("owner selectors %d %d %d %d\n", value, reference_value, + owner.values[0], owner.values[1]); + Index alias_selector{0}; + int *member_alias = &alias_selector.value; + value = (member_alias[alias_selector.value] = 1); + std::printf("member alias %d %d\n", value, alias_selector.value); int self_index = 0; int *self = &self_index; value = (self[self_index] = 1); diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 57fc61c261..7b3d0bf06e 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -1501,16 +1501,81 @@ fn main_0() -> i32 { (*a.borrow())[(0) as usize], (*a.borrow())[(1) as usize] ); + let mut indices: [i32; 2] = [1, 0]; + let __rhs = ({ + elem!(pointer, selector.value).write(55); + (elem!(pointer, selector.value).read()) + }); + value = __rhs; + reference_value = ({ + elem!(reference, indices[(0) as usize]).write(44); + (elem!(reference, indices[(0) as usize]).read()) + }); + let __rhs = ({ + (pointer.offset((selector.value) as isize)).write(33); + ((pointer.offset((selector.value) as isize)).read()) + }); + deref_value = __rhs; + printf!( + b"aggregate selectors %d %d %d %d\n", + value, + reference_value, + deref_value, + (*a.borrow())[(1) as usize] + ); + let mut owner: Owner_36 = Owner_36 { + values: Box::new([0, 20]), + index: 0, + }; + value = ({ + match ( + { 1 }, + &mut (owner.values[(owner.values[(0) as usize]) as usize]), + ) { + (__tmp_102, __tmp_103) => { + (*__tmp_103) = __tmp_102; + (*__tmp_103).clone() + } + } + }); + reference_value = ({ + owner.values[(owner.index) as usize] = 11; + owner.values[(owner.index) as usize] + }); + printf!( + b"owner selectors %d %d %d %d\n", + value, + reference_value, + owner.values[(0) as usize], + owner.values[(1) as usize] + ); + let alias_selector: Value = Rc::new(RefCell::new(Index_35 { value: 0 })); + let mut member_alias: Ptr = (field_ptr!(alias_selector.as_pointer(), value)); + let __rhs = ({ + match ({ 1 }, { + let __tmp_105 = member_alias.offset(({ (*alias_selector.borrow()).value }) as isize); + __tmp_105 + }) { + (__tmp_104, __tmp_105) => __tmp_105.with_mut(|__tmp_105| { + (*__tmp_105) = __tmp_104; + (*__tmp_105).clone() + }), + } + }); + value = __rhs; + printf!(b"member alias %d %d\n", value, { + (*alias_selector.borrow()).value + }); let self_index: Value = Rc::new(RefCell::new(0)); let mut self_: Ptr = (self_index.as_pointer()); let __rhs = ({ match ({ 1 }, { - let __tmp_103 = self_.offset((*self_index.borrow()) as isize); - __tmp_103 + let __tmp_107 = self_.offset((*self_index.borrow()) as isize); + __tmp_107 }) { - (__tmp_102, __tmp_103) => __tmp_103.with_mut(|__tmp_103| { - (*__tmp_103) = __tmp_102; - (*__tmp_103).clone() + (__tmp_106, __tmp_107) => __tmp_107.with_mut(|__tmp_107| { + (*__tmp_107) = __tmp_106; + (*__tmp_107).clone() }), } }); @@ -1526,13 +1591,13 @@ fn main_0() -> i32 { || -> i32 { return ({ match ({ 10000 }, { - let __tmp_105 = + let __tmp_109 = (captured_pointer.read()).offset((captured_index.read()) as isize); - __tmp_105 + __tmp_109 }) { - (__tmp_104, __tmp_105) => __tmp_105.with_mut(|__tmp_105| { - (*__tmp_105) = __tmp_104; - (*__tmp_105).clone() + (__tmp_108, __tmp_109) => __tmp_109.with_mut(|__tmp_109| { + (*__tmp_109) = __tmp_108; + (*__tmp_109).clone() }), } }); @@ -1566,9 +1631,9 @@ fn main_0() -> i32 { 0 )), ) { - (__tmp_106, __tmp_107) => __tmp_107.with_mut(|__tmp_107| { - (*__tmp_107) = (((*__tmp_107) as u32).wrapping_add((__tmp_106 as u32))) as u32; - (*__tmp_107).clone() + (__tmp_110, __tmp_111) => __tmp_111.with_mut(|__tmp_111| { + (*__tmp_111) = (((*__tmp_111) as u32).wrapping_add((__tmp_110 as u32))) as u32; + (*__tmp_111).clone() }), } }); @@ -1585,17 +1650,17 @@ fn main_0() -> i32 { ({ test_boxed_array_26() }); let mut global_result: u32 = ({ match ({ 1_u32 }, { - let __tmp_109 = global_array_28.with(|v| v.decay()).offset( + let __tmp_113 = global_array_28.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; global_array_28.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_109 + __tmp_113 }) { - (__tmp_108, __tmp_109) => __tmp_109.with_mut(|__tmp_109| { - (*__tmp_109) = (((*__tmp_109) as u32).wrapping_add((__tmp_108 as u32))) as u32; - (*__tmp_109).clone() + (__tmp_112, __tmp_113) => __tmp_113.with_mut(|__tmp_113| { + (*__tmp_113) = (((*__tmp_113) as u32).wrapping_add((__tmp_112 as u32))) as u32; + (*__tmp_113).clone() }), } }); @@ -1610,7 +1675,7 @@ fn main_0() -> i32 { i = 0; result = ({ match ({ 1_u32 }, { - let __tmp_111 = global_rows_29 + let __tmp_115 = global_rows_29 .with(|v| v.decay()) .offset( ({ @@ -1621,11 +1686,11 @@ fn main_0() -> i32 { ) .decay() .offset(0); - __tmp_111 + __tmp_115 }) { - (__tmp_110, __tmp_111) => __tmp_111.with_mut(|__tmp_111| { - (*__tmp_111) = (((*__tmp_111) as u32).wrapping_add((__tmp_110 as u32))) as u32; - (*__tmp_111).clone() + (__tmp_114, __tmp_115) => __tmp_115.with_mut(|__tmp_115| { + (*__tmp_115) = (((*__tmp_115) as u32).wrapping_add((__tmp_114 as u32))) as u32; + (*__tmp_115).clone() }), } }); @@ -1652,6 +1717,25 @@ pub struct Index_35 { #[offset(0)] pub value: i32, } +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(12)] +pub struct Owner_36 { + #[offset(0)] + #[byte_size(8)] + pub values: Box<[i32]>, + #[offset(8)] + pub index: i32, +} +impl Default for Owner_36 { + fn default() -> Self { + { + Owner_36 { + values: (0..2).map(|_| 0_i32).collect::>(), + index: 0_i32, + } + } + } +} pub trait IndexedBindingImpl { fn get_1_0(&self) -> Ptr; } diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index fada23ee2e..a84def89e6 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -1458,14 +1458,80 @@ unsafe fn main_0() -> i32 { (a[(1) as usize]), ) }); - let mut self_index: i32 = 0; - let mut self_: *mut i32 = (&mut self_index as *mut i32); - value = (match ({ 1 }, &mut (*self_.offset((self_index) as isize))) { + let mut indices: [i32; 2] = [1, 0]; + value = ({ + (*pointer.offset((selector.value) as isize)) = 55; + (*pointer.offset((selector.value) as isize)) + }); + reference_value = ({ + (*reference)[(indices[(0) as usize]) as usize] = 44; + (*reference)[(indices[(0) as usize]) as usize] + }); + deref_value = ({ + (*(pointer.offset((selector.value) as isize))) = 33; + (*(pointer.offset((selector.value) as isize))) + }); + (unsafe { + libc::printf( + c"aggregate selectors %d %d %d %d\n".as_ptr() as *const libc::c_char, + (value), + (reference_value), + (deref_value), + (a[(1) as usize]), + ) + }); + let mut owner: Owner_36 = Owner_36 { + values: [0, 20], + index: 0, + }; + value = (match ( + { 1 }, + &mut (owner.values[(owner.values[(0) as usize]) as usize]), + ) { (__tmp_106, __tmp_107) => { (*__tmp_107) = __tmp_106; (*__tmp_107).clone() } }); + reference_value = ({ + owner.values[(owner.index) as usize] = 11; + owner.values[(owner.index) as usize] + }); + (unsafe { + libc::printf( + c"owner selectors %d %d %d %d\n".as_ptr() as *const libc::c_char, + (value), + (reference_value), + (owner.values[(0) as usize]), + (owner.values[(1) as usize]), + ) + }); + let mut alias_selector: Index_35 = Index_35 { value: 0 }; + let mut member_alias: *mut i32 = (&mut alias_selector.value as *mut i32); + value = (match ( + { 1 }, + &mut (*member_alias.offset((alias_selector.value) as isize)), + ) { + (__tmp_108, __tmp_109) => { + (*__tmp_109) = __tmp_108; + (*__tmp_109).clone() + } + }); + (unsafe { + libc::printf( + c"member alias %d %d\n".as_ptr() as *const libc::c_char, + (value), + (alias_selector.value), + ) + }); + let mut self_index: i32 = 0; + let mut self_: *mut i32 = (&mut self_index as *mut i32); + value = (match ({ 1 }, &mut (*self_.offset((self_index) as isize))) { + (__tmp_110, __tmp_111) => { + (*__tmp_111) = __tmp_110; + (*__tmp_111).clone() + } + }); (unsafe { libc::printf( c"aliased indirect %d %d\n".as_ptr() as *const libc::c_char, @@ -1485,9 +1551,9 @@ unsafe fn main_0() -> i32 { { 10000 }, &mut (*(*captured_pointer).offset((*captured_index) as isize)), ) { - (__tmp_108, __tmp_109) => { - (*__tmp_109) = __tmp_108; - (*__tmp_109).clone() + (__tmp_112, __tmp_113) => { + (*__tmp_113) = __tmp_112; + (*__tmp_113).clone() } }); } @@ -1518,9 +1584,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_110, __tmp_111) => { - (*__tmp_111) = (((*__tmp_111) as u32).wrapping_add((__tmp_110 as u32))) as u32; - (*__tmp_111).clone() + (__tmp_114, __tmp_115) => { + (*__tmp_115) = (((*__tmp_115) as u32).wrapping_add((__tmp_114 as u32))) as u32; + (*__tmp_115).clone() } }); (unsafe { @@ -1542,9 +1608,9 @@ unsafe fn main_0() -> i32 { [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_28))[(0) as usize]) as usize]), ) { - (__tmp_112, __tmp_113) => { - (*__tmp_113) = (((*__tmp_113) as u32).wrapping_add((__tmp_112 as u32))) as u32; - (*__tmp_113).clone() + (__tmp_116, __tmp_117) => { + (*__tmp_117) = (((*__tmp_117) as u32).wrapping_add((__tmp_116 as u32))) as u32; + (*__tmp_117).clone() } }); (unsafe { @@ -1561,9 +1627,9 @@ unsafe fn main_0() -> i32 { [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_29)) [(i.postfix_inc()) as usize][(0) as usize]) as usize][(0) as usize]), ) { - (__tmp_114, __tmp_115) => { - (*__tmp_115) = (((*__tmp_115) as u32).wrapping_add((__tmp_114 as u32))) as u32; - (*__tmp_115).clone() + (__tmp_118, __tmp_119) => { + (*__tmp_119) = (((*__tmp_119) as u32).wrapping_add((__tmp_118 as u32))) as u32; + (*__tmp_119).clone() } }); (unsafe { @@ -1584,6 +1650,12 @@ unsafe fn main_0() -> i32 { pub struct Index_35 { pub value: i32, } +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Owner_36 { + pub values: [i32; 2], + pub index: i32, +} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const global_5); std::cell::LazyCell::force(&*&raw const global_record_8); From 38b0359107a178da38e44ada1d93af0cbad8418f Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Sat, 28 Nov 2026 16:40:57 +0000 Subject: [PATCH 14/25] Keep reference-member assignment targets stable through the store Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 5 + .../converter/models/converter_refcount.cpp | 13 +- tests/unit/assignment_single_eval.cpp | 40 + .../out/refcount/assignment_single_eval.rs | 816 ++++++++++++------ .../unit/out/unsafe/assignment_single_eval.rs | 691 +++++++++------ 5 files changed, 1051 insertions(+), 514 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 9e28aa2f35..689113109f 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -5079,6 +5079,11 @@ bool Converter::NeedsAssignmentBinding( const clang::Expr *lhs, const clang::Expr *rhs, const clang::CompoundAssignOperator *compound) { const auto *target = lhs->IgnoreParenImpCasts(); + if (const auto *member = clang::dyn_cast(target); + member && member->getMemberDecl()->getType()->isReferenceType()) { + // The referenced storage can also hold a value used to select the member. + return true; + } const auto *ref = clang::dyn_cast(target); const auto *var = ref ? clang::dyn_cast(ref->getDecl()) : nullptr; diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index bb8845b7ff..196393fdee 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -2536,7 +2536,18 @@ void ConverterRefCount::ConvertAssignment( // after the right operand, keeping its temporaries alive through the write. StrCat("match ({ ", rhs_value, " }, "); bool through_pointer = !pending_deref_.empty(); - if (staged_subscript) { + const auto *member = + clang::dyn_cast(lhs->IgnoreParenImpCasts()); + if (through_pointer && member && + member->getMemberDecl()->getType()->isReferenceType()) { + // Keep the referenced place, but end borrows used to select its owner. + StrCat("{ let ", left, token::kAssign); + { + PushParen paren(*this); + StrCat(pending_deref_.take()); + } + StrCat(".clone()", token::kSemiColon, left, "}"); + } else if (staged_subscript) { // End incidental index borrows before with_mut takes the write borrow. StrCat("{ let ", left, token::kAssign, pending_deref_.take(), token::kSemiColon, left, "}"); diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index f9602a067f..29c14b775b 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -53,6 +53,43 @@ template void test_comma() { std::printf("indirect simple %d %d %d\n", i, int(result), int(*p)); } +template void test_reference_members() { + struct Slot { + T &value; + }; + T index = 0, other = 77; + Slot a[2] = {{index}, {other}}; + a[index].value += 1; + std::printf("reference void %d %d\n", int(index), int(other)); + index = 0; + T result = (a[index].value += 1); + std::printf("reference compound %d %d %d\n", int(index), int(other), + int(result)); + index = 0; + result = (a[index].value = 1); + std::printf("reference simple %d %d %d\n", int(index), int(other), + int(result)); + index = 0; + result = (a[index++].value += 1); + std::printf("reference effect %d %d %d\n", int(index), int(other), + int(result)); + index = 0; + result = (a[index].value += (index = 1, T(2))); + std::printf("reference rhs %d %d %d\n", int(index), int(other), int(result)); +} + +void test_reference_pointer() { + struct Node { + Node *&link; + }; + Node *p = nullptr, *q = nullptr; + Node first{p}, second{q}; + p = &first; + q = &first; + Node *result = (p->link = &second); + std::printf("reference pointer %d %d\n", p == &second, result == &second); +} + int global = 10; int observe_global(int assigned) { return assigned + global; } int observe(int assigned, const int *stored) { return assigned + *stored; } @@ -261,6 +298,9 @@ int main() { test_local_members(); test_global_members(); test_static_members(); + test_reference_members(); + test_reference_members(); + test_reference_pointer(); test(); test(); test(); diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 7b3d0bf06e..0c0abb00f9 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -539,13 +539,282 @@ pub fn test_comma_4() { ((p.read()) as i32) ); } +pub fn test_reference_members_5() { + let index: Value = Rc::new(RefCell::new(0_u32)); + let other: Value = Rc::new(RefCell::new(77_u32)); + let mut a: [Slot_6; 2] = [ + Slot_6 { + value: index.as_pointer(), + }, + Slot_6 { + value: other.as_pointer(), + }, + ]; + { + match ({ 1_u32 }, { + let __tmp_57 = (a[(*index.borrow()) as usize].value).clone(); + __tmp_57 + }) { + (__tmp_56, __tmp_57) => __tmp_57.with_mut(|__tmp_57| { + (*__tmp_57) = (((*__tmp_57) as u32).wrapping_add((__tmp_56 as u32))) as u32; + }), + } + }; + printf!( + b"reference void %d %d\n", + ((*index.borrow()) as i32), + ((*other.borrow()) as i32) + ); + (*index.borrow_mut()) = 0_u32; + let mut result: u32 = ({ + match ({ 1_u32 }, { + let __tmp_59 = (a[(*index.borrow()) as usize].value).clone(); + __tmp_59 + }) { + (__tmp_58, __tmp_59) => __tmp_59.with_mut(|__tmp_59| { + (*__tmp_59) = (((*__tmp_59) as u32).wrapping_add((__tmp_58 as u32))) as u32; + (*__tmp_59).clone() + }), + } + }); + printf!( + b"reference compound %d %d %d\n", + ((*index.borrow()) as i32), + ((*other.borrow()) as i32), + (result as i32) + ); + (*index.borrow_mut()) = 0_u32; + let __rhs = ({ + match ({ 1_u32 }, { + let __tmp_61 = (a[(*index.borrow()) as usize].value).clone(); + __tmp_61 + }) { + (__tmp_60, __tmp_61) => __tmp_61.with_mut(|__tmp_61| { + (*__tmp_61) = __tmp_60; + (*__tmp_61).clone() + }), + } + }); + result = __rhs; + printf!( + b"reference simple %d %d %d\n", + ((*index.borrow()) as i32), + ((*other.borrow()) as i32), + (result as i32) + ); + (*index.borrow_mut()) = 0_u32; + let __rhs = ({ + match ({ 1_u32 }, { + let __tmp_63 = (a[((*index.borrow_mut()).postfix_inc()) as usize].value).clone(); + __tmp_63 + }) { + (__tmp_62, __tmp_63) => __tmp_63.with_mut(|__tmp_63| { + (*__tmp_63) = (((*__tmp_63) as u32).wrapping_add((__tmp_62 as u32))) as u32; + (*__tmp_63).clone() + }), + } + }); + result = __rhs; + printf!( + b"reference effect %d %d %d\n", + ((*index.borrow()) as i32), + ((*other.borrow()) as i32), + (result as i32) + ); + (*index.borrow_mut()) = 0_u32; + let __rhs = ({ + match ( + { + { + (*index.borrow_mut()) = 1_u32; + 2_u32 + } + }, + { + let __tmp_65 = (a[(*index.borrow()) as usize].value).clone(); + __tmp_65 + }, + ) { + (__tmp_64, __tmp_65) => __tmp_65.with_mut(|__tmp_65| { + (*__tmp_65) = (((*__tmp_65) as u32).wrapping_add((__tmp_64 as u32))) as u32; + (*__tmp_65).clone() + }), + } + }); + result = __rhs; + printf!( + b"reference rhs %d %d %d\n", + ((*index.borrow()) as i32), + ((*other.borrow()) as i32), + (result as i32) + ); +} +pub fn test_reference_members_7() { + let index: Value = Rc::new(RefCell::new(0_i16)); + let other: Value = Rc::new(RefCell::new(77_i16)); + let mut a: [Slot_8; 2] = [ + Slot_8 { + value: index.as_pointer(), + }, + Slot_8 { + value: other.as_pointer(), + }, + ]; + { + match ({ 1 }, { + let __tmp_67 = (a[(*index.borrow()) as usize].value).clone(); + __tmp_67 + }) { + (__tmp_66, __tmp_67) => __tmp_67.with_mut(|__tmp_67| { + (*__tmp_67) = (((*__tmp_67) as i32) + (__tmp_66 as i32)) as i16; + }), + } + }; + printf!( + b"reference void %d %d\n", + ((*index.borrow()) as i32), + ((*other.borrow()) as i32) + ); + (*index.borrow_mut()) = 0_i16; + let mut result: i16 = ({ + match ({ 1 }, { + let __tmp_69 = (a[(*index.borrow()) as usize].value).clone(); + __tmp_69 + }) { + (__tmp_68, __tmp_69) => __tmp_69.with_mut(|__tmp_69| { + (*__tmp_69) = (((*__tmp_69) as i32) + (__tmp_68 as i32)) as i16; + (*__tmp_69).clone() + }), + } + }); + printf!( + b"reference compound %d %d %d\n", + ((*index.borrow()) as i32), + ((*other.borrow()) as i32), + (result as i32) + ); + (*index.borrow_mut()) = 0_i16; + let __rhs = ({ + match ({ 1_i16 }, { + let __tmp_71 = (a[(*index.borrow()) as usize].value).clone(); + __tmp_71 + }) { + (__tmp_70, __tmp_71) => __tmp_71.with_mut(|__tmp_71| { + (*__tmp_71) = __tmp_70; + (*__tmp_71).clone() + }), + } + }); + result = __rhs; + printf!( + b"reference simple %d %d %d\n", + ((*index.borrow()) as i32), + ((*other.borrow()) as i32), + (result as i32) + ); + (*index.borrow_mut()) = 0_i16; + let __rhs = ({ + match ({ 1 }, { + let __tmp_73 = (a[((*index.borrow_mut()).postfix_inc()) as usize].value).clone(); + __tmp_73 + }) { + (__tmp_72, __tmp_73) => __tmp_73.with_mut(|__tmp_73| { + (*__tmp_73) = (((*__tmp_73) as i32) + (__tmp_72 as i32)) as i16; + (*__tmp_73).clone() + }), + } + }); + result = __rhs; + printf!( + b"reference effect %d %d %d\n", + ((*index.borrow()) as i32), + ((*other.borrow()) as i32), + (result as i32) + ); + (*index.borrow_mut()) = 0_i16; + let __rhs = ({ + match ( + { + ({ + (*index.borrow_mut()) = 1_i16; + 2_i16 + } as i32) + }, + { + let __tmp_75 = (a[(*index.borrow()) as usize].value).clone(); + __tmp_75 + }, + ) { + (__tmp_74, __tmp_75) => __tmp_75.with_mut(|__tmp_75| { + (*__tmp_75) = (((*__tmp_75) as i32) + (__tmp_74 as i32)) as i16; + (*__tmp_75).clone() + }), + } + }); + result = __rhs; + printf!( + b"reference rhs %d %d %d\n", + ((*index.borrow()) as i32), + ((*other.borrow()) as i32), + (result as i32) + ); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct Slot_6 { + #[offset(0)] + #[byte_size(8)] + pub value: Ptr, +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct Slot_8 { + #[offset(0)] + #[byte_size(8)] + pub value: Ptr, +} +pub fn test_reference_pointer_9() { + let p: Value> = Rc::new(RefCell::new(Ptr::::null())); + let q: Value> = Rc::new(RefCell::new(Ptr::::null())); + let first: Value = Rc::new(RefCell::new(Node_10 { + link: p.as_pointer(), + })); + let second: Value = Rc::new(RefCell::new(Node_10 { + link: q.as_pointer(), + })); + (*p.borrow_mut()) = (first.as_pointer()); + (*q.borrow_mut()) = (first.as_pointer()); + let mut result: Ptr = ({ + match ({ (second.as_pointer()) }, { + let __tmp_77 = ((*p.borrow()).with(|__s| __s.link.clone())).clone(); + __tmp_77 + }) { + (__tmp_76, __tmp_77) => __tmp_77.with_mut(|__tmp_77| { + (*__tmp_77) = __tmp_76; + (*__tmp_77).clone() + }), + } + }); + printf!( + b"reference pointer %d %d\n", + (({ (*p.borrow()).clone() } == { (second.as_pointer()) }) as i32), + (({ (result).clone() } == { (second.as_pointer()) }) as i32) + ); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct Node_10 { + #[offset(0)] + #[byte_size(8)] + pub link: Ptr>, +} thread_local!( - pub static global_5: Value = Rc::new(RefCell::new(10)); + pub static global_11: Value = Rc::new(RefCell::new(10)); ); -pub fn observe_global_6(mut assigned: i32) -> i32 { - return (assigned + global_5.with(|rc| *rc.borrow())); +pub fn observe_global_12(mut assigned: i32) -> i32 { + return (assigned + global_11.with(|rc| *rc.borrow())); } -pub fn observe_7(mut assigned: i32, mut stored: Ptr) -> i32 { +pub fn observe_13(mut assigned: i32, mut stored: Ptr) -> i32 { return ({ assigned } + { (stored.read()) }); } #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] @@ -562,63 +831,63 @@ pub struct GlobalRecord { pub inner: GlobalRecord_Inner, } thread_local!( - pub static global_record_8: Value = Rc::new(RefCell::new(GlobalRecord { + pub static global_record_14: Value = Rc::new(RefCell::new(GlobalRecord { inner: GlobalRecord_Inner { value: 10 }, })); ); -pub fn observe_record_9(mut assigned: i32) -> i32 { - return (assigned + { global_record_8.with(|rc| *rc.borrow()).inner.value }); +pub fn observe_record_15(mut assigned: i32) -> i32 { + return (assigned + { global_record_14.with(|rc| *rc.borrow()).inner.value }); } thread_local!( - pub static targets_10: Value> = Rc::new(RefCell::new(Box::new([10, 20]))); + pub static targets_16: Value> = Rc::new(RefCell::new(Box::new([10, 20]))); ); thread_local!( - pub static cursor_11: Value> = Rc::new(RefCell::new(targets_10.with(|v| v.decay()))); + pub static cursor_17: Value> = Rc::new(RefCell::new(targets_16.with(|v| v.decay()))); ); -pub fn test_borrows_12() { +pub fn test_borrows_18() { printf!( b"%d\n", ({ - observe_global_6({ - global_5.with(|rc| *rc.borrow_mut() = 99); - global_5.with(|rc| *rc.borrow()) + observe_global_12({ + global_11.with(|rc| *rc.borrow_mut() = 99); + global_11.with(|rc| *rc.borrow()) }) }) ); printf!( b"%d\n", ({ - observe_global_6({ - global_5.with(|rc| *rc.borrow_mut() += 5); - global_5.with(|rc| *rc.borrow()) + observe_global_12({ + global_11.with(|rc| *rc.borrow_mut() += 5); + global_11.with(|rc| *rc.borrow()) }) }) ); printf!( b"%d\n", ({ - observe_global_6({ - let __rhs = ({ observe_7(0, (global_5.with(|v| v.as_pointer()))) }); - global_5.with(|rc| *rc.borrow_mut() = __rhs); - global_5.with(|rc| *rc.borrow()) + observe_global_12({ + let __rhs = ({ observe_13(0, (global_11.with(|v| v.as_pointer()))) }); + global_11.with(|rc| *rc.borrow_mut() = __rhs); + global_11.with(|rc| *rc.borrow()) }) }) ); let mut assigned: i32 = (({ - let __tmp_56 = { - promoted_13.with(|rc| *rc.borrow_mut() = (-1_i32 as i16)); + let __tmp_78 = { + promoted_19.with(|rc| *rc.borrow_mut() = (-1_i32 as i16)); 0.5_f64 }; { - let rhs_0 = ((promoted_13.with(|rc| *rc.borrow()) as f64) + (__tmp_56 as f64)) as i16; - promoted_13.with(|rc| *rc.borrow_mut() = rhs_0); - promoted_13.with(|rc| *rc.borrow()) + let rhs_0 = ((promoted_19.with(|rc| *rc.borrow()) as f64) + (__tmp_78 as f64)) as i16; + promoted_19.with(|rc| *rc.borrow_mut() = rhs_0); + promoted_19.with(|rc| *rc.borrow()) } }) as i32); printf!( b"%d %d\n", assigned, - (promoted_13.with(|rc| *rc.borrow()) as i32) + (promoted_19.with(|rc| *rc.borrow()) as i32) ); let aliased: Value = Rc::new(RefCell::new(10_i16)); let mut alias: Ptr = (aliased.as_pointer()); @@ -632,55 +901,55 @@ pub fn test_borrows_12() { }, &mut (*aliased.borrow_mut()), ) { - (__tmp_57, __tmp_58) => { - (*__tmp_58) = (((*__tmp_58) as f64) + (__tmp_57 as f64)) as i16; - (*__tmp_58).clone() + (__tmp_79, __tmp_80) => { + (*__tmp_80) = (((*__tmp_80) as f64) + (__tmp_79 as f64)) as i16; + (*__tmp_80).clone() } } }) as i32); printf!(b"%d %d\n", assigned, ((*aliased.borrow()) as i32)); let mut enabled: bool = ({ - let __tmp_59 = { - ({ observe_7(0, (global_5.with(|v| v.as_pointer()))) }); + let __tmp_81 = { + ({ observe_13(0, (global_11.with(|v| v.as_pointer()))) }); 0.5_f64 }; { - let rhs_0 = ((flag_14.with(|rc| *rc.borrow()) as u8 as f64) + (__tmp_59 as f64)) != 0.0; - flag_14.with(|rc| *rc.borrow_mut() = rhs_0); - flag_14.with(|rc| *rc.borrow()) + let rhs_0 = ((flag_20.with(|rc| *rc.borrow()) as u8 as f64) + (__tmp_81 as f64)) != 0.0; + flag_20.with(|rc| *rc.borrow_mut() = rhs_0); + flag_20.with(|rc| *rc.borrow()) } }); printf!( b"%d %d\n", (enabled as i32), - (flag_14.with(|rc| *rc.borrow()) as i32) + (flag_20.with(|rc| *rc.borrow()) as i32) ); printf!( b"%d\n", ({ - observe_record_9({ - (*global_record_8.with(Value::clone).borrow_mut()) + observe_record_15({ + (*global_record_14.with(Value::clone).borrow_mut()) .inner .value = 99; - { global_record_8.with(|rc| *rc.borrow()).inner.value } + { global_record_14.with(|rc| *rc.borrow()).inner.value } }) }) ); let mut shifted: Ptr = ({ - let __tmp_60 = { - cursor_11 - .with(|rc| *rc.borrow_mut() = targets_10.with(|v| v.decay()).offset((1) as isize)); + let __tmp_82 = { + cursor_17 + .with(|rc| *rc.borrow_mut() = targets_16.with(|v| v.decay()).offset((1) as isize)); 1 }; - cursor_11.with(|rc| *rc.borrow_mut() -= (__tmp_60 as isize)); - (*cursor_11.with(Value::clone).borrow()).clone() + cursor_17.with(|rc| *rc.borrow_mut() -= (__tmp_82 as isize)); + (*cursor_17.with(Value::clone).borrow()).clone() }); printf!( b"%d %d\n", - (({ (*cursor_11.with(Value::clone).borrow()).clone() } == { - targets_10.with(|v| v.decay()) + (({ (*cursor_17.with(Value::clone).borrow()).clone() } == { + targets_16.with(|v| v.decay()) }) as i32), - (({ (shifted).clone() } == { (*cursor_11.with(Value::clone).borrow()).clone() }) as i32) + (({ (shifted).clone() } == { (*cursor_17.with(Value::clone).borrow()).clone() }) as i32) ); let local: Value = Rc::new(RefCell::new(10)); printf!( @@ -691,7 +960,7 @@ pub fn test_borrows_12() { (*local.borrow()) }; let _stored: Ptr = (local.as_pointer()); - observe_7(_assigned, _stored) + observe_13(_assigned, _stored) }) ); printf!( @@ -702,10 +971,10 @@ pub fn test_borrows_12() { (*local.borrow()) }; let _stored: Ptr = (local.as_pointer()); - observe_7(_assigned, _stored) + observe_13(_assigned, _stored) }) ); - let record: Value = Rc::new(RefCell::new(Record_15 { value: 10 })); + let record: Value = Rc::new(RefCell::new(Record_21 { value: 10 })); printf!( b"%d\n", ({ @@ -714,7 +983,7 @@ pub fn test_borrows_12() { { (*record.borrow()).value } }; let _stored: Ptr = (field_ptr!(record.as_pointer(), value)); - observe_7(_assigned, _stored) + observe_13(_assigned, _stored) }) ); printf!( @@ -725,25 +994,25 @@ pub fn test_borrows_12() { { (*record.borrow()).value } }; let _stored: Ptr = (field_ptr!(record.as_pointer(), value)); - observe_7(_assigned, _stored) + observe_13(_assigned, _stored) }) ); - let first: Value = >::default(); - *first.borrow_mut() = Link_16 { + let first: Value = >::default(); + *first.borrow_mut() = Link_22 { next: (first.as_pointer()), }; - let second: Value = Rc::new(RefCell::new(Link_16 { + let second: Value = Rc::new(RefCell::new(Link_22 { next: (first.as_pointer()), })); - let selector: Ptr> = field_ptr!(first.as_pointer(), next); - let mut selected: Ptr = ({ + let selector: Ptr> = field_ptr!(first.as_pointer(), next); + let mut selected: Ptr = ({ match ( { (second.as_pointer()) }, &(field!((selector.read()), next)), ) { - (__tmp_61, __tmp_62) => __tmp_62.with_mut(|__tmp_62| { - (*__tmp_62) = __tmp_61; - (*__tmp_62).clone() + (__tmp_83, __tmp_84) => __tmp_84.with_mut(|__tmp_84| { + (*__tmp_84) = __tmp_83; + (*__tmp_84).clone() }), } }); @@ -761,7 +1030,7 @@ pub fn test_borrows_12() { { (*values.borrow())[0_usize] } }; let _stored: Ptr = (values.decay().offset(0_usize)); - observe_7(_assigned, _stored) + observe_13(_assigned, _stored) }) ); printf!( @@ -772,45 +1041,45 @@ pub fn test_borrows_12() { { (*values.borrow())[0_usize] } }; let _stored: Ptr = (values.decay().offset(0_usize)); - observe_7(_assigned, _stored) + observe_13(_assigned, _stored) }) ); } thread_local!( - static promoted_13: Value = Rc::new(RefCell::new(10_i16)); + static promoted_19: Value = Rc::new(RefCell::new(10_i16)); ); thread_local!( - static flag_14: Value = Rc::new(RefCell::new(false)); + static flag_20: Value = Rc::new(RefCell::new(false)); ); #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(4)] -pub struct Record_15 { +pub struct Record_21 { #[offset(0)] pub value: i32, } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(8)] -pub struct Link_16 { +pub struct Link_22 { #[offset(0)] #[byte_size(8)] - pub next: Ptr, + pub next: Ptr, } thread_local!( - pub static selected_values_17: Value> = + pub static selected_values_23: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); ); #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct IndexedBinding {} -pub fn test_binding_18() { +pub fn test_binding_24() { let owner: Value = Rc::new(RefCell::new(::default())); - let __decomp_19: Ptr = owner.as_pointer(); - let value: Ptr = ({ IndexedBindingImpl::get_1_0(&__decomp_19) }); + let __decomp_25: Ptr = owner.as_pointer(); + let value: Ptr = ({ IndexedBindingImpl::get_1_0(&__decomp_25) }); let mut result: u32 = ({ - match ({ 1_u32 }, &({ IndexedBindingImpl::get_1_0(&__decomp_19) })) { - (__tmp_63, __tmp_64) => __tmp_64.with_mut(|__tmp_64| { - (*__tmp_64) = (((*__tmp_64) as u32).wrapping_add((__tmp_63 as u32))) as u32; - (*__tmp_64).clone() + match ({ 1_u32 }, &({ IndexedBindingImpl::get_1_0(&__decomp_25) })) { + (__tmp_85, __tmp_86) => __tmp_86.with_mut(|__tmp_86| { + (*__tmp_86) = (((*__tmp_86) as u32).wrapping_add((__tmp_85 as u32))) as u32; + (*__tmp_86).clone() }), } }); @@ -819,34 +1088,34 @@ pub fn test_binding_18() { result, ({ let __idx0 = (0) as usize; - selected_values_17.with(|rc| rc.borrow()[__idx0]) + selected_values_23.with(|rc| rc.borrow()[__idx0]) }) ); } thread_local!( - pub static initializer_target_20: Value = Rc::new(RefCell::new(10_u32)); + pub static initializer_target_26: Value = Rc::new(RefCell::new(10_u32)); ); -pub fn mutate_initializer_21() -> u32 { - initializer_target_20.with(|rc| *rc.borrow_mut() = 20_u32); +pub fn mutate_initializer_27() -> u32 { + initializer_target_26.with(|rc| *rc.borrow_mut() = 20_u32); return 1_u32; } thread_local!( - pub static initializer_result_22: Value = Rc::new(RefCell::new( + pub static initializer_result_28: Value = Rc::new(RefCell::new( ({ - let __tmp_65 = ({ mutate_initializer_21() }); + let __tmp_87 = ({ mutate_initializer_27() }); { - let rhs_0 = ((initializer_target_20.with(|rc| *rc.borrow()) as u32) - .wrapping_add((__tmp_65 as u32))) as u32; + let rhs_0 = ((initializer_target_26.with(|rc| *rc.borrow()) as u32) + .wrapping_add((__tmp_87 as u32))) as u32; { let __rhs = rhs_0; - initializer_target_20.with(|rc| *rc.borrow_mut() = __rhs) + initializer_target_26.with(|rc| *rc.borrow_mut() = __rhs) }; - initializer_target_20.with(|rc| *rc.borrow()) + initializer_target_26.with(|rc| *rc.borrow()) } }), )); ); -pub fn test_alias_scopes_23(parameter: i16) { +pub fn test_alias_scopes_29(parameter: i16) { let parameter: Value = Rc::new(RefCell::new(parameter)); let mut p: Ptr = (parameter.as_pointer()); let mut result: i16 = ({ @@ -859,9 +1128,9 @@ pub fn test_alias_scopes_23(parameter: i16) { }, &mut (*parameter.borrow_mut()), ) { - (__tmp_66, __tmp_67) => { - (*__tmp_67) = (((*__tmp_67) as f64) + (__tmp_66 as f64)) as i16; - (*__tmp_67).clone() + (__tmp_88, __tmp_89) => { + (*__tmp_89) = (((*__tmp_89) as f64) + (__tmp_88 as f64)) as i16; + (*__tmp_89).clone() } } }); @@ -885,9 +1154,9 @@ pub fn test_alias_scopes_23(parameter: i16) { { ({ (*mutate.borrow()).call() }).clone() }, &mut (*local.borrow_mut()), ) { - (__tmp_68, __tmp_69) => { - (*__tmp_69) = (((*__tmp_69) as f64) + (__tmp_68 as f64)) as i16; - (*__tmp_69).clone() + (__tmp_90, __tmp_91) => { + (*__tmp_91) = (((*__tmp_91) as f64) + (__tmp_90 as f64)) as i16; + (*__tmp_91).clone() } } }); @@ -898,22 +1167,22 @@ pub fn test_alias_scopes_23(parameter: i16) { ); printf!( b"initializer %u %u\n", - initializer_result_22.with(|rc| *rc.borrow()), - initializer_target_20.with(|rc| *rc.borrow()) + initializer_result_28.with(|rc| *rc.borrow()), + initializer_target_26.with(|rc| *rc.borrow()) ); } -pub fn test_boxed_array_24() { +pub fn test_boxed_array_30() { let a: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); let mut p: Ptr = a.decay(); let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_71 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_71 + let __tmp_93 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_93 }) { - (__tmp_70, __tmp_71) => __tmp_71.with_mut(|__tmp_71| { - (*__tmp_71) = (((*__tmp_71) as u32).wrapping_add((__tmp_70 as u32))) as u32; - (*__tmp_71).clone() + (__tmp_92, __tmp_93) => __tmp_93.with_mut(|__tmp_93| { + (*__tmp_93) = (((*__tmp_93) as u32).wrapping_add((__tmp_92 as u32))) as u32; + (*__tmp_93).clone() }), } }); @@ -928,12 +1197,12 @@ pub fn test_boxed_array_24() { i = 0; result = ({ match ({ 1_u32 }, { - let __tmp_73 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_73 + let __tmp_95 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_95 }) { - (__tmp_72, __tmp_73) => __tmp_73.with_mut(|__tmp_73| { - (*__tmp_73) = __tmp_72; - (*__tmp_73).clone() + (__tmp_94, __tmp_95) => __tmp_95.with_mut(|__tmp_95| { + (*__tmp_95) = __tmp_94; + (*__tmp_95).clone() }), } }); @@ -946,17 +1215,17 @@ pub fn test_boxed_array_24() { ); result = ({ match ({ 1_u32 }, { - let __tmp_75 = saved_25.with(|v| v.decay()).offset( + let __tmp_97 = saved_31.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; - saved_25.with(|rc| rc.borrow()[__idx0]) + saved_31.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_75 + __tmp_97 }) { - (__tmp_74, __tmp_75) => __tmp_75.with_mut(|__tmp_75| { - (*__tmp_75) = (((*__tmp_75) as u32).wrapping_add((__tmp_74 as u32))) as u32; - (*__tmp_75).clone() + (__tmp_96, __tmp_97) => __tmp_97.with_mut(|__tmp_97| { + (*__tmp_97) = (((*__tmp_97) as u32).wrapping_add((__tmp_96 as u32))) as u32; + (*__tmp_97).clone() }), } }); @@ -965,22 +1234,22 @@ pub fn test_boxed_array_24() { (result as i32), (({ let __idx0 = (0) as usize; - saved_25.with(|rc| rc.borrow()[__idx0]) + saved_31.with(|rc| rc.borrow()[__idx0]) }) as i32) ); } -pub fn test_boxed_array_26() { +pub fn test_boxed_array_32() { let a: Value> = Rc::new(RefCell::new(Box::new([0_i16, 20_i16, 30_i16]))); let mut p: Ptr = a.decay(); let mut i: i32 = 0; let mut result: i16 = ({ match ({ 1 }, { - let __tmp_77 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_77 + let __tmp_99 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_99 }) { - (__tmp_76, __tmp_77) => __tmp_77.with_mut(|__tmp_77| { - (*__tmp_77) = (((*__tmp_77) as i32) + (__tmp_76 as i32)) as i16; - (*__tmp_77).clone() + (__tmp_98, __tmp_99) => __tmp_99.with_mut(|__tmp_99| { + (*__tmp_99) = (((*__tmp_99) as i32) + (__tmp_98 as i32)) as i16; + (*__tmp_99).clone() }), } }); @@ -995,12 +1264,12 @@ pub fn test_boxed_array_26() { i = 0; result = ({ match ({ 1_i16 }, { - let __tmp_79 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_79 + let __tmp_101 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_101 }) { - (__tmp_78, __tmp_79) => __tmp_79.with_mut(|__tmp_79| { - (*__tmp_79) = __tmp_78; - (*__tmp_79).clone() + (__tmp_100, __tmp_101) => __tmp_101.with_mut(|__tmp_101| { + (*__tmp_101) = __tmp_100; + (*__tmp_101).clone() }), } }); @@ -1013,17 +1282,17 @@ pub fn test_boxed_array_26() { ); result = ({ match ({ 1 }, { - let __tmp_81 = saved_27.with(|v| v.decay()).offset( + let __tmp_103 = saved_33.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; - saved_27.with(|rc| rc.borrow()[__idx0]) + saved_33.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_81 + __tmp_103 }) { - (__tmp_80, __tmp_81) => __tmp_81.with_mut(|__tmp_81| { - (*__tmp_81) = (((*__tmp_81) as i32) + (__tmp_80 as i32)) as i16; - (*__tmp_81).clone() + (__tmp_102, __tmp_103) => __tmp_103.with_mut(|__tmp_103| { + (*__tmp_103) = (((*__tmp_103) as i32) + (__tmp_102 as i32)) as i16; + (*__tmp_103).clone() }), } }); @@ -1032,22 +1301,22 @@ pub fn test_boxed_array_26() { (result as i32), (({ let __idx0 = (0) as usize; - saved_27.with(|rc| rc.borrow()[__idx0]) + saved_33.with(|rc| rc.borrow()[__idx0]) }) as i32) ); } thread_local!( - static saved_25: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); + static saved_31: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); ); thread_local!( - static saved_27: Value> = Rc::new(RefCell::new(Box::new([0_i16, 20_i16, 30_i16]))); + static saved_33: Value> = Rc::new(RefCell::new(Box::new([0_i16, 20_i16, 30_i16]))); ); thread_local!( - pub static global_array_28: Value> = + pub static global_array_34: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); ); thread_local!( - pub static global_rows_29: Value]>> = Rc::new(RefCell::new(Box::new([ + pub static global_rows_35: Value]>> = Rc::new(RefCell::new(Box::new([ Box::new([0_u32, 10_u32]), Box::new([20_u32, 30_u32]), ]))); @@ -1063,7 +1332,7 @@ pub struct IndexedMember { pub promoted: i16, } thread_local!( - pub static global_members_30: Value> = Rc::new(RefCell::new(Box::new([ + pub static global_members_36: Value> = Rc::new(RefCell::new(Box::new([ IndexedMember { key: 0, value: 10_u32, @@ -1076,7 +1345,7 @@ thread_local!( }, ]))); ); -pub fn test_local_members_31() { +pub fn test_local_members_37() { let a: Value> = Rc::new(RefCell::new(Box::new([ IndexedMember { key: 0, @@ -1093,16 +1362,16 @@ pub fn test_local_members_31() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_83 = field_ptr!( + let __tmp_105 = field_ptr!( a.decay() .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), value ); - __tmp_83 + __tmp_105 }) { - (__tmp_82, __tmp_83) => __tmp_83.with_mut(|__tmp_83| { - (*__tmp_83) = (((*__tmp_83) as u32).wrapping_add((__tmp_82 as u32))) as u32; - (*__tmp_83).clone() + (__tmp_104, __tmp_105) => __tmp_105.with_mut(|__tmp_105| { + (*__tmp_105) = (((*__tmp_105) as u32).wrapping_add((__tmp_104 as u32))) as u32; + (*__tmp_105).clone() }), } }); @@ -1116,15 +1385,15 @@ pub fn test_local_members_31() { i = 0; { match ({ 1 }, { - let __tmp_85 = field_ptr!( + let __tmp_107 = field_ptr!( a.decay() .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), promoted ); - __tmp_85 + __tmp_107 }) { - (__tmp_84, __tmp_85) => __tmp_85.with_mut(|__tmp_85| { - (*__tmp_85) = (((*__tmp_85) as i32) + (__tmp_84 as i32)) as i16; + (__tmp_106, __tmp_107) => __tmp_107.with_mut(|__tmp_107| { + (*__tmp_107) = (((*__tmp_107) as i32) + (__tmp_106 as i32)) as i16; }), } }; @@ -1137,16 +1406,16 @@ pub fn test_local_members_31() { i = 0; result = ({ match ({ 99_u32 }, { - let __tmp_87 = field_ptr!( + let __tmp_109 = field_ptr!( a.decay() .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), value ); - __tmp_87 + __tmp_109 }) { - (__tmp_86, __tmp_87) => __tmp_87.with_mut(|__tmp_87| { - (*__tmp_87) = __tmp_86; - (*__tmp_87).clone() + (__tmp_108, __tmp_109) => __tmp_109.with_mut(|__tmp_109| { + (*__tmp_109) = __tmp_108; + (*__tmp_109).clone() }), } }); @@ -1159,25 +1428,25 @@ pub fn test_local_members_31() { ); printf!(b"member alias %u\n", p.with(|__s| __s.value)); } -pub fn test_global_members_32() { +pub fn test_global_members_38() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_89 = field_ptr!( - global_members_30.with(|v| v.decay()).offset({ + let __tmp_111 = field_ptr!( + global_members_36.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - global_members_30.with(|rc| rc.borrow()[__idx0]) + global_members_36.with(|rc| rc.borrow()[__idx0]) }) .key }), value ); - __tmp_89 + __tmp_111 }) { - (__tmp_88, __tmp_89) => __tmp_89.with_mut(|__tmp_89| { - (*__tmp_89) = (((*__tmp_89) as u32).wrapping_add((__tmp_88 as u32))) as u32; - (*__tmp_89).clone() + (__tmp_110, __tmp_111) => __tmp_111.with_mut(|__tmp_111| { + (*__tmp_111) = (((*__tmp_111) as u32).wrapping_add((__tmp_110 as u32))) as u32; + (*__tmp_111).clone() }), } }); @@ -1188,14 +1457,14 @@ pub fn test_global_members_32() { { ({ let __idx0 = (0) as usize; - global_members_30.with(|rc| rc.borrow()[__idx0]) + global_members_36.with(|rc| rc.borrow()[__idx0]) }) .value }, { ({ let __idx0 = (1) as usize; - global_members_30.with(|rc| rc.borrow()[__idx0]) + global_members_36.with(|rc| rc.borrow()[__idx0]) }) .value } @@ -1203,20 +1472,20 @@ pub fn test_global_members_32() { i = 0; { match ({ 1 }, { - let __tmp_91 = field_ptr!( - global_members_30.with(|v| v.decay()).offset({ + let __tmp_113 = field_ptr!( + global_members_36.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - global_members_30.with(|rc| rc.borrow()[__idx0]) + global_members_36.with(|rc| rc.borrow()[__idx0]) }) .key }), promoted ); - __tmp_91 + __tmp_113 }) { - (__tmp_90, __tmp_91) => __tmp_91.with_mut(|__tmp_91| { - (*__tmp_91) = (((*__tmp_91) as i32) + (__tmp_90 as i32)) as i16; + (__tmp_112, __tmp_113) => __tmp_113.with_mut(|__tmp_113| { + (*__tmp_113) = (((*__tmp_113) as i32) + (__tmp_112 as i32)) as i16; }), } }; @@ -1226,14 +1495,14 @@ pub fn test_global_members_32() { ({ ({ let __idx0 = (0) as usize; - global_members_30.with(|rc| rc.borrow()[__idx0]) + global_members_36.with(|rc| rc.borrow()[__idx0]) }) .promoted } as i32), ({ ({ let __idx0 = (1) as usize; - global_members_30.with(|rc| rc.borrow()[__idx0]) + global_members_36.with(|rc| rc.borrow()[__idx0]) }) .promoted } as i32) @@ -1241,21 +1510,21 @@ pub fn test_global_members_32() { i = 0; result = ({ match ({ 99_u32 }, { - let __tmp_93 = field_ptr!( - global_members_30.with(|v| v.decay()).offset({ + let __tmp_115 = field_ptr!( + global_members_36.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - global_members_30.with(|rc| rc.borrow()[__idx0]) + global_members_36.with(|rc| rc.borrow()[__idx0]) }) .key }), value ); - __tmp_93 + __tmp_115 }) { - (__tmp_92, __tmp_93) => __tmp_93.with_mut(|__tmp_93| { - (*__tmp_93) = __tmp_92; - (*__tmp_93).clone() + (__tmp_114, __tmp_115) => __tmp_115.with_mut(|__tmp_115| { + (*__tmp_115) = __tmp_114; + (*__tmp_115).clone() }), } }); @@ -1266,38 +1535,38 @@ pub fn test_global_members_32() { { ({ let __idx0 = (0) as usize; - global_members_30.with(|rc| rc.borrow()[__idx0]) + global_members_36.with(|rc| rc.borrow()[__idx0]) }) .value }, { ({ let __idx0 = (1) as usize; - global_members_30.with(|rc| rc.borrow()[__idx0]) + global_members_36.with(|rc| rc.borrow()[__idx0]) }) .value } ); } -pub fn test_static_members_33() { +pub fn test_static_members_39() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_95 = field_ptr!( - a_34.with(|v| v.decay()).offset({ + let __tmp_117 = field_ptr!( + a_40.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - a_34.with(|rc| rc.borrow()[__idx0]) + a_40.with(|rc| rc.borrow()[__idx0]) }) .key }), value ); - __tmp_95 + __tmp_117 }) { - (__tmp_94, __tmp_95) => __tmp_95.with_mut(|__tmp_95| { - (*__tmp_95) = (((*__tmp_95) as u32).wrapping_add((__tmp_94 as u32))) as u32; - (*__tmp_95).clone() + (__tmp_116, __tmp_117) => __tmp_117.with_mut(|__tmp_117| { + (*__tmp_117) = (((*__tmp_117) as u32).wrapping_add((__tmp_116 as u32))) as u32; + (*__tmp_117).clone() }), } }); @@ -1308,14 +1577,14 @@ pub fn test_static_members_33() { { ({ let __idx0 = (0) as usize; - a_34.with(|rc| rc.borrow()[__idx0]) + a_40.with(|rc| rc.borrow()[__idx0]) }) .value }, { ({ let __idx0 = (1) as usize; - a_34.with(|rc| rc.borrow()[__idx0]) + a_40.with(|rc| rc.borrow()[__idx0]) }) .value } @@ -1323,20 +1592,20 @@ pub fn test_static_members_33() { i = 0; { match ({ 1 }, { - let __tmp_97 = field_ptr!( - a_34.with(|v| v.decay()).offset({ + let __tmp_119 = field_ptr!( + a_40.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - a_34.with(|rc| rc.borrow()[__idx0]) + a_40.with(|rc| rc.borrow()[__idx0]) }) .key }), promoted ); - __tmp_97 + __tmp_119 }) { - (__tmp_96, __tmp_97) => __tmp_97.with_mut(|__tmp_97| { - (*__tmp_97) = (((*__tmp_97) as i32) + (__tmp_96 as i32)) as i16; + (__tmp_118, __tmp_119) => __tmp_119.with_mut(|__tmp_119| { + (*__tmp_119) = (((*__tmp_119) as i32) + (__tmp_118 as i32)) as i16; }), } }; @@ -1346,14 +1615,14 @@ pub fn test_static_members_33() { ({ ({ let __idx0 = (0) as usize; - a_34.with(|rc| rc.borrow()[__idx0]) + a_40.with(|rc| rc.borrow()[__idx0]) }) .promoted } as i32), ({ ({ let __idx0 = (1) as usize; - a_34.with(|rc| rc.borrow()[__idx0]) + a_40.with(|rc| rc.borrow()[__idx0]) }) .promoted } as i32) @@ -1361,21 +1630,21 @@ pub fn test_static_members_33() { i = 0; result = ({ match ({ 99_u32 }, { - let __tmp_99 = field_ptr!( - a_34.with(|v| v.decay()).offset({ + let __tmp_121 = field_ptr!( + a_40.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - a_34.with(|rc| rc.borrow()[__idx0]) + a_40.with(|rc| rc.borrow()[__idx0]) }) .key }), value ); - __tmp_99 + __tmp_121 }) { - (__tmp_98, __tmp_99) => __tmp_99.with_mut(|__tmp_99| { - (*__tmp_99) = __tmp_98; - (*__tmp_99).clone() + (__tmp_120, __tmp_121) => __tmp_121.with_mut(|__tmp_121| { + (*__tmp_121) = __tmp_120; + (*__tmp_121).clone() }), } }); @@ -1386,21 +1655,21 @@ pub fn test_static_members_33() { { ({ let __idx0 = (0) as usize; - a_34.with(|rc| rc.borrow()[__idx0]) + a_40.with(|rc| rc.borrow()[__idx0]) }) .value }, { ({ let __idx0 = (1) as usize; - a_34.with(|rc| rc.borrow()[__idx0]) + a_40.with(|rc| rc.borrow()[__idx0]) }) .value } ); } thread_local!( - static a_34: Value> = Rc::new(RefCell::new(Box::new([ + static a_40: Value> = Rc::new(RefCell::new(Box::new([ IndexedMember { key: 0, value: 10_u32, @@ -1441,7 +1710,7 @@ fn main_0() -> i32 { (*a.borrow())[(0) as usize], (*a.borrow())[(1) as usize] ); - let mut selector: Index_35 = Index_35 { value: 1 }; + let mut selector: Index_41 = Index_41 { value: 1 }; value = ({ (*a.borrow_mut())[(selector.value) as usize] = 88; (*a.borrow())[(selector.value) as usize] @@ -1462,12 +1731,12 @@ fn main_0() -> i32 { alias.write(0); let __rhs = ({ match ({ 1 }, { - let __tmp_101 = a.decay().offset((alias.read())); - __tmp_101 + let __tmp_123 = a.decay().offset((alias.read())); + __tmp_123 }) { - (__tmp_100, __tmp_101) => __tmp_101.with_mut(|__tmp_101| { - (*__tmp_101) = __tmp_100; - (*__tmp_101).clone() + (__tmp_122, __tmp_123) => __tmp_123.with_mut(|__tmp_123| { + (*__tmp_123) = __tmp_122; + (*__tmp_123).clone() }), } }); @@ -1523,7 +1792,7 @@ fn main_0() -> i32 { deref_value, (*a.borrow())[(1) as usize] ); - let mut owner: Owner_36 = Owner_36 { + let mut owner: Owner_42 = Owner_42 { values: Box::new([0, 20]), index: 0, }; @@ -1532,9 +1801,9 @@ fn main_0() -> i32 { { 1 }, &mut (owner.values[(owner.values[(0) as usize]) as usize]), ) { - (__tmp_102, __tmp_103) => { - (*__tmp_103) = __tmp_102; - (*__tmp_103).clone() + (__tmp_124, __tmp_125) => { + (*__tmp_125) = __tmp_124; + (*__tmp_125).clone() } } }); @@ -1549,16 +1818,16 @@ fn main_0() -> i32 { owner.values[(0) as usize], owner.values[(1) as usize] ); - let alias_selector: Value = Rc::new(RefCell::new(Index_35 { value: 0 })); + let alias_selector: Value = Rc::new(RefCell::new(Index_41 { value: 0 })); let mut member_alias: Ptr = (field_ptr!(alias_selector.as_pointer(), value)); let __rhs = ({ match ({ 1 }, { - let __tmp_105 = member_alias.offset(({ (*alias_selector.borrow()).value }) as isize); - __tmp_105 + let __tmp_127 = member_alias.offset(({ (*alias_selector.borrow()).value }) as isize); + __tmp_127 }) { - (__tmp_104, __tmp_105) => __tmp_105.with_mut(|__tmp_105| { - (*__tmp_105) = __tmp_104; - (*__tmp_105).clone() + (__tmp_126, __tmp_127) => __tmp_127.with_mut(|__tmp_127| { + (*__tmp_127) = __tmp_126; + (*__tmp_127).clone() }), } }); @@ -1570,12 +1839,12 @@ fn main_0() -> i32 { let mut self_: Ptr = (self_index.as_pointer()); let __rhs = ({ match ({ 1 }, { - let __tmp_107 = self_.offset((*self_index.borrow()) as isize); - __tmp_107 + let __tmp_129 = self_.offset((*self_index.borrow()) as isize); + __tmp_129 }) { - (__tmp_106, __tmp_107) => __tmp_107.with_mut(|__tmp_107| { - (*__tmp_107) = __tmp_106; - (*__tmp_107).clone() + (__tmp_128, __tmp_129) => __tmp_129.with_mut(|__tmp_129| { + (*__tmp_129) = __tmp_128; + (*__tmp_129).clone() }), } }); @@ -1591,13 +1860,13 @@ fn main_0() -> i32 { || -> i32 { return ({ match ({ 10000 }, { - let __tmp_109 = + let __tmp_131 = (captured_pointer.read()).offset((captured_index.read()) as isize); - __tmp_109 + __tmp_131 }) { - (__tmp_108, __tmp_109) => __tmp_109.with_mut(|__tmp_109| { - (*__tmp_109) = __tmp_108; - (*__tmp_109).clone() + (__tmp_130, __tmp_131) => __tmp_131.with_mut(|__tmp_131| { + (*__tmp_131) = __tmp_130; + (*__tmp_131).clone() }), } }); @@ -1609,9 +1878,12 @@ fn main_0() -> i32 { value, (*captured_index.borrow()) ); - ({ test_local_members_31() }); - ({ test_global_members_32() }); - ({ test_static_members_33() }); + ({ test_local_members_37() }); + ({ test_global_members_38() }); + ({ test_static_members_39() }); + ({ test_reference_members_5() }); + ({ test_reference_members_7() }); + ({ test_reference_pointer_9() }); ({ test_0() }); ({ test_1() }); ({ test_2() }); @@ -1631,9 +1903,9 @@ fn main_0() -> i32 { 0 )), ) { - (__tmp_110, __tmp_111) => __tmp_111.with_mut(|__tmp_111| { - (*__tmp_111) = (((*__tmp_111) as u32).wrapping_add((__tmp_110 as u32))) as u32; - (*__tmp_111).clone() + (__tmp_132, __tmp_133) => __tmp_133.with_mut(|__tmp_133| { + (*__tmp_133) = (((*__tmp_133) as u32).wrapping_add((__tmp_132 as u32))) as u32; + (*__tmp_133).clone() }), } }); @@ -1643,24 +1915,24 @@ fn main_0() -> i32 { result, (*values.borrow())[(0) as usize] ); - ({ test_borrows_12() }); - ({ test_binding_18() }); - ({ test_alias_scopes_23(10_i16) }); - ({ test_boxed_array_24() }); - ({ test_boxed_array_26() }); + ({ test_borrows_18() }); + ({ test_binding_24() }); + ({ test_alias_scopes_29(10_i16) }); + ({ test_boxed_array_30() }); + ({ test_boxed_array_32() }); let mut global_result: u32 = ({ match ({ 1_u32 }, { - let __tmp_113 = global_array_28.with(|v| v.decay()).offset( + let __tmp_135 = global_array_34.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; - global_array_28.with(|rc| rc.borrow()[__idx0]) + global_array_34.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_113 + __tmp_135 }) { - (__tmp_112, __tmp_113) => __tmp_113.with_mut(|__tmp_113| { - (*__tmp_113) = (((*__tmp_113) as u32).wrapping_add((__tmp_112 as u32))) as u32; - (*__tmp_113).clone() + (__tmp_134, __tmp_135) => __tmp_135.with_mut(|__tmp_135| { + (*__tmp_135) = (((*__tmp_135) as u32).wrapping_add((__tmp_134 as u32))) as u32; + (*__tmp_135).clone() }), } }); @@ -1669,28 +1941,28 @@ fn main_0() -> i32 { global_result, ({ let __idx0 = (0) as usize; - global_array_28.with(|rc| rc.borrow()[__idx0]) + global_array_34.with(|rc| rc.borrow()[__idx0]) }) ); i = 0; result = ({ match ({ 1_u32 }, { - let __tmp_115 = global_rows_29 + let __tmp_137 = global_rows_35 .with(|v| v.decay()) .offset( ({ let __idx0 = (i.postfix_inc()) as usize; let __idx1 = (0) as usize; - global_rows_29.with(|rc| rc.borrow()[__idx0][__idx1]) + global_rows_35.with(|rc| rc.borrow()[__idx0][__idx1]) }), ) .decay() .offset(0); - __tmp_115 + __tmp_137 }) { - (__tmp_114, __tmp_115) => __tmp_115.with_mut(|__tmp_115| { - (*__tmp_115) = (((*__tmp_115) as u32).wrapping_add((__tmp_114 as u32))) as u32; - (*__tmp_115).clone() + (__tmp_136, __tmp_137) => __tmp_137.with_mut(|__tmp_137| { + (*__tmp_137) = (((*__tmp_137) as u32).wrapping_add((__tmp_136 as u32))) as u32; + (*__tmp_137).clone() }), } }); @@ -1701,35 +1973,35 @@ fn main_0() -> i32 { ({ let __idx0 = (0) as usize; let __idx1 = (0) as usize; - global_rows_29.with(|rc| rc.borrow()[__idx0][__idx1]) + global_rows_35.with(|rc| rc.borrow()[__idx0][__idx1]) }), ({ let __idx0 = (1) as usize; let __idx1 = (0) as usize; - global_rows_29.with(|rc| rc.borrow()[__idx0][__idx1]) + global_rows_35.with(|rc| rc.borrow()[__idx0][__idx1]) }) ); return 0; } #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(4)] -pub struct Index_35 { +pub struct Index_41 { #[offset(0)] pub value: i32, } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] #[byte_size(12)] -pub struct Owner_36 { +pub struct Owner_42 { #[offset(0)] #[byte_size(8)] pub values: Box<[i32]>, #[offset(8)] pub index: i32, } -impl Default for Owner_36 { +impl Default for Owner_42 { fn default() -> Self { { - Owner_36 { + Owner_42 { values: (0..2).map(|_| 0_i32).collect::>(), index: 0_i32, } @@ -1741,23 +2013,23 @@ pub trait IndexedBindingImpl { } impl IndexedBindingImpl for Ptr { fn get_1_0(&self) -> Ptr { - return selected_values_17.with(|v| v.decay()).offset( + return selected_values_23.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; - selected_values_17.with(|rc| rc.borrow()[__idx0]) + selected_values_23.with(|rc| rc.borrow()[__idx0]) }), ); } } pub fn __cpp2rust_init_globals() { - let _ = global_5.with(|_| ()); - let _ = global_record_8.with(|_| ()); - let _ = targets_10.with(|_| ()); - let _ = cursor_11.with(|_| ()); - let _ = selected_values_17.with(|_| ()); - let _ = initializer_target_20.with(|_| ()); - let _ = initializer_result_22.with(|_| ()); - let _ = global_array_28.with(|_| ()); - let _ = global_rows_29.with(|_| ()); - let _ = global_members_30.with(|_| ()); + let _ = global_11.with(|_| ()); + let _ = global_record_14.with(|_| ()); + let _ = targets_16.with(|_| ()); + let _ = cursor_17.with(|_| ()); + let _ = selected_values_23.with(|_| ()); + let _ = initializer_target_26.with(|_| ()); + let _ = initializer_result_28.with(|_| ()); + let _ = global_array_34.with(|_| ()); + let _ = global_rows_35.with(|_| ()); + let _ = global_members_36.with(|_| ()); } diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index a84def89e6..75320ee266 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -577,11 +577,217 @@ pub unsafe fn test_comma_4() { ) }); } -pub static mut global_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10 }); -pub unsafe fn observe_global_6(mut assigned: i32) -> i32 { - return ((assigned) + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5))); +pub unsafe fn test_reference_members_5() { + let mut index: u32 = 0_u32; + let mut other: u32 = 77_u32; + let mut a: [Slot_6; 2] = [Slot_6 { value: &mut index }, Slot_6 { value: &mut other }]; + match ({ 1_u32 }, &mut (*a[(index) as usize].value)) { + (__tmp_56, __tmp_57) => { + (*__tmp_57) = (((*__tmp_57) as u32).wrapping_add((__tmp_56 as u32))) as u32; + } + }; + (unsafe { + libc::printf( + c"reference void %d %d\n".as_ptr() as *const libc::c_char, + (index as i32), + (other as i32), + ) + }); + index = 0_u32; + let mut result: u32 = (match ({ 1_u32 }, &mut (*a[(index) as usize].value)) { + (__tmp_58, __tmp_59) => { + (*__tmp_59) = (((*__tmp_59) as u32).wrapping_add((__tmp_58 as u32))) as u32; + (*__tmp_59).clone() + } + }); + (unsafe { + libc::printf( + c"reference compound %d %d %d\n".as_ptr() as *const libc::c_char, + (index as i32), + (other as i32), + (result as i32), + ) + }); + index = 0_u32; + result = (match ({ 1_u32 }, &mut (*a[(index) as usize].value)) { + (__tmp_60, __tmp_61) => { + (*__tmp_61) = __tmp_60; + (*__tmp_61).clone() + } + }); + (unsafe { + libc::printf( + c"reference simple %d %d %d\n".as_ptr() as *const libc::c_char, + (index as i32), + (other as i32), + (result as i32), + ) + }); + index = 0_u32; + result = (match ({ 1_u32 }, &mut (*a[(index.postfix_inc()) as usize].value)) { + (__tmp_62, __tmp_63) => { + (*__tmp_63) = (((*__tmp_63) as u32).wrapping_add((__tmp_62 as u32))) as u32; + (*__tmp_63).clone() + } + }); + (unsafe { + libc::printf( + c"reference effect %d %d %d\n".as_ptr() as *const libc::c_char, + (index as i32), + (other as i32), + (result as i32), + ) + }); + index = 0_u32; + result = (match ( + { + { + index = 1_u32; + 2_u32 + } + }, + &mut (*a[(index) as usize].value), + ) { + (__tmp_64, __tmp_65) => { + (*__tmp_65) = (((*__tmp_65) as u32).wrapping_add((__tmp_64 as u32))) as u32; + (*__tmp_65).clone() + } + }); + (unsafe { + libc::printf( + c"reference rhs %d %d %d\n".as_ptr() as *const libc::c_char, + (index as i32), + (other as i32), + (result as i32), + ) + }); +} +pub unsafe fn test_reference_members_7() { + let mut index: i16 = 0_i16; + let mut other: i16 = 77_i16; + let mut a: [Slot_8; 2] = [Slot_8 { value: &mut index }, Slot_8 { value: &mut other }]; + match ({ 1 }, &mut (*a[(index) as usize].value)) { + (__tmp_66, __tmp_67) => { + (*__tmp_67) = (((*__tmp_67) as i32) + (__tmp_66 as i32)) as i16; + } + }; + (unsafe { + libc::printf( + c"reference void %d %d\n".as_ptr() as *const libc::c_char, + (index as i32), + (other as i32), + ) + }); + index = 0_i16; + let mut result: i16 = (match ({ 1 }, &mut (*a[(index) as usize].value)) { + (__tmp_68, __tmp_69) => { + (*__tmp_69) = (((*__tmp_69) as i32) + (__tmp_68 as i32)) as i16; + (*__tmp_69).clone() + } + }); + (unsafe { + libc::printf( + c"reference compound %d %d %d\n".as_ptr() as *const libc::c_char, + (index as i32), + (other as i32), + (result as i32), + ) + }); + index = 0_i16; + result = (match ({ 1_i16 }, &mut (*a[(index) as usize].value)) { + (__tmp_70, __tmp_71) => { + (*__tmp_71) = __tmp_70; + (*__tmp_71).clone() + } + }); + (unsafe { + libc::printf( + c"reference simple %d %d %d\n".as_ptr() as *const libc::c_char, + (index as i32), + (other as i32), + (result as i32), + ) + }); + index = 0_i16; + result = (match ({ 1 }, &mut (*a[(index.postfix_inc()) as usize].value)) { + (__tmp_72, __tmp_73) => { + (*__tmp_73) = (((*__tmp_73) as i32) + (__tmp_72 as i32)) as i16; + (*__tmp_73).clone() + } + }); + (unsafe { + libc::printf( + c"reference effect %d %d %d\n".as_ptr() as *const libc::c_char, + (index as i32), + (other as i32), + (result as i32), + ) + }); + index = 0_i16; + result = (match ( + { + ({ + index = 1_i16; + 2_i16 + } as i32) + }, + &mut (*a[(index) as usize].value), + ) { + (__tmp_74, __tmp_75) => { + (*__tmp_75) = (((*__tmp_75) as i32) + (__tmp_74 as i32)) as i16; + (*__tmp_75).clone() + } + }); + (unsafe { + libc::printf( + c"reference rhs %d %d %d\n".as_ptr() as *const libc::c_char, + (index as i32), + (other as i32), + (result as i32), + ) + }); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Slot_6 { + pub value: *mut u32, +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Slot_8 { + pub value: *mut i16, } -pub unsafe fn observe_7(mut assigned: i32, mut stored: *const i32) -> i32 { +pub unsafe fn test_reference_pointer_9() { + let mut p: *mut Node_10 = std::ptr::null_mut(); + let mut q: *mut Node_10 = std::ptr::null_mut(); + let mut first: Node_10 = Node_10 { link: &mut p }; + let mut second: Node_10 = Node_10 { link: &mut q }; + p = (&mut first as *mut Node_10); + q = (&mut first as *mut Node_10); + let mut result: *mut Node_10 = (match ({ (&mut second as *mut Node_10) }, &mut (*(*p).link)) { + (__tmp_76, __tmp_77) => { + (*__tmp_77) = __tmp_76; + (*__tmp_77).clone() + } + }); + (unsafe { + libc::printf( + c"reference pointer %d %d\n".as_ptr() as *const libc::c_char, + (((p) == (&mut second as *mut Node_10)) as i32), + (((result) == (&mut second as *mut Node_10)) as i32), + ) + }); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Node_10 { + pub link: *mut *mut Node_10, +} +pub static mut global_11: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10 }); +pub unsafe fn observe_global_12(mut assigned: i32) -> i32 { + return ((assigned) + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11))); +} +pub unsafe fn observe_13(mut assigned: i32, mut stored: *const i32) -> i32 { return ((assigned) + (*stored)); } #[repr(C)] @@ -594,31 +800,31 @@ pub struct GlobalRecord_Inner { pub struct GlobalRecord { pub inner: GlobalRecord_Inner, } -pub static mut global_record_8: std::cell::LazyCell = +pub static mut global_record_14: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { GlobalRecord { inner: GlobalRecord_Inner { value: 10 }, } }); -pub unsafe fn observe_record_9(mut assigned: i32) -> i32 { +pub unsafe fn observe_record_15(mut assigned: i32) -> i32 { return ((assigned) - + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_8)) + + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_14)) .inner .value)); } -pub static mut targets_10: std::cell::LazyCell<[i32; 2]> = +pub static mut targets_16: std::cell::LazyCell<[i32; 2]> = std::cell::LazyCell::new(|| unsafe { [10, 20] }); -pub static mut cursor_11: std::cell::LazyCell<*mut i32> = std::cell::LazyCell::new(|| unsafe { - (*std::cell::LazyCell::force_mut(&mut *&raw mut targets_10)).as_mut_ptr() +pub static mut cursor_17: std::cell::LazyCell<*mut i32> = std::cell::LazyCell::new(|| unsafe { + (*std::cell::LazyCell::force_mut(&mut *&raw mut targets_16)).as_mut_ptr() }); -pub unsafe fn test_borrows_12() { +pub unsafe fn test_borrows_18() { (unsafe { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - observe_global_6({ - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)) = 99; - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)) + observe_global_12({ + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11)) = 99; + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11)) }) }), ) @@ -627,9 +833,9 @@ pub unsafe fn test_borrows_12() { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - observe_global_6({ - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)) += 5; - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)) + observe_global_12({ + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11)) += 5; + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11)) }) }), ) @@ -638,16 +844,16 @@ pub unsafe fn test_borrows_12() { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - observe_global_6({ - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)) = (unsafe { - observe_7( + observe_global_12({ + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11)) = (unsafe { + observe_13( 0, - (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)) + (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11)) as *mut i32) .cast_const(), ) }); - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11)) }) }), ) @@ -655,22 +861,22 @@ pub unsafe fn test_borrows_12() { let mut assigned: i32 = ((match ( { { - (*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_13)) = (-1_i32 as i16); + (*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_19)) = (-1_i32 as i16); 0.5_f64 } }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_13)), + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_19)), ) { - (__tmp_56, __tmp_57) => { - (*__tmp_57) = (((*__tmp_57) as f64) + (__tmp_56 as f64)) as i16; - (*__tmp_57).clone() + (__tmp_78, __tmp_79) => { + (*__tmp_79) = (((*__tmp_79) as f64) + (__tmp_78 as f64)) as i16; + (*__tmp_79).clone() } }) as i32); (unsafe { libc::printf( c"%d %d\n".as_ptr() as *const libc::c_char, (assigned), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_13)) as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_19)) as i32), ) }); let mut aliased: i16 = 10_i16; @@ -684,9 +890,9 @@ pub unsafe fn test_borrows_12() { }, &mut (aliased), ) { - (__tmp_58, __tmp_59) => { - (*__tmp_59) = (((*__tmp_59) as f64) + (__tmp_58 as f64)) as i16; - (*__tmp_59).clone() + (__tmp_80, __tmp_81) => { + (*__tmp_81) = (((*__tmp_81) as f64) + (__tmp_80 as f64)) as i16; + (*__tmp_81).clone() } }) as i32); (unsafe { @@ -700,9 +906,9 @@ pub unsafe fn test_borrows_12() { { { (unsafe { - observe_7( + observe_13( 0, - (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_5)) + (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11)) as *mut i32) .cast_const(), ) @@ -710,29 +916,29 @@ pub unsafe fn test_borrows_12() { 0.5_f64 } }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut flag_14)), + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut flag_20)), ) { - (__tmp_60, __tmp_61) => { - (*__tmp_61) = (((*__tmp_61) as u8 as f64) + (__tmp_60 as f64)) != 0.0; - (*__tmp_61).clone() + (__tmp_82, __tmp_83) => { + (*__tmp_83) = (((*__tmp_83) as u8 as f64) + (__tmp_82 as f64)) != 0.0; + (*__tmp_83).clone() } }); (unsafe { libc::printf( c"%d %d\n".as_ptr() as *const libc::c_char, (enabled as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut flag_14)) as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut flag_20)) as i32), ) }); (unsafe { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - observe_record_9({ - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_8)) + observe_record_15({ + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_14)) .inner .value = 99; - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_8)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_14)) .inner .value }) @@ -742,27 +948,27 @@ pub unsafe fn test_borrows_12() { let mut shifted: *mut i32 = (match ( { { - (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_11)) = - (*std::cell::LazyCell::force_mut(&mut *&raw mut targets_10)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_17)) = + (*std::cell::LazyCell::force_mut(&mut *&raw mut targets_16)) .as_mut_ptr() .offset((1) as isize); 1 } }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_11)), + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_17)), ) { - (__tmp_62, __tmp_63) => { - (*__tmp_63) = (*__tmp_63).offset(-(__tmp_62 as isize)); - (*__tmp_63).clone() + (__tmp_84, __tmp_85) => { + (*__tmp_85) = (*__tmp_85).offset(-(__tmp_84 as isize)); + (*__tmp_85).clone() } }); (unsafe { libc::printf( c"%d %d\n".as_ptr() as *const libc::c_char, - (((*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_11)) - == ((*std::cell::LazyCell::force_mut(&mut *&raw mut targets_10)).as_mut_ptr())) + (((*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_17)) + == ((*std::cell::LazyCell::force_mut(&mut *&raw mut targets_16)).as_mut_ptr())) as i32), - (((shifted) == (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_11))) as i32), + (((shifted) == (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_17))) as i32), ) }); let mut local: i32 = 10; @@ -775,7 +981,7 @@ pub unsafe fn test_borrows_12() { local }; let _stored: *const i32 = (&mut local as *mut i32).cast_const(); - observe_7(_assigned, _stored) + observe_13(_assigned, _stored) }), ) }); @@ -788,11 +994,11 @@ pub unsafe fn test_borrows_12() { local }; let _stored: *const i32 = (&mut local as *mut i32).cast_const(); - observe_7(_assigned, _stored) + observe_13(_assigned, _stored) }), ) }); - let mut record: Record_15 = Record_15 { value: 10 }; + let mut record: Record_21 = Record_21 { value: 10 }; (unsafe { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, @@ -802,7 +1008,7 @@ pub unsafe fn test_borrows_12() { record.value }; let _stored: *const i32 = (&mut record.value as *mut i32).cast_const(); - observe_7(_assigned, _stored) + observe_13(_assigned, _stored) }), ) }); @@ -815,32 +1021,32 @@ pub unsafe fn test_borrows_12() { record.value }; let _stored: *const i32 = (&mut record.value as *mut i32).cast_const(); - observe_7(_assigned, _stored) + observe_13(_assigned, _stored) }), ) }); - let mut first: Link_16 = ::default(); - first = Link_16 { - next: (&mut first as *mut Link_16), + let mut first: Link_22 = ::default(); + first = Link_22 { + next: (&mut first as *mut Link_22), }; - let mut second: Link_16 = Link_16 { - next: (&mut first as *mut Link_16), + let mut second: Link_22 = Link_22 { + next: (&mut first as *mut Link_22), }; - let selector: *mut *mut Link_16 = &mut first.next; - let mut selected: *mut Link_16 = (match ( - { (&mut second as *mut Link_16) }, + let selector: *mut *mut Link_22 = &mut first.next; + let mut selected: *mut Link_22 = (match ( + { (&mut second as *mut Link_22) }, &mut ((*(*selector)).next), ) { - (__tmp_64, __tmp_65) => { - (*__tmp_65) = __tmp_64; - (*__tmp_65).clone() + (__tmp_86, __tmp_87) => { + (*__tmp_87) = __tmp_86; + (*__tmp_87).clone() } }); (unsafe { libc::printf( c"%d %d\n".as_ptr() as *const libc::c_char, - (((selected) == (&mut second as *mut Link_16)) as i32), - (((first.next) == (&mut second as *mut Link_16)) as i32), + (((selected) == (&mut second as *mut Link_22)) as i32), + (((first.next) == (&mut second as *mut Link_22)) as i32), ) }); let mut values: Vec = vec![10; 1_usize]; @@ -853,7 +1059,7 @@ pub unsafe fn test_borrows_12() { values[(0_usize)] }; let _stored: *const i32 = (&mut values[(0_usize)] as *mut i32).cast_const(); - observe_7(_assigned, _stored) + observe_13(_assigned, _stored) }), ) }); @@ -866,75 +1072,75 @@ pub unsafe fn test_borrows_12() { values[(0_usize)] }; let _stored: *const i32 = (&mut values[(0_usize)] as *mut i32).cast_const(); - observe_7(_assigned, _stored) + observe_13(_assigned, _stored) }), ) }); } -static mut promoted_13: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10_i16 }); -static mut flag_14: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { false }); +static mut promoted_19: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10_i16 }); +static mut flag_20: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { false }); #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Record_15 { +pub struct Record_21 { pub value: i32, } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Link_16 { - pub next: *mut Link_16, +pub struct Link_22 { + pub next: *mut Link_22, } -pub static mut selected_values_17: std::cell::LazyCell<[u32; 3]> = +pub static mut selected_values_23: std::cell::LazyCell<[u32; 3]> = std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] pub struct IndexedBinding {} impl IndexedBinding { pub unsafe fn get_1_0(&mut self) -> *mut u32 { - return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_17)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_17))[(0) as usize]) + return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_23)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_23))[(0) as usize]) as usize]; } } -pub unsafe fn test_binding_18() { +pub unsafe fn test_binding_24() { let mut owner: IndexedBinding = ::default(); - let __decomp_19: *mut IndexedBinding = &mut owner; - let value: *mut u32 = (unsafe { IndexedBinding::get_1_0(&mut (*__decomp_19)) }); + let __decomp_25: *mut IndexedBinding = &mut owner; + let value: *mut u32 = (unsafe { IndexedBinding::get_1_0(&mut (*__decomp_25)) }); let mut result: u32 = (match ( { 1_u32 }, - &mut (*(unsafe { IndexedBinding::get_1_0(&mut (*__decomp_19)) })), + &mut (*(unsafe { IndexedBinding::get_1_0(&mut (*__decomp_25)) })), ) { - (__tmp_66, __tmp_67) => { - (*__tmp_67) = (((*__tmp_67) as u32).wrapping_add((__tmp_66 as u32))) as u32; - (*__tmp_67).clone() + (__tmp_88, __tmp_89) => { + (*__tmp_89) = (((*__tmp_89) as u32).wrapping_add((__tmp_88 as u32))) as u32; + (*__tmp_89).clone() } }); (unsafe { libc::printf( c"binding compound %u %u\n".as_ptr() as *const libc::c_char, (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_17))[(0) as usize]), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_23))[(0) as usize]), ) }); } -pub static mut initializer_target_20: std::cell::LazyCell = +pub static mut initializer_target_26: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10_u32 }); -pub unsafe fn mutate_initializer_21() -> u32 { - (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_20)) = 20_u32; +pub unsafe fn mutate_initializer_27() -> u32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_26)) = 20_u32; return 1_u32; } -pub static mut initializer_result_22: std::cell::LazyCell = +pub static mut initializer_result_28: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { (match ( - { (unsafe { mutate_initializer_21() }) }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_20)), + { (unsafe { mutate_initializer_27() }) }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_26)), ) { - (__tmp_68, __tmp_69) => { - (*__tmp_69) = (((*__tmp_69) as u32).wrapping_add((__tmp_68 as u32))) as u32; - (*__tmp_69).clone() + (__tmp_90, __tmp_91) => { + (*__tmp_91) = (((*__tmp_91) as u32).wrapping_add((__tmp_90 as u32))) as u32; + (*__tmp_91).clone() } }) }); -pub unsafe fn test_alias_scopes_23(mut parameter: i16) { +pub unsafe fn test_alias_scopes_29(mut parameter: i16) { let mut p: *mut i16 = (&mut parameter as *mut i16); let mut result: i16 = (match ( { @@ -945,9 +1151,9 @@ pub unsafe fn test_alias_scopes_23(mut parameter: i16) { }, &mut (parameter), ) { - (__tmp_70, __tmp_71) => { - (*__tmp_71) = (((*__tmp_71) as f64) + (__tmp_70 as f64)) as i16; - (*__tmp_71).clone() + (__tmp_92, __tmp_93) => { + (*__tmp_93) = (((*__tmp_93) as f64) + (__tmp_92 as f64)) as i16; + (*__tmp_93).clone() } }); (unsafe { @@ -968,9 +1174,9 @@ pub unsafe fn test_alias_scopes_23(mut parameter: i16) { } ); result = (match ({ (unsafe { mutate.call() }).clone() }, &mut (local)) { - (__tmp_72, __tmp_73) => { - (*__tmp_73) = (((*__tmp_73) as f64) + (__tmp_72 as f64)) as i16; - (*__tmp_73).clone() + (__tmp_94, __tmp_95) => { + (*__tmp_95) = (((*__tmp_95) as f64) + (__tmp_94 as f64)) as i16; + (*__tmp_95).clone() } }); (unsafe { @@ -983,12 +1189,12 @@ pub unsafe fn test_alias_scopes_23(mut parameter: i16) { (unsafe { libc::printf( c"initializer %u %u\n".as_ptr() as *const libc::c_char, - (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_result_22)), - (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_20)), + (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_result_28)), + (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_26)), ) }); } -pub unsafe fn test_boxed_array_24() { +pub unsafe fn test_boxed_array_30() { let mut a: [u32; 3] = [0_u32, 20_u32, 30_u32]; let mut p: *mut u32 = a.as_mut_ptr(); let mut i: i32 = 0; @@ -996,9 +1202,9 @@ pub unsafe fn test_boxed_array_24() { { 1_u32 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), ) { - (__tmp_74, __tmp_75) => { - (*__tmp_75) = (((*__tmp_75) as u32).wrapping_add((__tmp_74 as u32))) as u32; - (*__tmp_75).clone() + (__tmp_96, __tmp_97) => { + (*__tmp_97) = (((*__tmp_97) as u32).wrapping_add((__tmp_96 as u32))) as u32; + (*__tmp_97).clone() } }); (unsafe { @@ -1016,9 +1222,9 @@ pub unsafe fn test_boxed_array_24() { { 1_u32 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), ) { - (__tmp_76, __tmp_77) => { - (*__tmp_77) = __tmp_76; - (*__tmp_77).clone() + (__tmp_98, __tmp_99) => { + (*__tmp_99) = __tmp_98; + (*__tmp_99).clone() } }); (unsafe { @@ -1032,30 +1238,30 @@ pub unsafe fn test_boxed_array_24() { }); result = (match ( { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_25)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_25))[(0) as usize]) as usize]), + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_31)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_31))[(0) as usize]) as usize]), ) { - (__tmp_78, __tmp_79) => { - (*__tmp_79) = (((*__tmp_79) as u32).wrapping_add((__tmp_78 as u32))) as u32; - (*__tmp_79).clone() + (__tmp_100, __tmp_101) => { + (*__tmp_101) = (((*__tmp_101) as u32).wrapping_add((__tmp_100 as u32))) as u32; + (*__tmp_101).clone() } }); (unsafe { libc::printf( c"static array %d %d\n".as_ptr() as *const libc::c_char, (result as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_25))[(0) as usize] as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_31))[(0) as usize] as i32), ) }); } -pub unsafe fn test_boxed_array_26() { +pub unsafe fn test_boxed_array_32() { let mut a: [i16; 3] = [0_i16, 20_i16, 30_i16]; let mut p: *mut i16 = a.as_mut_ptr(); let mut i: i32 = 0; let mut result: i16 = (match ({ 1 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize])) { - (__tmp_80, __tmp_81) => { - (*__tmp_81) = (((*__tmp_81) as i32) + (__tmp_80 as i32)) as i16; - (*__tmp_81).clone() + (__tmp_102, __tmp_103) => { + (*__tmp_103) = (((*__tmp_103) as i32) + (__tmp_102 as i32)) as i16; + (*__tmp_103).clone() } }); (unsafe { @@ -1073,9 +1279,9 @@ pub unsafe fn test_boxed_array_26() { { 1_i16 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), ) { - (__tmp_82, __tmp_83) => { - (*__tmp_83) = __tmp_82; - (*__tmp_83).clone() + (__tmp_104, __tmp_105) => { + (*__tmp_105) = __tmp_104; + (*__tmp_105).clone() } }); (unsafe { @@ -1089,29 +1295,29 @@ pub unsafe fn test_boxed_array_26() { }); result = (match ( { 1 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_27)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_27))[(0) as usize]) as usize]), + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_33)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_33))[(0) as usize]) as usize]), ) { - (__tmp_84, __tmp_85) => { - (*__tmp_85) = (((*__tmp_85) as i32) + (__tmp_84 as i32)) as i16; - (*__tmp_85).clone() + (__tmp_106, __tmp_107) => { + (*__tmp_107) = (((*__tmp_107) as i32) + (__tmp_106 as i32)) as i16; + (*__tmp_107).clone() } }); (unsafe { libc::printf( c"static array %d %d\n".as_ptr() as *const libc::c_char, (result as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_27))[(0) as usize] as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_33))[(0) as usize] as i32), ) }); } -static mut saved_25: std::cell::LazyCell<[u32; 3]> = +static mut saved_31: std::cell::LazyCell<[u32; 3]> = std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); -static mut saved_27: std::cell::LazyCell<[i16; 3]> = +static mut saved_33: std::cell::LazyCell<[i16; 3]> = std::cell::LazyCell::new(|| unsafe { [0_i16, 20_i16, 30_i16] }); -pub static mut global_array_28: std::cell::LazyCell<[u32; 3]> = +pub static mut global_array_34: std::cell::LazyCell<[u32; 3]> = std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); -pub static mut global_rows_29: std::cell::LazyCell<[[u32; 2]; 2]> = +pub static mut global_rows_35: std::cell::LazyCell<[[u32; 2]; 2]> = std::cell::LazyCell::new(|| unsafe { [[0_u32, 10_u32], [20_u32, 30_u32]] }); #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] @@ -1120,7 +1326,7 @@ pub struct IndexedMember { pub value: u32, pub promoted: i16, } -pub static mut global_members_30: std::cell::LazyCell<[IndexedMember; 2]> = +pub static mut global_members_36: std::cell::LazyCell<[IndexedMember; 2]> = std::cell::LazyCell::new(|| unsafe { [ IndexedMember { @@ -1135,7 +1341,7 @@ pub static mut global_members_30: std::cell::LazyCell<[IndexedMember; 2]> = }, ] }); -pub unsafe fn test_local_members_31() { +pub unsafe fn test_local_members_37() { let mut a: [IndexedMember; 2] = [ IndexedMember { key: 0, @@ -1154,9 +1360,9 @@ pub unsafe fn test_local_members_31() { { 1_u32 }, &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].value), ) { - (__tmp_86, __tmp_87) => { - (*__tmp_87) = (((*__tmp_87) as u32).wrapping_add((__tmp_86 as u32))) as u32; - (*__tmp_87).clone() + (__tmp_108, __tmp_109) => { + (*__tmp_109) = (((*__tmp_109) as u32).wrapping_add((__tmp_108 as u32))) as u32; + (*__tmp_109).clone() } }); (unsafe { @@ -1173,8 +1379,8 @@ pub unsafe fn test_local_members_31() { { 1 }, &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].promoted), ) { - (__tmp_88, __tmp_89) => { - (*__tmp_89) = (((*__tmp_89) as i32) + (__tmp_88 as i32)) as i16; + (__tmp_110, __tmp_111) => { + (*__tmp_111) = (((*__tmp_111) as i32) + (__tmp_110 as i32)) as i16; } }; (unsafe { @@ -1190,9 +1396,9 @@ pub unsafe fn test_local_members_31() { { 99_u32 }, &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].value), ) { - (__tmp_90, __tmp_91) => { - (*__tmp_91) = __tmp_90; - (*__tmp_91).clone() + (__tmp_112, __tmp_113) => { + (*__tmp_113) = __tmp_112; + (*__tmp_113).clone() } }); (unsafe { @@ -1211,19 +1417,19 @@ pub unsafe fn test_local_members_31() { ) }); } -pub unsafe fn test_global_members_32() { +pub unsafe fn test_global_members_38() { let mut i: i32 = 0; let mut result: u32 = (match ( { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30)) + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36)) [(i.postfix_inc()) as usize] .key) as usize] .value), ) { - (__tmp_92, __tmp_93) => { - (*__tmp_93) = (((*__tmp_93) as u32).wrapping_add((__tmp_92 as u32))) as u32; - (*__tmp_93).clone() + (__tmp_114, __tmp_115) => { + (*__tmp_115) = (((*__tmp_115) as u32).wrapping_add((__tmp_114 as u32))) as u32; + (*__tmp_115).clone() } }); (unsafe { @@ -1231,47 +1437,47 @@ pub unsafe fn test_global_members_32() { c"member unsigned %d %u %u %u\n".as_ptr() as *const libc::c_char, (i), (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30))[(0) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36))[(0) as usize] .value), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30))[(1) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36))[(1) as usize] .value), ) }); i = 0; match ( { 1 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30)) + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36)) [(i.postfix_inc()) as usize] .key) as usize] .promoted), ) { - (__tmp_94, __tmp_95) => { - (*__tmp_95) = (((*__tmp_95) as i32) + (__tmp_94 as i32)) as i16; + (__tmp_116, __tmp_117) => { + (*__tmp_117) = (((*__tmp_117) as i32) + (__tmp_116 as i32)) as i16; } }; (unsafe { libc::printf( c"member promoted %d %d %d\n".as_ptr() as *const libc::c_char, (i), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30))[(0) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36))[(0) as usize] .promoted as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30))[(1) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36))[(1) as usize] .promoted as i32), ) }); i = 0; result = (match ( { 99_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30)) + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36)) [(i.postfix_inc()) as usize] .key) as usize] .value), ) { - (__tmp_96, __tmp_97) => { - (*__tmp_97) = __tmp_96; - (*__tmp_97).clone() + (__tmp_118, __tmp_119) => { + (*__tmp_119) = __tmp_118; + (*__tmp_119).clone() } }); (unsafe { @@ -1279,25 +1485,25 @@ pub unsafe fn test_global_members_32() { c"member simple %d %u %u %u\n".as_ptr() as *const libc::c_char, (i), (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30))[(0) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36))[(0) as usize] .value), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_30))[(1) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36))[(1) as usize] .value), ) }); } -pub unsafe fn test_static_members_33() { +pub unsafe fn test_static_members_39() { let mut i: i32 = 0; let mut result: u32 = (match ( { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(i.postfix_inc()) as usize] + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(i.postfix_inc()) as usize] .key) as usize] .value), ) { - (__tmp_98, __tmp_99) => { - (*__tmp_99) = (((*__tmp_99) as u32).wrapping_add((__tmp_98 as u32))) as u32; - (*__tmp_99).clone() + (__tmp_120, __tmp_121) => { + (*__tmp_121) = (((*__tmp_121) as u32).wrapping_add((__tmp_120 as u32))) as u32; + (*__tmp_121).clone() } }); (unsafe { @@ -1305,41 +1511,41 @@ pub unsafe fn test_static_members_33() { c"member unsigned %d %u %u %u\n".as_ptr() as *const libc::c_char, (i), (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(0) as usize].value), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(1) as usize].value), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(0) as usize].value), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(1) as usize].value), ) }); i = 0; match ( { 1 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(i.postfix_inc()) as usize] + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(i.postfix_inc()) as usize] .key) as usize] .promoted), ) { - (__tmp_100, __tmp_101) => { - (*__tmp_101) = (((*__tmp_101) as i32) + (__tmp_100 as i32)) as i16; + (__tmp_122, __tmp_123) => { + (*__tmp_123) = (((*__tmp_123) as i32) + (__tmp_122 as i32)) as i16; } }; (unsafe { libc::printf( c"member promoted %d %d %d\n".as_ptr() as *const libc::c_char, (i), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(0) as usize].promoted as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(1) as usize].promoted as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(0) as usize].promoted as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(1) as usize].promoted as i32), ) }); i = 0; result = (match ( { 99_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(i.postfix_inc()) as usize] + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(i.postfix_inc()) as usize] .key) as usize] .value), ) { - (__tmp_102, __tmp_103) => { - (*__tmp_103) = __tmp_102; - (*__tmp_103).clone() + (__tmp_124, __tmp_125) => { + (*__tmp_125) = __tmp_124; + (*__tmp_125).clone() } }); (unsafe { @@ -1347,12 +1553,12 @@ pub unsafe fn test_static_members_33() { c"member simple %d %u %u %u\n".as_ptr() as *const libc::c_char, (i), (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(0) as usize].value), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_34))[(1) as usize].value), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(0) as usize].value), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(1) as usize].value), ) }); } -static mut a_34: std::cell::LazyCell<[IndexedMember; 2]> = std::cell::LazyCell::new(|| unsafe { +static mut a_40: std::cell::LazyCell<[IndexedMember; 2]> = std::cell::LazyCell::new(|| unsafe { [ IndexedMember { key: 0, @@ -1400,7 +1606,7 @@ unsafe fn main_0() -> i32 { (a[(1) as usize]), ) }); - let mut selector: Index_35 = Index_35 { value: 1 }; + let mut selector: Index_41 = Index_41 { value: 1 }; value = ({ a[(selector.value) as usize] = 88; a[(selector.value) as usize] @@ -1421,9 +1627,9 @@ unsafe fn main_0() -> i32 { let alias: *mut i32 = &mut a[(0) as usize]; (*alias) = 0; value = (match ({ 1 }, &mut (a[(*alias) as usize])) { - (__tmp_104, __tmp_105) => { - (*__tmp_105) = __tmp_104; - (*__tmp_105).clone() + (__tmp_126, __tmp_127) => { + (*__tmp_127) = __tmp_126; + (*__tmp_127).clone() } }); (unsafe { @@ -1480,7 +1686,7 @@ unsafe fn main_0() -> i32 { (a[(1) as usize]), ) }); - let mut owner: Owner_36 = Owner_36 { + let mut owner: Owner_42 = Owner_42 { values: [0, 20], index: 0, }; @@ -1488,9 +1694,9 @@ unsafe fn main_0() -> i32 { { 1 }, &mut (owner.values[(owner.values[(0) as usize]) as usize]), ) { - (__tmp_106, __tmp_107) => { - (*__tmp_107) = __tmp_106; - (*__tmp_107).clone() + (__tmp_128, __tmp_129) => { + (*__tmp_129) = __tmp_128; + (*__tmp_129).clone() } }); reference_value = ({ @@ -1506,15 +1712,15 @@ unsafe fn main_0() -> i32 { (owner.values[(1) as usize]), ) }); - let mut alias_selector: Index_35 = Index_35 { value: 0 }; + let mut alias_selector: Index_41 = Index_41 { value: 0 }; let mut member_alias: *mut i32 = (&mut alias_selector.value as *mut i32); value = (match ( { 1 }, &mut (*member_alias.offset((alias_selector.value) as isize)), ) { - (__tmp_108, __tmp_109) => { - (*__tmp_109) = __tmp_108; - (*__tmp_109).clone() + (__tmp_130, __tmp_131) => { + (*__tmp_131) = __tmp_130; + (*__tmp_131).clone() } }); (unsafe { @@ -1527,9 +1733,9 @@ unsafe fn main_0() -> i32 { let mut self_index: i32 = 0; let mut self_: *mut i32 = (&mut self_index as *mut i32); value = (match ({ 1 }, &mut (*self_.offset((self_index) as isize))) { - (__tmp_110, __tmp_111) => { - (*__tmp_111) = __tmp_110; - (*__tmp_111).clone() + (__tmp_132, __tmp_133) => { + (*__tmp_133) = __tmp_132; + (*__tmp_133).clone() } }); (unsafe { @@ -1551,9 +1757,9 @@ unsafe fn main_0() -> i32 { { 10000 }, &mut (*(*captured_pointer).offset((*captured_index) as isize)), ) { - (__tmp_112, __tmp_113) => { - (*__tmp_113) = __tmp_112; - (*__tmp_113).clone() + (__tmp_134, __tmp_135) => { + (*__tmp_135) = __tmp_134; + (*__tmp_135).clone() } }); } @@ -1566,9 +1772,12 @@ unsafe fn main_0() -> i32 { (captured_index), ) }); - (unsafe { test_local_members_31() }); - (unsafe { test_global_members_32() }); - (unsafe { test_static_members_33() }); + (unsafe { test_local_members_37() }); + (unsafe { test_global_members_38() }); + (unsafe { test_static_members_39() }); + (unsafe { test_reference_members_5() }); + (unsafe { test_reference_members_7() }); + (unsafe { test_reference_pointer_9() }); (unsafe { test_0() }); (unsafe { test_1() }); (unsafe { test_2() }); @@ -1584,9 +1793,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_114, __tmp_115) => { - (*__tmp_115) = (((*__tmp_115) as u32).wrapping_add((__tmp_114 as u32))) as u32; - (*__tmp_115).clone() + (__tmp_136, __tmp_137) => { + (*__tmp_137) = (((*__tmp_137) as u32).wrapping_add((__tmp_136 as u32))) as u32; + (*__tmp_137).clone() } }); (unsafe { @@ -1597,39 +1806,39 @@ unsafe fn main_0() -> i32 { (values[(0) as usize]), ) }); - (unsafe { test_borrows_12() }); - (unsafe { test_binding_18() }); - (unsafe { test_alias_scopes_23(10_i16) }); - (unsafe { test_boxed_array_24() }); - (unsafe { test_boxed_array_26() }); + (unsafe { test_borrows_18() }); + (unsafe { test_binding_24() }); + (unsafe { test_alias_scopes_29(10_i16) }); + (unsafe { test_boxed_array_30() }); + (unsafe { test_boxed_array_32() }); let mut global_result: u32 = (match ( { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_28)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_28))[(0) as usize]) + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_34)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_34))[(0) as usize]) as usize]), ) { - (__tmp_116, __tmp_117) => { - (*__tmp_117) = (((*__tmp_117) as u32).wrapping_add((__tmp_116 as u32))) as u32; - (*__tmp_117).clone() + (__tmp_138, __tmp_139) => { + (*__tmp_139) = (((*__tmp_139) as u32).wrapping_add((__tmp_138 as u32))) as u32; + (*__tmp_139).clone() } }); (unsafe { libc::printf( c"global array %u %u\n".as_ptr() as *const libc::c_char, (global_result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_28))[(0) as usize]), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_34))[(0) as usize]), ) }); i = 0; result = (match ( { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_29)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_29)) + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_35)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_35)) [(i.postfix_inc()) as usize][(0) as usize]) as usize][(0) as usize]), ) { - (__tmp_118, __tmp_119) => { - (*__tmp_119) = (((*__tmp_119) as u32).wrapping_add((__tmp_118 as u32))) as u32; - (*__tmp_119).clone() + (__tmp_140, __tmp_141) => { + (*__tmp_141) = (((*__tmp_141) as u32).wrapping_add((__tmp_140 as u32))) as u32; + (*__tmp_141).clone() } }); (unsafe { @@ -1637,9 +1846,9 @@ unsafe fn main_0() -> i32 { c"nested array %d %u %u %u\n".as_ptr() as *const libc::c_char, (i), (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_29))[(0) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_35))[(0) as usize] [(0) as usize]), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_29))[(1) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_35))[(1) as usize] [(0) as usize]), ) }); @@ -1647,24 +1856,24 @@ unsafe fn main_0() -> i32 { } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Index_35 { +pub struct Index_41 { pub value: i32, } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Owner_36 { +pub struct Owner_42 { pub values: [i32; 2], pub index: i32, } pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const global_5); - std::cell::LazyCell::force(&*&raw const global_record_8); - std::cell::LazyCell::force(&*&raw const targets_10); - std::cell::LazyCell::force(&*&raw const cursor_11); - std::cell::LazyCell::force(&*&raw const selected_values_17); - std::cell::LazyCell::force(&*&raw const initializer_target_20); - std::cell::LazyCell::force(&*&raw const initializer_result_22); - std::cell::LazyCell::force(&*&raw const global_array_28); - std::cell::LazyCell::force(&*&raw const global_rows_29); - std::cell::LazyCell::force(&*&raw const global_members_30); + std::cell::LazyCell::force(&*&raw const global_11); + std::cell::LazyCell::force(&*&raw const global_record_14); + std::cell::LazyCell::force(&*&raw const targets_16); + std::cell::LazyCell::force(&*&raw const cursor_17); + std::cell::LazyCell::force(&*&raw const selected_values_23); + std::cell::LazyCell::force(&*&raw const initializer_target_26); + std::cell::LazyCell::force(&*&raw const initializer_result_28); + std::cell::LazyCell::force(&*&raw const global_array_34); + std::cell::LazyCell::force(&*&raw const global_rows_35); + std::cell::LazyCell::force(&*&raw const global_members_36); } From 2acd7820a0f9df26e7db5ab5b458a71fc6ff01d2 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Sat, 28 Nov 2026 17:12:04 +0000 Subject: [PATCH 15/25] Preserve referenced target chains and captured assignment ordering Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 15 +- .../converter/models/converter_refcount.cpp | 14 +- tests/unit/assignment_single_eval.cpp | 29 + .../out/refcount/assignment_single_eval.rs | 701 +++++++++++------- .../unit/out/unsafe/assignment_single_eval.rs | 607 +++++++++------ 5 files changed, 844 insertions(+), 522 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 689113109f..3b8e7c20b6 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -5079,10 +5079,14 @@ bool Converter::NeedsAssignmentBinding( const clang::Expr *lhs, const clang::Expr *rhs, const clang::CompoundAssignOperator *compound) { const auto *target = lhs->IgnoreParenImpCasts(); - if (const auto *member = clang::dyn_cast(target); - member && member->getMemberDecl()->getType()->isReferenceType()) { - // The referenced storage can also hold a value used to select the member. - return true; + for (const auto *part = target; part;) { + if (const auto *member = clang::dyn_cast(part); + member && member->getMemberDecl()->getType()->isReferenceType()) { + // Referenced storage can also hold a value used to select the target. + return true; + } + const auto *object = GetEnclosingObject(part); + part = object ? object->IgnoreParenImpCasts() : nullptr; } const auto *ref = clang::dyn_cast(target); const auto *var = @@ -5115,7 +5119,8 @@ bool Converter::NeedsAssignmentBinding( return false; } if (!(var->isLocalVarDecl() || clang::isa(var)) || - IsGlobalVar(var) || !curr_function_) { + IsGlobalVar(var) || !curr_function_ || + var->getDeclContext() != curr_function_) { return true; } auto refers_to_var = [&](auto &&self, const clang::Stmt *stmt) -> bool { diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 196393fdee..31bc594ffe 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -2536,10 +2536,16 @@ void ConverterRefCount::ConvertAssignment( // after the right operand, keeping its temporaries alive through the write. StrCat("match ({ ", rhs_value, " }, "); bool through_pointer = !pending_deref_.empty(); - const auto *member = - clang::dyn_cast(lhs->IgnoreParenImpCasts()); - if (through_pointer && member && - member->getMemberDecl()->getType()->isReferenceType()) { + bool through_reference_member = false; + for (const auto *part = lhs->IgnoreParenImpCasts(); part;) { + if (const auto *member = clang::dyn_cast(part)) { + through_reference_member |= + member->getMemberDecl()->getType()->isReferenceType(); + } + const auto *object = GetEnclosingObject(part); + part = object ? object->IgnoreParenImpCasts() : nullptr; + } + if (through_pointer && through_reference_member) { // Keep the referenced place, but end borrows used to select its owner. StrCat("{ let ", left, token::kAssign); { diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index 29c14b775b..acd839b7eb 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -90,6 +90,32 @@ void test_reference_pointer() { std::printf("reference pointer %d %d\n", p == &second, result == &second); } +template void test_reference_subfields() { + struct Index { + T value; + }; + struct Slot { + Index &ref; + }; + Index index{0}, other{77}; + Slot a[2] = {{index}, {other}}; + T result = (a[index.value].ref.value += 1); + std::printf("reference subfield compound %d %d %d\n", int(result), + int(index.value), int(other.value)); + index.value = 0; + result = (a[index.value].ref.value = 1); + std::printf("reference subfield simple %d %d %d\n", int(result), + int(index.value), int(other.value)); +} + +void test_captured_alias() { + short x = 10; + short *p = &x; + auto f = [&]() { return (x += (*p = -1, 0.5)); }; + int result = f(); + std::printf("captured outer alias %d %d\n", result, int(x)); +} + int global = 10; int observe_global(int assigned) { return assigned + global; } int observe(int assigned, const int *stored) { return assigned + *stored; } @@ -301,6 +327,9 @@ int main() { test_reference_members(); test_reference_members(); test_reference_pointer(); + test_reference_subfields(); + test_reference_subfields(); + test_captured_alias(); test(); test(); test(); diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 0c0abb00f9..fb23b7cb79 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -808,13 +808,167 @@ pub struct Node_10 { #[byte_size(8)] pub link: Ptr>, } +pub fn test_reference_subfields_11() { + let index: Value = Rc::new(RefCell::new(Index_12 { value: 0_u32 })); + let other: Value = Rc::new(RefCell::new(Index_12 { value: 77_u32 })); + let mut a: [Slot_13; 2] = [ + Slot_13 { + ref_: index.as_pointer(), + }, + Slot_13 { + ref_: other.as_pointer(), + }, + ]; + let mut result: u32 = ({ + match ({ 1_u32 }, { + let __tmp_79 = (field!(a[({ (*index.borrow()).value }) as usize].ref_, value)).clone(); + __tmp_79 + }) { + (__tmp_78, __tmp_79) => __tmp_79.with_mut(|__tmp_79| { + (*__tmp_79) = (((*__tmp_79) as u32).wrapping_add((__tmp_78 as u32))) as u32; + (*__tmp_79).clone() + }), + } + }); + printf!( + b"reference subfield compound %d %d %d\n", + (result as i32), + ({ (*index.borrow()).value } as i32), + ({ (*other.borrow()).value } as i32) + ); + (*index.borrow_mut()).value = 0_u32; + result = ({ + match ({ 1_u32 }, { + let __tmp_81 = (field!(a[({ (*index.borrow()).value }) as usize].ref_, value)).clone(); + __tmp_81 + }) { + (__tmp_80, __tmp_81) => __tmp_81.with_mut(|__tmp_81| { + (*__tmp_81) = __tmp_80; + (*__tmp_81).clone() + }), + } + }); + printf!( + b"reference subfield simple %d %d %d\n", + (result as i32), + ({ (*index.borrow()).value } as i32), + ({ (*other.borrow()).value } as i32) + ); +} +pub fn test_reference_subfields_14() { + let index: Value = Rc::new(RefCell::new(Index_15 { value: 0_i16 })); + let other: Value = Rc::new(RefCell::new(Index_15 { value: 77_i16 })); + let mut a: [Slot_16; 2] = [ + Slot_16 { + ref_: index.as_pointer(), + }, + Slot_16 { + ref_: other.as_pointer(), + }, + ]; + let mut result: i16 = ({ + match ({ 1 }, { + let __tmp_83 = (field!(a[({ (*index.borrow()).value }) as usize].ref_, value)).clone(); + __tmp_83 + }) { + (__tmp_82, __tmp_83) => __tmp_83.with_mut(|__tmp_83| { + (*__tmp_83) = (((*__tmp_83) as i32) + (__tmp_82 as i32)) as i16; + (*__tmp_83).clone() + }), + } + }); + printf!( + b"reference subfield compound %d %d %d\n", + (result as i32), + ({ (*index.borrow()).value } as i32), + ({ (*other.borrow()).value } as i32) + ); + (*index.borrow_mut()).value = 0_i16; + result = ({ + match ({ 1_i16 }, { + let __tmp_85 = (field!(a[({ (*index.borrow()).value }) as usize].ref_, value)).clone(); + __tmp_85 + }) { + (__tmp_84, __tmp_85) => __tmp_85.with_mut(|__tmp_85| { + (*__tmp_85) = __tmp_84; + (*__tmp_85).clone() + }), + } + }); + printf!( + b"reference subfield simple %d %d %d\n", + (result as i32), + ({ (*index.borrow()).value } as i32), + ({ (*other.borrow()).value } as i32) + ); +} +#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(4)] +pub struct Index_12 { + #[offset(0)] + pub value: u32, +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct Slot_13 { + #[offset(0)] + #[byte_size(8)] + pub ref_: Ptr, +} +#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(2)] +pub struct Index_15 { + #[offset(0)] + pub value: i16, +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct Slot_16 { + #[offset(0)] + #[byte_size(8)] + pub ref_: Ptr, +} +pub fn test_captured_alias_17() { + let x: Value = Rc::new(RefCell::new(10_i16)); + let p: Value> = Rc::new(RefCell::new((x.as_pointer()))); + let f: Value i16>> = Rc::new(RefCell::new(lambda!( + { + let x: Ptr = x.as_pointer(); + let p: Ptr> = p.as_pointer(); + }, + || -> i16 { + return ({ + match ( + { + { + (p.read()).write((-1_i32 as i16)); + 0.5_f64 + } + }, + &(x), + ) { + (__tmp_86, __tmp_87) => __tmp_87.with_mut(|__tmp_87| { + (*__tmp_87) = (((*__tmp_87) as f64) + (__tmp_86 as f64)) as i16; + (*__tmp_87).clone() + }), + } + }); + } + ))); + let mut result: i32 = (({ (*f.borrow()).call() }) as i32); + printf!( + b"captured outer alias %d %d\n", + result, + ((*x.borrow()) as i32) + ); +} thread_local!( - pub static global_11: Value = Rc::new(RefCell::new(10)); + pub static global_18: Value = Rc::new(RefCell::new(10)); ); -pub fn observe_global_12(mut assigned: i32) -> i32 { - return (assigned + global_11.with(|rc| *rc.borrow())); +pub fn observe_global_19(mut assigned: i32) -> i32 { + return (assigned + global_18.with(|rc| *rc.borrow())); } -pub fn observe_13(mut assigned: i32, mut stored: Ptr) -> i32 { +pub fn observe_20(mut assigned: i32, mut stored: Ptr) -> i32 { return ({ assigned } + { (stored.read()) }); } #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] @@ -831,63 +985,63 @@ pub struct GlobalRecord { pub inner: GlobalRecord_Inner, } thread_local!( - pub static global_record_14: Value = Rc::new(RefCell::new(GlobalRecord { + pub static global_record_21: Value = Rc::new(RefCell::new(GlobalRecord { inner: GlobalRecord_Inner { value: 10 }, })); ); -pub fn observe_record_15(mut assigned: i32) -> i32 { - return (assigned + { global_record_14.with(|rc| *rc.borrow()).inner.value }); +pub fn observe_record_22(mut assigned: i32) -> i32 { + return (assigned + { global_record_21.with(|rc| *rc.borrow()).inner.value }); } thread_local!( - pub static targets_16: Value> = Rc::new(RefCell::new(Box::new([10, 20]))); + pub static targets_23: Value> = Rc::new(RefCell::new(Box::new([10, 20]))); ); thread_local!( - pub static cursor_17: Value> = Rc::new(RefCell::new(targets_16.with(|v| v.decay()))); + pub static cursor_24: Value> = Rc::new(RefCell::new(targets_23.with(|v| v.decay()))); ); -pub fn test_borrows_18() { +pub fn test_borrows_25() { printf!( b"%d\n", ({ - observe_global_12({ - global_11.with(|rc| *rc.borrow_mut() = 99); - global_11.with(|rc| *rc.borrow()) + observe_global_19({ + global_18.with(|rc| *rc.borrow_mut() = 99); + global_18.with(|rc| *rc.borrow()) }) }) ); printf!( b"%d\n", ({ - observe_global_12({ - global_11.with(|rc| *rc.borrow_mut() += 5); - global_11.with(|rc| *rc.borrow()) + observe_global_19({ + global_18.with(|rc| *rc.borrow_mut() += 5); + global_18.with(|rc| *rc.borrow()) }) }) ); printf!( b"%d\n", ({ - observe_global_12({ - let __rhs = ({ observe_13(0, (global_11.with(|v| v.as_pointer()))) }); - global_11.with(|rc| *rc.borrow_mut() = __rhs); - global_11.with(|rc| *rc.borrow()) + observe_global_19({ + let __rhs = ({ observe_20(0, (global_18.with(|v| v.as_pointer()))) }); + global_18.with(|rc| *rc.borrow_mut() = __rhs); + global_18.with(|rc| *rc.borrow()) }) }) ); let mut assigned: i32 = (({ - let __tmp_78 = { - promoted_19.with(|rc| *rc.borrow_mut() = (-1_i32 as i16)); + let __tmp_88 = { + promoted_26.with(|rc| *rc.borrow_mut() = (-1_i32 as i16)); 0.5_f64 }; { - let rhs_0 = ((promoted_19.with(|rc| *rc.borrow()) as f64) + (__tmp_78 as f64)) as i16; - promoted_19.with(|rc| *rc.borrow_mut() = rhs_0); - promoted_19.with(|rc| *rc.borrow()) + let rhs_0 = ((promoted_26.with(|rc| *rc.borrow()) as f64) + (__tmp_88 as f64)) as i16; + promoted_26.with(|rc| *rc.borrow_mut() = rhs_0); + promoted_26.with(|rc| *rc.borrow()) } }) as i32); printf!( b"%d %d\n", assigned, - (promoted_19.with(|rc| *rc.borrow()) as i32) + (promoted_26.with(|rc| *rc.borrow()) as i32) ); let aliased: Value = Rc::new(RefCell::new(10_i16)); let mut alias: Ptr = (aliased.as_pointer()); @@ -901,55 +1055,55 @@ pub fn test_borrows_18() { }, &mut (*aliased.borrow_mut()), ) { - (__tmp_79, __tmp_80) => { - (*__tmp_80) = (((*__tmp_80) as f64) + (__tmp_79 as f64)) as i16; - (*__tmp_80).clone() + (__tmp_89, __tmp_90) => { + (*__tmp_90) = (((*__tmp_90) as f64) + (__tmp_89 as f64)) as i16; + (*__tmp_90).clone() } } }) as i32); printf!(b"%d %d\n", assigned, ((*aliased.borrow()) as i32)); let mut enabled: bool = ({ - let __tmp_81 = { - ({ observe_13(0, (global_11.with(|v| v.as_pointer()))) }); + let __tmp_91 = { + ({ observe_20(0, (global_18.with(|v| v.as_pointer()))) }); 0.5_f64 }; { - let rhs_0 = ((flag_20.with(|rc| *rc.borrow()) as u8 as f64) + (__tmp_81 as f64)) != 0.0; - flag_20.with(|rc| *rc.borrow_mut() = rhs_0); - flag_20.with(|rc| *rc.borrow()) + let rhs_0 = ((flag_27.with(|rc| *rc.borrow()) as u8 as f64) + (__tmp_91 as f64)) != 0.0; + flag_27.with(|rc| *rc.borrow_mut() = rhs_0); + flag_27.with(|rc| *rc.borrow()) } }); printf!( b"%d %d\n", (enabled as i32), - (flag_20.with(|rc| *rc.borrow()) as i32) + (flag_27.with(|rc| *rc.borrow()) as i32) ); printf!( b"%d\n", ({ - observe_record_15({ - (*global_record_14.with(Value::clone).borrow_mut()) + observe_record_22({ + (*global_record_21.with(Value::clone).borrow_mut()) .inner .value = 99; - { global_record_14.with(|rc| *rc.borrow()).inner.value } + { global_record_21.with(|rc| *rc.borrow()).inner.value } }) }) ); let mut shifted: Ptr = ({ - let __tmp_82 = { - cursor_17 - .with(|rc| *rc.borrow_mut() = targets_16.with(|v| v.decay()).offset((1) as isize)); + let __tmp_92 = { + cursor_24 + .with(|rc| *rc.borrow_mut() = targets_23.with(|v| v.decay()).offset((1) as isize)); 1 }; - cursor_17.with(|rc| *rc.borrow_mut() -= (__tmp_82 as isize)); - (*cursor_17.with(Value::clone).borrow()).clone() + cursor_24.with(|rc| *rc.borrow_mut() -= (__tmp_92 as isize)); + (*cursor_24.with(Value::clone).borrow()).clone() }); printf!( b"%d %d\n", - (({ (*cursor_17.with(Value::clone).borrow()).clone() } == { - targets_16.with(|v| v.decay()) + (({ (*cursor_24.with(Value::clone).borrow()).clone() } == { + targets_23.with(|v| v.decay()) }) as i32), - (({ (shifted).clone() } == { (*cursor_17.with(Value::clone).borrow()).clone() }) as i32) + (({ (shifted).clone() } == { (*cursor_24.with(Value::clone).borrow()).clone() }) as i32) ); let local: Value = Rc::new(RefCell::new(10)); printf!( @@ -960,7 +1114,7 @@ pub fn test_borrows_18() { (*local.borrow()) }; let _stored: Ptr = (local.as_pointer()); - observe_13(_assigned, _stored) + observe_20(_assigned, _stored) }) ); printf!( @@ -971,10 +1125,10 @@ pub fn test_borrows_18() { (*local.borrow()) }; let _stored: Ptr = (local.as_pointer()); - observe_13(_assigned, _stored) + observe_20(_assigned, _stored) }) ); - let record: Value = Rc::new(RefCell::new(Record_21 { value: 10 })); + let record: Value = Rc::new(RefCell::new(Record_28 { value: 10 })); printf!( b"%d\n", ({ @@ -983,7 +1137,7 @@ pub fn test_borrows_18() { { (*record.borrow()).value } }; let _stored: Ptr = (field_ptr!(record.as_pointer(), value)); - observe_13(_assigned, _stored) + observe_20(_assigned, _stored) }) ); printf!( @@ -994,25 +1148,25 @@ pub fn test_borrows_18() { { (*record.borrow()).value } }; let _stored: Ptr = (field_ptr!(record.as_pointer(), value)); - observe_13(_assigned, _stored) + observe_20(_assigned, _stored) }) ); - let first: Value = >::default(); - *first.borrow_mut() = Link_22 { + let first: Value = >::default(); + *first.borrow_mut() = Link_29 { next: (first.as_pointer()), }; - let second: Value = Rc::new(RefCell::new(Link_22 { + let second: Value = Rc::new(RefCell::new(Link_29 { next: (first.as_pointer()), })); - let selector: Ptr> = field_ptr!(first.as_pointer(), next); - let mut selected: Ptr = ({ + let selector: Ptr> = field_ptr!(first.as_pointer(), next); + let mut selected: Ptr = ({ match ( { (second.as_pointer()) }, &(field!((selector.read()), next)), ) { - (__tmp_83, __tmp_84) => __tmp_84.with_mut(|__tmp_84| { - (*__tmp_84) = __tmp_83; - (*__tmp_84).clone() + (__tmp_93, __tmp_94) => __tmp_94.with_mut(|__tmp_94| { + (*__tmp_94) = __tmp_93; + (*__tmp_94).clone() }), } }); @@ -1030,7 +1184,7 @@ pub fn test_borrows_18() { { (*values.borrow())[0_usize] } }; let _stored: Ptr = (values.decay().offset(0_usize)); - observe_13(_assigned, _stored) + observe_20(_assigned, _stored) }) ); printf!( @@ -1041,45 +1195,45 @@ pub fn test_borrows_18() { { (*values.borrow())[0_usize] } }; let _stored: Ptr = (values.decay().offset(0_usize)); - observe_13(_assigned, _stored) + observe_20(_assigned, _stored) }) ); } thread_local!( - static promoted_19: Value = Rc::new(RefCell::new(10_i16)); + static promoted_26: Value = Rc::new(RefCell::new(10_i16)); ); thread_local!( - static flag_20: Value = Rc::new(RefCell::new(false)); + static flag_27: Value = Rc::new(RefCell::new(false)); ); #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(4)] -pub struct Record_21 { +pub struct Record_28 { #[offset(0)] pub value: i32, } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(8)] -pub struct Link_22 { +pub struct Link_29 { #[offset(0)] #[byte_size(8)] - pub next: Ptr, + pub next: Ptr, } thread_local!( - pub static selected_values_23: Value> = + pub static selected_values_30: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); ); #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct IndexedBinding {} -pub fn test_binding_24() { +pub fn test_binding_31() { let owner: Value = Rc::new(RefCell::new(::default())); - let __decomp_25: Ptr = owner.as_pointer(); - let value: Ptr = ({ IndexedBindingImpl::get_1_0(&__decomp_25) }); + let __decomp_32: Ptr = owner.as_pointer(); + let value: Ptr = ({ IndexedBindingImpl::get_1_0(&__decomp_32) }); let mut result: u32 = ({ - match ({ 1_u32 }, &({ IndexedBindingImpl::get_1_0(&__decomp_25) })) { - (__tmp_85, __tmp_86) => __tmp_86.with_mut(|__tmp_86| { - (*__tmp_86) = (((*__tmp_86) as u32).wrapping_add((__tmp_85 as u32))) as u32; - (*__tmp_86).clone() + match ({ 1_u32 }, &({ IndexedBindingImpl::get_1_0(&__decomp_32) })) { + (__tmp_95, __tmp_96) => __tmp_96.with_mut(|__tmp_96| { + (*__tmp_96) = (((*__tmp_96) as u32).wrapping_add((__tmp_95 as u32))) as u32; + (*__tmp_96).clone() }), } }); @@ -1088,34 +1242,34 @@ pub fn test_binding_24() { result, ({ let __idx0 = (0) as usize; - selected_values_23.with(|rc| rc.borrow()[__idx0]) + selected_values_30.with(|rc| rc.borrow()[__idx0]) }) ); } thread_local!( - pub static initializer_target_26: Value = Rc::new(RefCell::new(10_u32)); + pub static initializer_target_33: Value = Rc::new(RefCell::new(10_u32)); ); -pub fn mutate_initializer_27() -> u32 { - initializer_target_26.with(|rc| *rc.borrow_mut() = 20_u32); +pub fn mutate_initializer_34() -> u32 { + initializer_target_33.with(|rc| *rc.borrow_mut() = 20_u32); return 1_u32; } thread_local!( - pub static initializer_result_28: Value = Rc::new(RefCell::new( + pub static initializer_result_35: Value = Rc::new(RefCell::new( ({ - let __tmp_87 = ({ mutate_initializer_27() }); + let __tmp_97 = ({ mutate_initializer_34() }); { - let rhs_0 = ((initializer_target_26.with(|rc| *rc.borrow()) as u32) - .wrapping_add((__tmp_87 as u32))) as u32; + let rhs_0 = ((initializer_target_33.with(|rc| *rc.borrow()) as u32) + .wrapping_add((__tmp_97 as u32))) as u32; { let __rhs = rhs_0; - initializer_target_26.with(|rc| *rc.borrow_mut() = __rhs) + initializer_target_33.with(|rc| *rc.borrow_mut() = __rhs) }; - initializer_target_26.with(|rc| *rc.borrow()) + initializer_target_33.with(|rc| *rc.borrow()) } }), )); ); -pub fn test_alias_scopes_29(parameter: i16) { +pub fn test_alias_scopes_36(parameter: i16) { let parameter: Value = Rc::new(RefCell::new(parameter)); let mut p: Ptr = (parameter.as_pointer()); let mut result: i16 = ({ @@ -1128,9 +1282,9 @@ pub fn test_alias_scopes_29(parameter: i16) { }, &mut (*parameter.borrow_mut()), ) { - (__tmp_88, __tmp_89) => { - (*__tmp_89) = (((*__tmp_89) as f64) + (__tmp_88 as f64)) as i16; - (*__tmp_89).clone() + (__tmp_98, __tmp_99) => { + (*__tmp_99) = (((*__tmp_99) as f64) + (__tmp_98 as f64)) as i16; + (*__tmp_99).clone() } } }); @@ -1154,9 +1308,9 @@ pub fn test_alias_scopes_29(parameter: i16) { { ({ (*mutate.borrow()).call() }).clone() }, &mut (*local.borrow_mut()), ) { - (__tmp_90, __tmp_91) => { - (*__tmp_91) = (((*__tmp_91) as f64) + (__tmp_90 as f64)) as i16; - (*__tmp_91).clone() + (__tmp_100, __tmp_101) => { + (*__tmp_101) = (((*__tmp_101) as f64) + (__tmp_100 as f64)) as i16; + (*__tmp_101).clone() } } }); @@ -1167,22 +1321,22 @@ pub fn test_alias_scopes_29(parameter: i16) { ); printf!( b"initializer %u %u\n", - initializer_result_28.with(|rc| *rc.borrow()), - initializer_target_26.with(|rc| *rc.borrow()) + initializer_result_35.with(|rc| *rc.borrow()), + initializer_target_33.with(|rc| *rc.borrow()) ); } -pub fn test_boxed_array_30() { +pub fn test_boxed_array_37() { let a: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); let mut p: Ptr = a.decay(); let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_93 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_93 + let __tmp_103 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_103 }) { - (__tmp_92, __tmp_93) => __tmp_93.with_mut(|__tmp_93| { - (*__tmp_93) = (((*__tmp_93) as u32).wrapping_add((__tmp_92 as u32))) as u32; - (*__tmp_93).clone() + (__tmp_102, __tmp_103) => __tmp_103.with_mut(|__tmp_103| { + (*__tmp_103) = (((*__tmp_103) as u32).wrapping_add((__tmp_102 as u32))) as u32; + (*__tmp_103).clone() }), } }); @@ -1197,12 +1351,12 @@ pub fn test_boxed_array_30() { i = 0; result = ({ match ({ 1_u32 }, { - let __tmp_95 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_95 + let __tmp_105 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_105 }) { - (__tmp_94, __tmp_95) => __tmp_95.with_mut(|__tmp_95| { - (*__tmp_95) = __tmp_94; - (*__tmp_95).clone() + (__tmp_104, __tmp_105) => __tmp_105.with_mut(|__tmp_105| { + (*__tmp_105) = __tmp_104; + (*__tmp_105).clone() }), } }); @@ -1215,17 +1369,17 @@ pub fn test_boxed_array_30() { ); result = ({ match ({ 1_u32 }, { - let __tmp_97 = saved_31.with(|v| v.decay()).offset( + let __tmp_107 = saved_38.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; - saved_31.with(|rc| rc.borrow()[__idx0]) + saved_38.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_97 + __tmp_107 }) { - (__tmp_96, __tmp_97) => __tmp_97.with_mut(|__tmp_97| { - (*__tmp_97) = (((*__tmp_97) as u32).wrapping_add((__tmp_96 as u32))) as u32; - (*__tmp_97).clone() + (__tmp_106, __tmp_107) => __tmp_107.with_mut(|__tmp_107| { + (*__tmp_107) = (((*__tmp_107) as u32).wrapping_add((__tmp_106 as u32))) as u32; + (*__tmp_107).clone() }), } }); @@ -1234,22 +1388,22 @@ pub fn test_boxed_array_30() { (result as i32), (({ let __idx0 = (0) as usize; - saved_31.with(|rc| rc.borrow()[__idx0]) + saved_38.with(|rc| rc.borrow()[__idx0]) }) as i32) ); } -pub fn test_boxed_array_32() { +pub fn test_boxed_array_39() { let a: Value> = Rc::new(RefCell::new(Box::new([0_i16, 20_i16, 30_i16]))); let mut p: Ptr = a.decay(); let mut i: i32 = 0; let mut result: i16 = ({ match ({ 1 }, { - let __tmp_99 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_99 + let __tmp_109 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_109 }) { - (__tmp_98, __tmp_99) => __tmp_99.with_mut(|__tmp_99| { - (*__tmp_99) = (((*__tmp_99) as i32) + (__tmp_98 as i32)) as i16; - (*__tmp_99).clone() + (__tmp_108, __tmp_109) => __tmp_109.with_mut(|__tmp_109| { + (*__tmp_109) = (((*__tmp_109) as i32) + (__tmp_108 as i32)) as i16; + (*__tmp_109).clone() }), } }); @@ -1264,12 +1418,12 @@ pub fn test_boxed_array_32() { i = 0; result = ({ match ({ 1_i16 }, { - let __tmp_101 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_101 + let __tmp_111 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_111 }) { - (__tmp_100, __tmp_101) => __tmp_101.with_mut(|__tmp_101| { - (*__tmp_101) = __tmp_100; - (*__tmp_101).clone() + (__tmp_110, __tmp_111) => __tmp_111.with_mut(|__tmp_111| { + (*__tmp_111) = __tmp_110; + (*__tmp_111).clone() }), } }); @@ -1282,17 +1436,17 @@ pub fn test_boxed_array_32() { ); result = ({ match ({ 1 }, { - let __tmp_103 = saved_33.with(|v| v.decay()).offset( + let __tmp_113 = saved_40.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; - saved_33.with(|rc| rc.borrow()[__idx0]) + saved_40.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_103 + __tmp_113 }) { - (__tmp_102, __tmp_103) => __tmp_103.with_mut(|__tmp_103| { - (*__tmp_103) = (((*__tmp_103) as i32) + (__tmp_102 as i32)) as i16; - (*__tmp_103).clone() + (__tmp_112, __tmp_113) => __tmp_113.with_mut(|__tmp_113| { + (*__tmp_113) = (((*__tmp_113) as i32) + (__tmp_112 as i32)) as i16; + (*__tmp_113).clone() }), } }); @@ -1301,22 +1455,22 @@ pub fn test_boxed_array_32() { (result as i32), (({ let __idx0 = (0) as usize; - saved_33.with(|rc| rc.borrow()[__idx0]) + saved_40.with(|rc| rc.borrow()[__idx0]) }) as i32) ); } thread_local!( - static saved_31: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); + static saved_38: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); ); thread_local!( - static saved_33: Value> = Rc::new(RefCell::new(Box::new([0_i16, 20_i16, 30_i16]))); + static saved_40: Value> = Rc::new(RefCell::new(Box::new([0_i16, 20_i16, 30_i16]))); ); thread_local!( - pub static global_array_34: Value> = + pub static global_array_41: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); ); thread_local!( - pub static global_rows_35: Value]>> = Rc::new(RefCell::new(Box::new([ + pub static global_rows_42: Value]>> = Rc::new(RefCell::new(Box::new([ Box::new([0_u32, 10_u32]), Box::new([20_u32, 30_u32]), ]))); @@ -1332,7 +1486,7 @@ pub struct IndexedMember { pub promoted: i16, } thread_local!( - pub static global_members_36: Value> = Rc::new(RefCell::new(Box::new([ + pub static global_members_43: Value> = Rc::new(RefCell::new(Box::new([ IndexedMember { key: 0, value: 10_u32, @@ -1345,7 +1499,7 @@ thread_local!( }, ]))); ); -pub fn test_local_members_37() { +pub fn test_local_members_44() { let a: Value> = Rc::new(RefCell::new(Box::new([ IndexedMember { key: 0, @@ -1362,16 +1516,16 @@ pub fn test_local_members_37() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_105 = field_ptr!( + let __tmp_115 = field_ptr!( a.decay() .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), value ); - __tmp_105 + __tmp_115 }) { - (__tmp_104, __tmp_105) => __tmp_105.with_mut(|__tmp_105| { - (*__tmp_105) = (((*__tmp_105) as u32).wrapping_add((__tmp_104 as u32))) as u32; - (*__tmp_105).clone() + (__tmp_114, __tmp_115) => __tmp_115.with_mut(|__tmp_115| { + (*__tmp_115) = (((*__tmp_115) as u32).wrapping_add((__tmp_114 as u32))) as u32; + (*__tmp_115).clone() }), } }); @@ -1385,15 +1539,15 @@ pub fn test_local_members_37() { i = 0; { match ({ 1 }, { - let __tmp_107 = field_ptr!( + let __tmp_117 = field_ptr!( a.decay() .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), promoted ); - __tmp_107 + __tmp_117 }) { - (__tmp_106, __tmp_107) => __tmp_107.with_mut(|__tmp_107| { - (*__tmp_107) = (((*__tmp_107) as i32) + (__tmp_106 as i32)) as i16; + (__tmp_116, __tmp_117) => __tmp_117.with_mut(|__tmp_117| { + (*__tmp_117) = (((*__tmp_117) as i32) + (__tmp_116 as i32)) as i16; }), } }; @@ -1406,16 +1560,16 @@ pub fn test_local_members_37() { i = 0; result = ({ match ({ 99_u32 }, { - let __tmp_109 = field_ptr!( + let __tmp_119 = field_ptr!( a.decay() .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), value ); - __tmp_109 + __tmp_119 }) { - (__tmp_108, __tmp_109) => __tmp_109.with_mut(|__tmp_109| { - (*__tmp_109) = __tmp_108; - (*__tmp_109).clone() + (__tmp_118, __tmp_119) => __tmp_119.with_mut(|__tmp_119| { + (*__tmp_119) = __tmp_118; + (*__tmp_119).clone() }), } }); @@ -1428,25 +1582,25 @@ pub fn test_local_members_37() { ); printf!(b"member alias %u\n", p.with(|__s| __s.value)); } -pub fn test_global_members_38() { +pub fn test_global_members_45() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_111 = field_ptr!( - global_members_36.with(|v| v.decay()).offset({ + let __tmp_121 = field_ptr!( + global_members_43.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - global_members_36.with(|rc| rc.borrow()[__idx0]) + global_members_43.with(|rc| rc.borrow()[__idx0]) }) .key }), value ); - __tmp_111 + __tmp_121 }) { - (__tmp_110, __tmp_111) => __tmp_111.with_mut(|__tmp_111| { - (*__tmp_111) = (((*__tmp_111) as u32).wrapping_add((__tmp_110 as u32))) as u32; - (*__tmp_111).clone() + (__tmp_120, __tmp_121) => __tmp_121.with_mut(|__tmp_121| { + (*__tmp_121) = (((*__tmp_121) as u32).wrapping_add((__tmp_120 as u32))) as u32; + (*__tmp_121).clone() }), } }); @@ -1457,14 +1611,14 @@ pub fn test_global_members_38() { { ({ let __idx0 = (0) as usize; - global_members_36.with(|rc| rc.borrow()[__idx0]) + global_members_43.with(|rc| rc.borrow()[__idx0]) }) .value }, { ({ let __idx0 = (1) as usize; - global_members_36.with(|rc| rc.borrow()[__idx0]) + global_members_43.with(|rc| rc.borrow()[__idx0]) }) .value } @@ -1472,20 +1626,20 @@ pub fn test_global_members_38() { i = 0; { match ({ 1 }, { - let __tmp_113 = field_ptr!( - global_members_36.with(|v| v.decay()).offset({ + let __tmp_123 = field_ptr!( + global_members_43.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - global_members_36.with(|rc| rc.borrow()[__idx0]) + global_members_43.with(|rc| rc.borrow()[__idx0]) }) .key }), promoted ); - __tmp_113 + __tmp_123 }) { - (__tmp_112, __tmp_113) => __tmp_113.with_mut(|__tmp_113| { - (*__tmp_113) = (((*__tmp_113) as i32) + (__tmp_112 as i32)) as i16; + (__tmp_122, __tmp_123) => __tmp_123.with_mut(|__tmp_123| { + (*__tmp_123) = (((*__tmp_123) as i32) + (__tmp_122 as i32)) as i16; }), } }; @@ -1495,14 +1649,14 @@ pub fn test_global_members_38() { ({ ({ let __idx0 = (0) as usize; - global_members_36.with(|rc| rc.borrow()[__idx0]) + global_members_43.with(|rc| rc.borrow()[__idx0]) }) .promoted } as i32), ({ ({ let __idx0 = (1) as usize; - global_members_36.with(|rc| rc.borrow()[__idx0]) + global_members_43.with(|rc| rc.borrow()[__idx0]) }) .promoted } as i32) @@ -1510,21 +1664,21 @@ pub fn test_global_members_38() { i = 0; result = ({ match ({ 99_u32 }, { - let __tmp_115 = field_ptr!( - global_members_36.with(|v| v.decay()).offset({ + let __tmp_125 = field_ptr!( + global_members_43.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - global_members_36.with(|rc| rc.borrow()[__idx0]) + global_members_43.with(|rc| rc.borrow()[__idx0]) }) .key }), value ); - __tmp_115 + __tmp_125 }) { - (__tmp_114, __tmp_115) => __tmp_115.with_mut(|__tmp_115| { - (*__tmp_115) = __tmp_114; - (*__tmp_115).clone() + (__tmp_124, __tmp_125) => __tmp_125.with_mut(|__tmp_125| { + (*__tmp_125) = __tmp_124; + (*__tmp_125).clone() }), } }); @@ -1535,38 +1689,38 @@ pub fn test_global_members_38() { { ({ let __idx0 = (0) as usize; - global_members_36.with(|rc| rc.borrow()[__idx0]) + global_members_43.with(|rc| rc.borrow()[__idx0]) }) .value }, { ({ let __idx0 = (1) as usize; - global_members_36.with(|rc| rc.borrow()[__idx0]) + global_members_43.with(|rc| rc.borrow()[__idx0]) }) .value } ); } -pub fn test_static_members_39() { +pub fn test_static_members_46() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_117 = field_ptr!( - a_40.with(|v| v.decay()).offset({ + let __tmp_127 = field_ptr!( + a_47.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - a_40.with(|rc| rc.borrow()[__idx0]) + a_47.with(|rc| rc.borrow()[__idx0]) }) .key }), value ); - __tmp_117 + __tmp_127 }) { - (__tmp_116, __tmp_117) => __tmp_117.with_mut(|__tmp_117| { - (*__tmp_117) = (((*__tmp_117) as u32).wrapping_add((__tmp_116 as u32))) as u32; - (*__tmp_117).clone() + (__tmp_126, __tmp_127) => __tmp_127.with_mut(|__tmp_127| { + (*__tmp_127) = (((*__tmp_127) as u32).wrapping_add((__tmp_126 as u32))) as u32; + (*__tmp_127).clone() }), } }); @@ -1577,14 +1731,14 @@ pub fn test_static_members_39() { { ({ let __idx0 = (0) as usize; - a_40.with(|rc| rc.borrow()[__idx0]) + a_47.with(|rc| rc.borrow()[__idx0]) }) .value }, { ({ let __idx0 = (1) as usize; - a_40.with(|rc| rc.borrow()[__idx0]) + a_47.with(|rc| rc.borrow()[__idx0]) }) .value } @@ -1592,20 +1746,20 @@ pub fn test_static_members_39() { i = 0; { match ({ 1 }, { - let __tmp_119 = field_ptr!( - a_40.with(|v| v.decay()).offset({ + let __tmp_129 = field_ptr!( + a_47.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - a_40.with(|rc| rc.borrow()[__idx0]) + a_47.with(|rc| rc.borrow()[__idx0]) }) .key }), promoted ); - __tmp_119 + __tmp_129 }) { - (__tmp_118, __tmp_119) => __tmp_119.with_mut(|__tmp_119| { - (*__tmp_119) = (((*__tmp_119) as i32) + (__tmp_118 as i32)) as i16; + (__tmp_128, __tmp_129) => __tmp_129.with_mut(|__tmp_129| { + (*__tmp_129) = (((*__tmp_129) as i32) + (__tmp_128 as i32)) as i16; }), } }; @@ -1615,14 +1769,14 @@ pub fn test_static_members_39() { ({ ({ let __idx0 = (0) as usize; - a_40.with(|rc| rc.borrow()[__idx0]) + a_47.with(|rc| rc.borrow()[__idx0]) }) .promoted } as i32), ({ ({ let __idx0 = (1) as usize; - a_40.with(|rc| rc.borrow()[__idx0]) + a_47.with(|rc| rc.borrow()[__idx0]) }) .promoted } as i32) @@ -1630,21 +1784,21 @@ pub fn test_static_members_39() { i = 0; result = ({ match ({ 99_u32 }, { - let __tmp_121 = field_ptr!( - a_40.with(|v| v.decay()).offset({ + let __tmp_131 = field_ptr!( + a_47.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; - a_40.with(|rc| rc.borrow()[__idx0]) + a_47.with(|rc| rc.borrow()[__idx0]) }) .key }), value ); - __tmp_121 + __tmp_131 }) { - (__tmp_120, __tmp_121) => __tmp_121.with_mut(|__tmp_121| { - (*__tmp_121) = __tmp_120; - (*__tmp_121).clone() + (__tmp_130, __tmp_131) => __tmp_131.with_mut(|__tmp_131| { + (*__tmp_131) = __tmp_130; + (*__tmp_131).clone() }), } }); @@ -1655,21 +1809,21 @@ pub fn test_static_members_39() { { ({ let __idx0 = (0) as usize; - a_40.with(|rc| rc.borrow()[__idx0]) + a_47.with(|rc| rc.borrow()[__idx0]) }) .value }, { ({ let __idx0 = (1) as usize; - a_40.with(|rc| rc.borrow()[__idx0]) + a_47.with(|rc| rc.borrow()[__idx0]) }) .value } ); } thread_local!( - static a_40: Value> = Rc::new(RefCell::new(Box::new([ + static a_47: Value> = Rc::new(RefCell::new(Box::new([ IndexedMember { key: 0, value: 10_u32, @@ -1710,7 +1864,7 @@ fn main_0() -> i32 { (*a.borrow())[(0) as usize], (*a.borrow())[(1) as usize] ); - let mut selector: Index_41 = Index_41 { value: 1 }; + let mut selector: Index_48 = Index_48 { value: 1 }; value = ({ (*a.borrow_mut())[(selector.value) as usize] = 88; (*a.borrow())[(selector.value) as usize] @@ -1731,12 +1885,12 @@ fn main_0() -> i32 { alias.write(0); let __rhs = ({ match ({ 1 }, { - let __tmp_123 = a.decay().offset((alias.read())); - __tmp_123 + let __tmp_133 = a.decay().offset((alias.read())); + __tmp_133 }) { - (__tmp_122, __tmp_123) => __tmp_123.with_mut(|__tmp_123| { - (*__tmp_123) = __tmp_122; - (*__tmp_123).clone() + (__tmp_132, __tmp_133) => __tmp_133.with_mut(|__tmp_133| { + (*__tmp_133) = __tmp_132; + (*__tmp_133).clone() }), } }); @@ -1792,7 +1946,7 @@ fn main_0() -> i32 { deref_value, (*a.borrow())[(1) as usize] ); - let mut owner: Owner_42 = Owner_42 { + let mut owner: Owner_49 = Owner_49 { values: Box::new([0, 20]), index: 0, }; @@ -1801,9 +1955,9 @@ fn main_0() -> i32 { { 1 }, &mut (owner.values[(owner.values[(0) as usize]) as usize]), ) { - (__tmp_124, __tmp_125) => { - (*__tmp_125) = __tmp_124; - (*__tmp_125).clone() + (__tmp_134, __tmp_135) => { + (*__tmp_135) = __tmp_134; + (*__tmp_135).clone() } } }); @@ -1818,16 +1972,16 @@ fn main_0() -> i32 { owner.values[(0) as usize], owner.values[(1) as usize] ); - let alias_selector: Value = Rc::new(RefCell::new(Index_41 { value: 0 })); + let alias_selector: Value = Rc::new(RefCell::new(Index_48 { value: 0 })); let mut member_alias: Ptr = (field_ptr!(alias_selector.as_pointer(), value)); let __rhs = ({ match ({ 1 }, { - let __tmp_127 = member_alias.offset(({ (*alias_selector.borrow()).value }) as isize); - __tmp_127 + let __tmp_137 = member_alias.offset(({ (*alias_selector.borrow()).value }) as isize); + __tmp_137 }) { - (__tmp_126, __tmp_127) => __tmp_127.with_mut(|__tmp_127| { - (*__tmp_127) = __tmp_126; - (*__tmp_127).clone() + (__tmp_136, __tmp_137) => __tmp_137.with_mut(|__tmp_137| { + (*__tmp_137) = __tmp_136; + (*__tmp_137).clone() }), } }); @@ -1839,12 +1993,12 @@ fn main_0() -> i32 { let mut self_: Ptr = (self_index.as_pointer()); let __rhs = ({ match ({ 1 }, { - let __tmp_129 = self_.offset((*self_index.borrow()) as isize); - __tmp_129 + let __tmp_139 = self_.offset((*self_index.borrow()) as isize); + __tmp_139 }) { - (__tmp_128, __tmp_129) => __tmp_129.with_mut(|__tmp_129| { - (*__tmp_129) = __tmp_128; - (*__tmp_129).clone() + (__tmp_138, __tmp_139) => __tmp_139.with_mut(|__tmp_139| { + (*__tmp_139) = __tmp_138; + (*__tmp_139).clone() }), } }); @@ -1860,13 +2014,13 @@ fn main_0() -> i32 { || -> i32 { return ({ match ({ 10000 }, { - let __tmp_131 = + let __tmp_141 = (captured_pointer.read()).offset((captured_index.read()) as isize); - __tmp_131 + __tmp_141 }) { - (__tmp_130, __tmp_131) => __tmp_131.with_mut(|__tmp_131| { - (*__tmp_131) = __tmp_130; - (*__tmp_131).clone() + (__tmp_140, __tmp_141) => __tmp_141.with_mut(|__tmp_141| { + (*__tmp_141) = __tmp_140; + (*__tmp_141).clone() }), } }); @@ -1878,12 +2032,15 @@ fn main_0() -> i32 { value, (*captured_index.borrow()) ); - ({ test_local_members_37() }); - ({ test_global_members_38() }); - ({ test_static_members_39() }); + ({ test_local_members_44() }); + ({ test_global_members_45() }); + ({ test_static_members_46() }); ({ test_reference_members_5() }); ({ test_reference_members_7() }); ({ test_reference_pointer_9() }); + ({ test_reference_subfields_11() }); + ({ test_reference_subfields_14() }); + ({ test_captured_alias_17() }); ({ test_0() }); ({ test_1() }); ({ test_2() }); @@ -1903,9 +2060,9 @@ fn main_0() -> i32 { 0 )), ) { - (__tmp_132, __tmp_133) => __tmp_133.with_mut(|__tmp_133| { - (*__tmp_133) = (((*__tmp_133) as u32).wrapping_add((__tmp_132 as u32))) as u32; - (*__tmp_133).clone() + (__tmp_142, __tmp_143) => __tmp_143.with_mut(|__tmp_143| { + (*__tmp_143) = (((*__tmp_143) as u32).wrapping_add((__tmp_142 as u32))) as u32; + (*__tmp_143).clone() }), } }); @@ -1915,24 +2072,24 @@ fn main_0() -> i32 { result, (*values.borrow())[(0) as usize] ); - ({ test_borrows_18() }); - ({ test_binding_24() }); - ({ test_alias_scopes_29(10_i16) }); - ({ test_boxed_array_30() }); - ({ test_boxed_array_32() }); + ({ test_borrows_25() }); + ({ test_binding_31() }); + ({ test_alias_scopes_36(10_i16) }); + ({ test_boxed_array_37() }); + ({ test_boxed_array_39() }); let mut global_result: u32 = ({ match ({ 1_u32 }, { - let __tmp_135 = global_array_34.with(|v| v.decay()).offset( + let __tmp_145 = global_array_41.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; - global_array_34.with(|rc| rc.borrow()[__idx0]) + global_array_41.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_135 + __tmp_145 }) { - (__tmp_134, __tmp_135) => __tmp_135.with_mut(|__tmp_135| { - (*__tmp_135) = (((*__tmp_135) as u32).wrapping_add((__tmp_134 as u32))) as u32; - (*__tmp_135).clone() + (__tmp_144, __tmp_145) => __tmp_145.with_mut(|__tmp_145| { + (*__tmp_145) = (((*__tmp_145) as u32).wrapping_add((__tmp_144 as u32))) as u32; + (*__tmp_145).clone() }), } }); @@ -1941,28 +2098,28 @@ fn main_0() -> i32 { global_result, ({ let __idx0 = (0) as usize; - global_array_34.with(|rc| rc.borrow()[__idx0]) + global_array_41.with(|rc| rc.borrow()[__idx0]) }) ); i = 0; result = ({ match ({ 1_u32 }, { - let __tmp_137 = global_rows_35 + let __tmp_147 = global_rows_42 .with(|v| v.decay()) .offset( ({ let __idx0 = (i.postfix_inc()) as usize; let __idx1 = (0) as usize; - global_rows_35.with(|rc| rc.borrow()[__idx0][__idx1]) + global_rows_42.with(|rc| rc.borrow()[__idx0][__idx1]) }), ) .decay() .offset(0); - __tmp_137 + __tmp_147 }) { - (__tmp_136, __tmp_137) => __tmp_137.with_mut(|__tmp_137| { - (*__tmp_137) = (((*__tmp_137) as u32).wrapping_add((__tmp_136 as u32))) as u32; - (*__tmp_137).clone() + (__tmp_146, __tmp_147) => __tmp_147.with_mut(|__tmp_147| { + (*__tmp_147) = (((*__tmp_147) as u32).wrapping_add((__tmp_146 as u32))) as u32; + (*__tmp_147).clone() }), } }); @@ -1973,35 +2130,35 @@ fn main_0() -> i32 { ({ let __idx0 = (0) as usize; let __idx1 = (0) as usize; - global_rows_35.with(|rc| rc.borrow()[__idx0][__idx1]) + global_rows_42.with(|rc| rc.borrow()[__idx0][__idx1]) }), ({ let __idx0 = (1) as usize; let __idx1 = (0) as usize; - global_rows_35.with(|rc| rc.borrow()[__idx0][__idx1]) + global_rows_42.with(|rc| rc.borrow()[__idx0][__idx1]) }) ); return 0; } #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(4)] -pub struct Index_41 { +pub struct Index_48 { #[offset(0)] pub value: i32, } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] #[byte_size(12)] -pub struct Owner_42 { +pub struct Owner_49 { #[offset(0)] #[byte_size(8)] pub values: Box<[i32]>, #[offset(8)] pub index: i32, } -impl Default for Owner_42 { +impl Default for Owner_49 { fn default() -> Self { { - Owner_42 { + Owner_49 { values: (0..2).map(|_| 0_i32).collect::>(), index: 0_i32, } @@ -2013,23 +2170,23 @@ pub trait IndexedBindingImpl { } impl IndexedBindingImpl for Ptr { fn get_1_0(&self) -> Ptr { - return selected_values_23.with(|v| v.decay()).offset( + return selected_values_30.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; - selected_values_23.with(|rc| rc.borrow()[__idx0]) + selected_values_30.with(|rc| rc.borrow()[__idx0]) }), ); } } pub fn __cpp2rust_init_globals() { - let _ = global_11.with(|_| ()); - let _ = global_record_14.with(|_| ()); - let _ = targets_16.with(|_| ()); - let _ = cursor_17.with(|_| ()); - let _ = selected_values_23.with(|_| ()); - let _ = initializer_target_26.with(|_| ()); - let _ = initializer_result_28.with(|_| ()); - let _ = global_array_34.with(|_| ()); - let _ = global_rows_35.with(|_| ()); - let _ = global_members_36.with(|_| ()); + let _ = global_18.with(|_| ()); + let _ = global_record_21.with(|_| ()); + let _ = targets_23.with(|_| ()); + let _ = cursor_24.with(|_| ()); + let _ = selected_values_30.with(|_| ()); + let _ = initializer_target_33.with(|_| ()); + let _ = initializer_result_35.with(|_| ()); + let _ = global_array_41.with(|_| ()); + let _ = global_rows_42.with(|_| ()); + let _ = global_members_43.with(|_| ()); } diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 75320ee266..2621bbe4cc 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -783,11 +783,133 @@ pub unsafe fn test_reference_pointer_9() { pub struct Node_10 { pub link: *mut *mut Node_10, } -pub static mut global_11: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10 }); -pub unsafe fn observe_global_12(mut assigned: i32) -> i32 { - return ((assigned) + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11))); +pub unsafe fn test_reference_subfields_11() { + let mut index: Index_12 = Index_12 { value: 0_u32 }; + let mut other: Index_12 = Index_12 { value: 77_u32 }; + let mut a: [Slot_13; 2] = [Slot_13 { ref_: &mut index }, Slot_13 { ref_: &mut other }]; + let mut result: u32 = (match ({ 1_u32 }, &mut ((*a[(index.value) as usize].ref_).value)) { + (__tmp_78, __tmp_79) => { + (*__tmp_79) = (((*__tmp_79) as u32).wrapping_add((__tmp_78 as u32))) as u32; + (*__tmp_79).clone() + } + }); + (unsafe { + libc::printf( + c"reference subfield compound %d %d %d\n".as_ptr() as *const libc::c_char, + (result as i32), + (index.value as i32), + (other.value as i32), + ) + }); + index.value = 0_u32; + result = (match ({ 1_u32 }, &mut ((*a[(index.value) as usize].ref_).value)) { + (__tmp_80, __tmp_81) => { + (*__tmp_81) = __tmp_80; + (*__tmp_81).clone() + } + }); + (unsafe { + libc::printf( + c"reference subfield simple %d %d %d\n".as_ptr() as *const libc::c_char, + (result as i32), + (index.value as i32), + (other.value as i32), + ) + }); +} +pub unsafe fn test_reference_subfields_14() { + let mut index: Index_15 = Index_15 { value: 0_i16 }; + let mut other: Index_15 = Index_15 { value: 77_i16 }; + let mut a: [Slot_16; 2] = [Slot_16 { ref_: &mut index }, Slot_16 { ref_: &mut other }]; + let mut result: i16 = (match ({ 1 }, &mut ((*a[(index.value) as usize].ref_).value)) { + (__tmp_82, __tmp_83) => { + (*__tmp_83) = (((*__tmp_83) as i32) + (__tmp_82 as i32)) as i16; + (*__tmp_83).clone() + } + }); + (unsafe { + libc::printf( + c"reference subfield compound %d %d %d\n".as_ptr() as *const libc::c_char, + (result as i32), + (index.value as i32), + (other.value as i32), + ) + }); + index.value = 0_i16; + result = (match ({ 1_i16 }, &mut ((*a[(index.value) as usize].ref_).value)) { + (__tmp_84, __tmp_85) => { + (*__tmp_85) = __tmp_84; + (*__tmp_85).clone() + } + }); + (unsafe { + libc::printf( + c"reference subfield simple %d %d %d\n".as_ptr() as *const libc::c_char, + (result as i32), + (index.value as i32), + (other.value as i32), + ) + }); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Index_12 { + pub value: u32, } -pub unsafe fn observe_13(mut assigned: i32, mut stored: *const i32) -> i32 { +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Slot_13 { + pub ref_: *mut Index_12, +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Index_15 { + pub value: i16, +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Slot_16 { + pub ref_: *mut Index_15, +} +pub unsafe fn test_captured_alias_17() { + let mut x: i16 = 10_i16; + let mut p: *mut i16 = (&mut x as *mut i16); + let mut f: FnPtr i16> = lambda_unsafe!( + { + let x: *mut i16 = &mut x; + let p: *mut *mut i16 = &mut p; + }, + || -> i16 { + return (match ( + { + { + (*(*p)) = (-1_i32 as i16); + 0.5_f64 + } + }, + &mut (*x), + ) { + (__tmp_86, __tmp_87) => { + (*__tmp_87) = (((*__tmp_87) as f64) + (__tmp_86 as f64)) as i16; + (*__tmp_87).clone() + } + }); + } + ); + let mut result: i32 = ((unsafe { f.call() }) as i32); + (unsafe { + libc::printf( + c"captured outer alias %d %d\n".as_ptr() as *const libc::c_char, + (result), + (x as i32), + ) + }); +} +pub static mut global_18: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10 }); +pub unsafe fn observe_global_19(mut assigned: i32) -> i32 { + return ((assigned) + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18))); +} +pub unsafe fn observe_20(mut assigned: i32, mut stored: *const i32) -> i32 { return ((assigned) + (*stored)); } #[repr(C)] @@ -800,31 +922,31 @@ pub struct GlobalRecord_Inner { pub struct GlobalRecord { pub inner: GlobalRecord_Inner, } -pub static mut global_record_14: std::cell::LazyCell = +pub static mut global_record_21: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { GlobalRecord { inner: GlobalRecord_Inner { value: 10 }, } }); -pub unsafe fn observe_record_15(mut assigned: i32) -> i32 { +pub unsafe fn observe_record_22(mut assigned: i32) -> i32 { return ((assigned) - + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_14)) + + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_21)) .inner .value)); } -pub static mut targets_16: std::cell::LazyCell<[i32; 2]> = +pub static mut targets_23: std::cell::LazyCell<[i32; 2]> = std::cell::LazyCell::new(|| unsafe { [10, 20] }); -pub static mut cursor_17: std::cell::LazyCell<*mut i32> = std::cell::LazyCell::new(|| unsafe { - (*std::cell::LazyCell::force_mut(&mut *&raw mut targets_16)).as_mut_ptr() +pub static mut cursor_24: std::cell::LazyCell<*mut i32> = std::cell::LazyCell::new(|| unsafe { + (*std::cell::LazyCell::force_mut(&mut *&raw mut targets_23)).as_mut_ptr() }); -pub unsafe fn test_borrows_18() { +pub unsafe fn test_borrows_25() { (unsafe { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - observe_global_12({ - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11)) = 99; - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11)) + observe_global_19({ + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18)) = 99; + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18)) }) }), ) @@ -833,9 +955,9 @@ pub unsafe fn test_borrows_18() { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - observe_global_12({ - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11)) += 5; - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11)) + observe_global_19({ + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18)) += 5; + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18)) }) }), ) @@ -844,16 +966,16 @@ pub unsafe fn test_borrows_18() { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - observe_global_12({ - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11)) = (unsafe { - observe_13( + observe_global_19({ + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18)) = (unsafe { + observe_20( 0, - (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11)) + (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18)) as *mut i32) .cast_const(), ) }); - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18)) }) }), ) @@ -861,22 +983,22 @@ pub unsafe fn test_borrows_18() { let mut assigned: i32 = ((match ( { { - (*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_19)) = (-1_i32 as i16); + (*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_26)) = (-1_i32 as i16); 0.5_f64 } }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_19)), + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_26)), ) { - (__tmp_78, __tmp_79) => { - (*__tmp_79) = (((*__tmp_79) as f64) + (__tmp_78 as f64)) as i16; - (*__tmp_79).clone() + (__tmp_88, __tmp_89) => { + (*__tmp_89) = (((*__tmp_89) as f64) + (__tmp_88 as f64)) as i16; + (*__tmp_89).clone() } }) as i32); (unsafe { libc::printf( c"%d %d\n".as_ptr() as *const libc::c_char, (assigned), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_19)) as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_26)) as i32), ) }); let mut aliased: i16 = 10_i16; @@ -890,9 +1012,9 @@ pub unsafe fn test_borrows_18() { }, &mut (aliased), ) { - (__tmp_80, __tmp_81) => { - (*__tmp_81) = (((*__tmp_81) as f64) + (__tmp_80 as f64)) as i16; - (*__tmp_81).clone() + (__tmp_90, __tmp_91) => { + (*__tmp_91) = (((*__tmp_91) as f64) + (__tmp_90 as f64)) as i16; + (*__tmp_91).clone() } }) as i32); (unsafe { @@ -906,9 +1028,9 @@ pub unsafe fn test_borrows_18() { { { (unsafe { - observe_13( + observe_20( 0, - (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_11)) + (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18)) as *mut i32) .cast_const(), ) @@ -916,29 +1038,29 @@ pub unsafe fn test_borrows_18() { 0.5_f64 } }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut flag_20)), + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut flag_27)), ) { - (__tmp_82, __tmp_83) => { - (*__tmp_83) = (((*__tmp_83) as u8 as f64) + (__tmp_82 as f64)) != 0.0; - (*__tmp_83).clone() + (__tmp_92, __tmp_93) => { + (*__tmp_93) = (((*__tmp_93) as u8 as f64) + (__tmp_92 as f64)) != 0.0; + (*__tmp_93).clone() } }); (unsafe { libc::printf( c"%d %d\n".as_ptr() as *const libc::c_char, (enabled as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut flag_20)) as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut flag_27)) as i32), ) }); (unsafe { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - observe_record_15({ - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_14)) + observe_record_22({ + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_21)) .inner .value = 99; - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_14)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_21)) .inner .value }) @@ -948,27 +1070,27 @@ pub unsafe fn test_borrows_18() { let mut shifted: *mut i32 = (match ( { { - (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_17)) = - (*std::cell::LazyCell::force_mut(&mut *&raw mut targets_16)) + (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_24)) = + (*std::cell::LazyCell::force_mut(&mut *&raw mut targets_23)) .as_mut_ptr() .offset((1) as isize); 1 } }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_17)), + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_24)), ) { - (__tmp_84, __tmp_85) => { - (*__tmp_85) = (*__tmp_85).offset(-(__tmp_84 as isize)); - (*__tmp_85).clone() + (__tmp_94, __tmp_95) => { + (*__tmp_95) = (*__tmp_95).offset(-(__tmp_94 as isize)); + (*__tmp_95).clone() } }); (unsafe { libc::printf( c"%d %d\n".as_ptr() as *const libc::c_char, - (((*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_17)) - == ((*std::cell::LazyCell::force_mut(&mut *&raw mut targets_16)).as_mut_ptr())) + (((*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_24)) + == ((*std::cell::LazyCell::force_mut(&mut *&raw mut targets_23)).as_mut_ptr())) as i32), - (((shifted) == (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_17))) as i32), + (((shifted) == (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_24))) as i32), ) }); let mut local: i32 = 10; @@ -981,7 +1103,7 @@ pub unsafe fn test_borrows_18() { local }; let _stored: *const i32 = (&mut local as *mut i32).cast_const(); - observe_13(_assigned, _stored) + observe_20(_assigned, _stored) }), ) }); @@ -994,11 +1116,11 @@ pub unsafe fn test_borrows_18() { local }; let _stored: *const i32 = (&mut local as *mut i32).cast_const(); - observe_13(_assigned, _stored) + observe_20(_assigned, _stored) }), ) }); - let mut record: Record_21 = Record_21 { value: 10 }; + let mut record: Record_28 = Record_28 { value: 10 }; (unsafe { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, @@ -1008,7 +1130,7 @@ pub unsafe fn test_borrows_18() { record.value }; let _stored: *const i32 = (&mut record.value as *mut i32).cast_const(); - observe_13(_assigned, _stored) + observe_20(_assigned, _stored) }), ) }); @@ -1021,32 +1143,32 @@ pub unsafe fn test_borrows_18() { record.value }; let _stored: *const i32 = (&mut record.value as *mut i32).cast_const(); - observe_13(_assigned, _stored) + observe_20(_assigned, _stored) }), ) }); - let mut first: Link_22 = ::default(); - first = Link_22 { - next: (&mut first as *mut Link_22), + let mut first: Link_29 = ::default(); + first = Link_29 { + next: (&mut first as *mut Link_29), }; - let mut second: Link_22 = Link_22 { - next: (&mut first as *mut Link_22), + let mut second: Link_29 = Link_29 { + next: (&mut first as *mut Link_29), }; - let selector: *mut *mut Link_22 = &mut first.next; - let mut selected: *mut Link_22 = (match ( - { (&mut second as *mut Link_22) }, + let selector: *mut *mut Link_29 = &mut first.next; + let mut selected: *mut Link_29 = (match ( + { (&mut second as *mut Link_29) }, &mut ((*(*selector)).next), ) { - (__tmp_86, __tmp_87) => { - (*__tmp_87) = __tmp_86; - (*__tmp_87).clone() + (__tmp_96, __tmp_97) => { + (*__tmp_97) = __tmp_96; + (*__tmp_97).clone() } }); (unsafe { libc::printf( c"%d %d\n".as_ptr() as *const libc::c_char, - (((selected) == (&mut second as *mut Link_22)) as i32), - (((first.next) == (&mut second as *mut Link_22)) as i32), + (((selected) == (&mut second as *mut Link_29)) as i32), + (((first.next) == (&mut second as *mut Link_29)) as i32), ) }); let mut values: Vec = vec![10; 1_usize]; @@ -1059,7 +1181,7 @@ pub unsafe fn test_borrows_18() { values[(0_usize)] }; let _stored: *const i32 = (&mut values[(0_usize)] as *mut i32).cast_const(); - observe_13(_assigned, _stored) + observe_20(_assigned, _stored) }), ) }); @@ -1072,75 +1194,75 @@ pub unsafe fn test_borrows_18() { values[(0_usize)] }; let _stored: *const i32 = (&mut values[(0_usize)] as *mut i32).cast_const(); - observe_13(_assigned, _stored) + observe_20(_assigned, _stored) }), ) }); } -static mut promoted_19: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10_i16 }); -static mut flag_20: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { false }); +static mut promoted_26: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10_i16 }); +static mut flag_27: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { false }); #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Record_21 { +pub struct Record_28 { pub value: i32, } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Link_22 { - pub next: *mut Link_22, +pub struct Link_29 { + pub next: *mut Link_29, } -pub static mut selected_values_23: std::cell::LazyCell<[u32; 3]> = +pub static mut selected_values_30: std::cell::LazyCell<[u32; 3]> = std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] pub struct IndexedBinding {} impl IndexedBinding { pub unsafe fn get_1_0(&mut self) -> *mut u32 { - return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_23)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_23))[(0) as usize]) + return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_30)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_30))[(0) as usize]) as usize]; } } -pub unsafe fn test_binding_24() { +pub unsafe fn test_binding_31() { let mut owner: IndexedBinding = ::default(); - let __decomp_25: *mut IndexedBinding = &mut owner; - let value: *mut u32 = (unsafe { IndexedBinding::get_1_0(&mut (*__decomp_25)) }); + let __decomp_32: *mut IndexedBinding = &mut owner; + let value: *mut u32 = (unsafe { IndexedBinding::get_1_0(&mut (*__decomp_32)) }); let mut result: u32 = (match ( { 1_u32 }, - &mut (*(unsafe { IndexedBinding::get_1_0(&mut (*__decomp_25)) })), + &mut (*(unsafe { IndexedBinding::get_1_0(&mut (*__decomp_32)) })), ) { - (__tmp_88, __tmp_89) => { - (*__tmp_89) = (((*__tmp_89) as u32).wrapping_add((__tmp_88 as u32))) as u32; - (*__tmp_89).clone() + (__tmp_98, __tmp_99) => { + (*__tmp_99) = (((*__tmp_99) as u32).wrapping_add((__tmp_98 as u32))) as u32; + (*__tmp_99).clone() } }); (unsafe { libc::printf( c"binding compound %u %u\n".as_ptr() as *const libc::c_char, (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_23))[(0) as usize]), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_30))[(0) as usize]), ) }); } -pub static mut initializer_target_26: std::cell::LazyCell = +pub static mut initializer_target_33: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10_u32 }); -pub unsafe fn mutate_initializer_27() -> u32 { - (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_26)) = 20_u32; +pub unsafe fn mutate_initializer_34() -> u32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_33)) = 20_u32; return 1_u32; } -pub static mut initializer_result_28: std::cell::LazyCell = +pub static mut initializer_result_35: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { (match ( - { (unsafe { mutate_initializer_27() }) }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_26)), + { (unsafe { mutate_initializer_34() }) }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_33)), ) { - (__tmp_90, __tmp_91) => { - (*__tmp_91) = (((*__tmp_91) as u32).wrapping_add((__tmp_90 as u32))) as u32; - (*__tmp_91).clone() + (__tmp_100, __tmp_101) => { + (*__tmp_101) = (((*__tmp_101) as u32).wrapping_add((__tmp_100 as u32))) as u32; + (*__tmp_101).clone() } }) }); -pub unsafe fn test_alias_scopes_29(mut parameter: i16) { +pub unsafe fn test_alias_scopes_36(mut parameter: i16) { let mut p: *mut i16 = (&mut parameter as *mut i16); let mut result: i16 = (match ( { @@ -1151,9 +1273,9 @@ pub unsafe fn test_alias_scopes_29(mut parameter: i16) { }, &mut (parameter), ) { - (__tmp_92, __tmp_93) => { - (*__tmp_93) = (((*__tmp_93) as f64) + (__tmp_92 as f64)) as i16; - (*__tmp_93).clone() + (__tmp_102, __tmp_103) => { + (*__tmp_103) = (((*__tmp_103) as f64) + (__tmp_102 as f64)) as i16; + (*__tmp_103).clone() } }); (unsafe { @@ -1174,9 +1296,9 @@ pub unsafe fn test_alias_scopes_29(mut parameter: i16) { } ); result = (match ({ (unsafe { mutate.call() }).clone() }, &mut (local)) { - (__tmp_94, __tmp_95) => { - (*__tmp_95) = (((*__tmp_95) as f64) + (__tmp_94 as f64)) as i16; - (*__tmp_95).clone() + (__tmp_104, __tmp_105) => { + (*__tmp_105) = (((*__tmp_105) as f64) + (__tmp_104 as f64)) as i16; + (*__tmp_105).clone() } }); (unsafe { @@ -1189,12 +1311,12 @@ pub unsafe fn test_alias_scopes_29(mut parameter: i16) { (unsafe { libc::printf( c"initializer %u %u\n".as_ptr() as *const libc::c_char, - (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_result_28)), - (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_26)), + (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_result_35)), + (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_33)), ) }); } -pub unsafe fn test_boxed_array_30() { +pub unsafe fn test_boxed_array_37() { let mut a: [u32; 3] = [0_u32, 20_u32, 30_u32]; let mut p: *mut u32 = a.as_mut_ptr(); let mut i: i32 = 0; @@ -1202,9 +1324,9 @@ pub unsafe fn test_boxed_array_30() { { 1_u32 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), ) { - (__tmp_96, __tmp_97) => { - (*__tmp_97) = (((*__tmp_97) as u32).wrapping_add((__tmp_96 as u32))) as u32; - (*__tmp_97).clone() + (__tmp_106, __tmp_107) => { + (*__tmp_107) = (((*__tmp_107) as u32).wrapping_add((__tmp_106 as u32))) as u32; + (*__tmp_107).clone() } }); (unsafe { @@ -1222,9 +1344,9 @@ pub unsafe fn test_boxed_array_30() { { 1_u32 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), ) { - (__tmp_98, __tmp_99) => { - (*__tmp_99) = __tmp_98; - (*__tmp_99).clone() + (__tmp_108, __tmp_109) => { + (*__tmp_109) = __tmp_108; + (*__tmp_109).clone() } }); (unsafe { @@ -1238,30 +1360,30 @@ pub unsafe fn test_boxed_array_30() { }); result = (match ( { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_31)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_31))[(0) as usize]) as usize]), + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_38)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_38))[(0) as usize]) as usize]), ) { - (__tmp_100, __tmp_101) => { - (*__tmp_101) = (((*__tmp_101) as u32).wrapping_add((__tmp_100 as u32))) as u32; - (*__tmp_101).clone() + (__tmp_110, __tmp_111) => { + (*__tmp_111) = (((*__tmp_111) as u32).wrapping_add((__tmp_110 as u32))) as u32; + (*__tmp_111).clone() } }); (unsafe { libc::printf( c"static array %d %d\n".as_ptr() as *const libc::c_char, (result as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_31))[(0) as usize] as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_38))[(0) as usize] as i32), ) }); } -pub unsafe fn test_boxed_array_32() { +pub unsafe fn test_boxed_array_39() { let mut a: [i16; 3] = [0_i16, 20_i16, 30_i16]; let mut p: *mut i16 = a.as_mut_ptr(); let mut i: i32 = 0; let mut result: i16 = (match ({ 1 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize])) { - (__tmp_102, __tmp_103) => { - (*__tmp_103) = (((*__tmp_103) as i32) + (__tmp_102 as i32)) as i16; - (*__tmp_103).clone() + (__tmp_112, __tmp_113) => { + (*__tmp_113) = (((*__tmp_113) as i32) + (__tmp_112 as i32)) as i16; + (*__tmp_113).clone() } }); (unsafe { @@ -1279,9 +1401,9 @@ pub unsafe fn test_boxed_array_32() { { 1_i16 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), ) { - (__tmp_104, __tmp_105) => { - (*__tmp_105) = __tmp_104; - (*__tmp_105).clone() + (__tmp_114, __tmp_115) => { + (*__tmp_115) = __tmp_114; + (*__tmp_115).clone() } }); (unsafe { @@ -1295,29 +1417,29 @@ pub unsafe fn test_boxed_array_32() { }); result = (match ( { 1 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_33)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_33))[(0) as usize]) as usize]), + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_40)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_40))[(0) as usize]) as usize]), ) { - (__tmp_106, __tmp_107) => { - (*__tmp_107) = (((*__tmp_107) as i32) + (__tmp_106 as i32)) as i16; - (*__tmp_107).clone() + (__tmp_116, __tmp_117) => { + (*__tmp_117) = (((*__tmp_117) as i32) + (__tmp_116 as i32)) as i16; + (*__tmp_117).clone() } }); (unsafe { libc::printf( c"static array %d %d\n".as_ptr() as *const libc::c_char, (result as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_33))[(0) as usize] as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_40))[(0) as usize] as i32), ) }); } -static mut saved_31: std::cell::LazyCell<[u32; 3]> = +static mut saved_38: std::cell::LazyCell<[u32; 3]> = std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); -static mut saved_33: std::cell::LazyCell<[i16; 3]> = +static mut saved_40: std::cell::LazyCell<[i16; 3]> = std::cell::LazyCell::new(|| unsafe { [0_i16, 20_i16, 30_i16] }); -pub static mut global_array_34: std::cell::LazyCell<[u32; 3]> = +pub static mut global_array_41: std::cell::LazyCell<[u32; 3]> = std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); -pub static mut global_rows_35: std::cell::LazyCell<[[u32; 2]; 2]> = +pub static mut global_rows_42: std::cell::LazyCell<[[u32; 2]; 2]> = std::cell::LazyCell::new(|| unsafe { [[0_u32, 10_u32], [20_u32, 30_u32]] }); #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] @@ -1326,7 +1448,7 @@ pub struct IndexedMember { pub value: u32, pub promoted: i16, } -pub static mut global_members_36: std::cell::LazyCell<[IndexedMember; 2]> = +pub static mut global_members_43: std::cell::LazyCell<[IndexedMember; 2]> = std::cell::LazyCell::new(|| unsafe { [ IndexedMember { @@ -1341,7 +1463,7 @@ pub static mut global_members_36: std::cell::LazyCell<[IndexedMember; 2]> = }, ] }); -pub unsafe fn test_local_members_37() { +pub unsafe fn test_local_members_44() { let mut a: [IndexedMember; 2] = [ IndexedMember { key: 0, @@ -1360,9 +1482,9 @@ pub unsafe fn test_local_members_37() { { 1_u32 }, &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].value), ) { - (__tmp_108, __tmp_109) => { - (*__tmp_109) = (((*__tmp_109) as u32).wrapping_add((__tmp_108 as u32))) as u32; - (*__tmp_109).clone() + (__tmp_118, __tmp_119) => { + (*__tmp_119) = (((*__tmp_119) as u32).wrapping_add((__tmp_118 as u32))) as u32; + (*__tmp_119).clone() } }); (unsafe { @@ -1379,8 +1501,8 @@ pub unsafe fn test_local_members_37() { { 1 }, &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].promoted), ) { - (__tmp_110, __tmp_111) => { - (*__tmp_111) = (((*__tmp_111) as i32) + (__tmp_110 as i32)) as i16; + (__tmp_120, __tmp_121) => { + (*__tmp_121) = (((*__tmp_121) as i32) + (__tmp_120 as i32)) as i16; } }; (unsafe { @@ -1396,9 +1518,9 @@ pub unsafe fn test_local_members_37() { { 99_u32 }, &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].value), ) { - (__tmp_112, __tmp_113) => { - (*__tmp_113) = __tmp_112; - (*__tmp_113).clone() + (__tmp_122, __tmp_123) => { + (*__tmp_123) = __tmp_122; + (*__tmp_123).clone() } }); (unsafe { @@ -1417,19 +1539,19 @@ pub unsafe fn test_local_members_37() { ) }); } -pub unsafe fn test_global_members_38() { +pub unsafe fn test_global_members_45() { let mut i: i32 = 0; let mut result: u32 = (match ( { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36)) + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43)) [(i.postfix_inc()) as usize] .key) as usize] .value), ) { - (__tmp_114, __tmp_115) => { - (*__tmp_115) = (((*__tmp_115) as u32).wrapping_add((__tmp_114 as u32))) as u32; - (*__tmp_115).clone() + (__tmp_124, __tmp_125) => { + (*__tmp_125) = (((*__tmp_125) as u32).wrapping_add((__tmp_124 as u32))) as u32; + (*__tmp_125).clone() } }); (unsafe { @@ -1437,47 +1559,47 @@ pub unsafe fn test_global_members_38() { c"member unsigned %d %u %u %u\n".as_ptr() as *const libc::c_char, (i), (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36))[(0) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43))[(0) as usize] .value), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36))[(1) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43))[(1) as usize] .value), ) }); i = 0; match ( { 1 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36)) + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43)) [(i.postfix_inc()) as usize] .key) as usize] .promoted), ) { - (__tmp_116, __tmp_117) => { - (*__tmp_117) = (((*__tmp_117) as i32) + (__tmp_116 as i32)) as i16; + (__tmp_126, __tmp_127) => { + (*__tmp_127) = (((*__tmp_127) as i32) + (__tmp_126 as i32)) as i16; } }; (unsafe { libc::printf( c"member promoted %d %d %d\n".as_ptr() as *const libc::c_char, (i), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36))[(0) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43))[(0) as usize] .promoted as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36))[(1) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43))[(1) as usize] .promoted as i32), ) }); i = 0; result = (match ( { 99_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36)) + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43)) [(i.postfix_inc()) as usize] .key) as usize] .value), ) { - (__tmp_118, __tmp_119) => { - (*__tmp_119) = __tmp_118; - (*__tmp_119).clone() + (__tmp_128, __tmp_129) => { + (*__tmp_129) = __tmp_128; + (*__tmp_129).clone() } }); (unsafe { @@ -1485,25 +1607,25 @@ pub unsafe fn test_global_members_38() { c"member simple %d %u %u %u\n".as_ptr() as *const libc::c_char, (i), (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36))[(0) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43))[(0) as usize] .value), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_36))[(1) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43))[(1) as usize] .value), ) }); } -pub unsafe fn test_static_members_39() { +pub unsafe fn test_static_members_46() { let mut i: i32 = 0; let mut result: u32 = (match ( { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(i.postfix_inc()) as usize] + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(i.postfix_inc()) as usize] .key) as usize] .value), ) { - (__tmp_120, __tmp_121) => { - (*__tmp_121) = (((*__tmp_121) as u32).wrapping_add((__tmp_120 as u32))) as u32; - (*__tmp_121).clone() + (__tmp_130, __tmp_131) => { + (*__tmp_131) = (((*__tmp_131) as u32).wrapping_add((__tmp_130 as u32))) as u32; + (*__tmp_131).clone() } }); (unsafe { @@ -1511,41 +1633,41 @@ pub unsafe fn test_static_members_39() { c"member unsigned %d %u %u %u\n".as_ptr() as *const libc::c_char, (i), (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(0) as usize].value), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(1) as usize].value), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(0) as usize].value), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(1) as usize].value), ) }); i = 0; match ( { 1 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(i.postfix_inc()) as usize] + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(i.postfix_inc()) as usize] .key) as usize] .promoted), ) { - (__tmp_122, __tmp_123) => { - (*__tmp_123) = (((*__tmp_123) as i32) + (__tmp_122 as i32)) as i16; + (__tmp_132, __tmp_133) => { + (*__tmp_133) = (((*__tmp_133) as i32) + (__tmp_132 as i32)) as i16; } }; (unsafe { libc::printf( c"member promoted %d %d %d\n".as_ptr() as *const libc::c_char, (i), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(0) as usize].promoted as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(1) as usize].promoted as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(0) as usize].promoted as i32), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(1) as usize].promoted as i32), ) }); i = 0; result = (match ( { 99_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(i.postfix_inc()) as usize] + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(i.postfix_inc()) as usize] .key) as usize] .value), ) { - (__tmp_124, __tmp_125) => { - (*__tmp_125) = __tmp_124; - (*__tmp_125).clone() + (__tmp_134, __tmp_135) => { + (*__tmp_135) = __tmp_134; + (*__tmp_135).clone() } }); (unsafe { @@ -1553,12 +1675,12 @@ pub unsafe fn test_static_members_39() { c"member simple %d %u %u %u\n".as_ptr() as *const libc::c_char, (i), (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(0) as usize].value), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_40))[(1) as usize].value), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(0) as usize].value), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(1) as usize].value), ) }); } -static mut a_40: std::cell::LazyCell<[IndexedMember; 2]> = std::cell::LazyCell::new(|| unsafe { +static mut a_47: std::cell::LazyCell<[IndexedMember; 2]> = std::cell::LazyCell::new(|| unsafe { [ IndexedMember { key: 0, @@ -1606,7 +1728,7 @@ unsafe fn main_0() -> i32 { (a[(1) as usize]), ) }); - let mut selector: Index_41 = Index_41 { value: 1 }; + let mut selector: Index_48 = Index_48 { value: 1 }; value = ({ a[(selector.value) as usize] = 88; a[(selector.value) as usize] @@ -1627,9 +1749,9 @@ unsafe fn main_0() -> i32 { let alias: *mut i32 = &mut a[(0) as usize]; (*alias) = 0; value = (match ({ 1 }, &mut (a[(*alias) as usize])) { - (__tmp_126, __tmp_127) => { - (*__tmp_127) = __tmp_126; - (*__tmp_127).clone() + (__tmp_136, __tmp_137) => { + (*__tmp_137) = __tmp_136; + (*__tmp_137).clone() } }); (unsafe { @@ -1686,7 +1808,7 @@ unsafe fn main_0() -> i32 { (a[(1) as usize]), ) }); - let mut owner: Owner_42 = Owner_42 { + let mut owner: Owner_49 = Owner_49 { values: [0, 20], index: 0, }; @@ -1694,9 +1816,9 @@ unsafe fn main_0() -> i32 { { 1 }, &mut (owner.values[(owner.values[(0) as usize]) as usize]), ) { - (__tmp_128, __tmp_129) => { - (*__tmp_129) = __tmp_128; - (*__tmp_129).clone() + (__tmp_138, __tmp_139) => { + (*__tmp_139) = __tmp_138; + (*__tmp_139).clone() } }); reference_value = ({ @@ -1712,15 +1834,15 @@ unsafe fn main_0() -> i32 { (owner.values[(1) as usize]), ) }); - let mut alias_selector: Index_41 = Index_41 { value: 0 }; + let mut alias_selector: Index_48 = Index_48 { value: 0 }; let mut member_alias: *mut i32 = (&mut alias_selector.value as *mut i32); value = (match ( { 1 }, &mut (*member_alias.offset((alias_selector.value) as isize)), ) { - (__tmp_130, __tmp_131) => { - (*__tmp_131) = __tmp_130; - (*__tmp_131).clone() + (__tmp_140, __tmp_141) => { + (*__tmp_141) = __tmp_140; + (*__tmp_141).clone() } }); (unsafe { @@ -1733,9 +1855,9 @@ unsafe fn main_0() -> i32 { let mut self_index: i32 = 0; let mut self_: *mut i32 = (&mut self_index as *mut i32); value = (match ({ 1 }, &mut (*self_.offset((self_index) as isize))) { - (__tmp_132, __tmp_133) => { - (*__tmp_133) = __tmp_132; - (*__tmp_133).clone() + (__tmp_142, __tmp_143) => { + (*__tmp_143) = __tmp_142; + (*__tmp_143).clone() } }); (unsafe { @@ -1757,9 +1879,9 @@ unsafe fn main_0() -> i32 { { 10000 }, &mut (*(*captured_pointer).offset((*captured_index) as isize)), ) { - (__tmp_134, __tmp_135) => { - (*__tmp_135) = __tmp_134; - (*__tmp_135).clone() + (__tmp_144, __tmp_145) => { + (*__tmp_145) = __tmp_144; + (*__tmp_145).clone() } }); } @@ -1772,12 +1894,15 @@ unsafe fn main_0() -> i32 { (captured_index), ) }); - (unsafe { test_local_members_37() }); - (unsafe { test_global_members_38() }); - (unsafe { test_static_members_39() }); + (unsafe { test_local_members_44() }); + (unsafe { test_global_members_45() }); + (unsafe { test_static_members_46() }); (unsafe { test_reference_members_5() }); (unsafe { test_reference_members_7() }); (unsafe { test_reference_pointer_9() }); + (unsafe { test_reference_subfields_11() }); + (unsafe { test_reference_subfields_14() }); + (unsafe { test_captured_alias_17() }); (unsafe { test_0() }); (unsafe { test_1() }); (unsafe { test_2() }); @@ -1793,9 +1918,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_136, __tmp_137) => { - (*__tmp_137) = (((*__tmp_137) as u32).wrapping_add((__tmp_136 as u32))) as u32; - (*__tmp_137).clone() + (__tmp_146, __tmp_147) => { + (*__tmp_147) = (((*__tmp_147) as u32).wrapping_add((__tmp_146 as u32))) as u32; + (*__tmp_147).clone() } }); (unsafe { @@ -1806,39 +1931,39 @@ unsafe fn main_0() -> i32 { (values[(0) as usize]), ) }); - (unsafe { test_borrows_18() }); - (unsafe { test_binding_24() }); - (unsafe { test_alias_scopes_29(10_i16) }); - (unsafe { test_boxed_array_30() }); - (unsafe { test_boxed_array_32() }); + (unsafe { test_borrows_25() }); + (unsafe { test_binding_31() }); + (unsafe { test_alias_scopes_36(10_i16) }); + (unsafe { test_boxed_array_37() }); + (unsafe { test_boxed_array_39() }); let mut global_result: u32 = (match ( { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_34)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_34))[(0) as usize]) + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_41)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_41))[(0) as usize]) as usize]), ) { - (__tmp_138, __tmp_139) => { - (*__tmp_139) = (((*__tmp_139) as u32).wrapping_add((__tmp_138 as u32))) as u32; - (*__tmp_139).clone() + (__tmp_148, __tmp_149) => { + (*__tmp_149) = (((*__tmp_149) as u32).wrapping_add((__tmp_148 as u32))) as u32; + (*__tmp_149).clone() } }); (unsafe { libc::printf( c"global array %u %u\n".as_ptr() as *const libc::c_char, (global_result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_34))[(0) as usize]), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_41))[(0) as usize]), ) }); i = 0; result = (match ( { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_35)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_35)) + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_42)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_42)) [(i.postfix_inc()) as usize][(0) as usize]) as usize][(0) as usize]), ) { - (__tmp_140, __tmp_141) => { - (*__tmp_141) = (((*__tmp_141) as u32).wrapping_add((__tmp_140 as u32))) as u32; - (*__tmp_141).clone() + (__tmp_150, __tmp_151) => { + (*__tmp_151) = (((*__tmp_151) as u32).wrapping_add((__tmp_150 as u32))) as u32; + (*__tmp_151).clone() } }); (unsafe { @@ -1846,9 +1971,9 @@ unsafe fn main_0() -> i32 { c"nested array %d %u %u %u\n".as_ptr() as *const libc::c_char, (i), (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_35))[(0) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_42))[(0) as usize] [(0) as usize]), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_35))[(1) as usize] + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_42))[(1) as usize] [(0) as usize]), ) }); @@ -1856,24 +1981,24 @@ unsafe fn main_0() -> i32 { } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Index_41 { +pub struct Index_48 { pub value: i32, } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Owner_42 { +pub struct Owner_49 { pub values: [i32; 2], pub index: i32, } pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const global_11); - std::cell::LazyCell::force(&*&raw const global_record_14); - std::cell::LazyCell::force(&*&raw const targets_16); - std::cell::LazyCell::force(&*&raw const cursor_17); - std::cell::LazyCell::force(&*&raw const selected_values_23); - std::cell::LazyCell::force(&*&raw const initializer_target_26); - std::cell::LazyCell::force(&*&raw const initializer_result_28); - std::cell::LazyCell::force(&*&raw const global_array_34); - std::cell::LazyCell::force(&*&raw const global_rows_35); - std::cell::LazyCell::force(&*&raw const global_members_36); + std::cell::LazyCell::force(&*&raw const global_18); + std::cell::LazyCell::force(&*&raw const global_record_21); + std::cell::LazyCell::force(&*&raw const targets_23); + std::cell::LazyCell::force(&*&raw const cursor_24); + std::cell::LazyCell::force(&*&raw const selected_values_30); + std::cell::LazyCell::force(&*&raw const initializer_target_33); + std::cell::LazyCell::force(&*&raw const initializer_result_35); + std::cell::LazyCell::force(&*&raw const global_array_41); + std::cell::LazyCell::force(&*&raw const global_rows_42); + std::cell::LazyCell::force(&*&raw const global_members_43); } From 1142cfdb12fc726aabddcf4391dd7b62927a50ed Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Sat, 28 Nov 2026 19:50:47 +0000 Subject: [PATCH 16/25] Keep stable container and pointer indices on compact assignment lowering Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 147 +++++++---- tests/unit/assignment_single_eval.cpp | 49 ++++ .../out/refcount/assignment_single_eval.rs | 234 ++++++++++++++---- .../unit/out/unsafe/assignment_single_eval.rs | 178 ++++++++++--- 4 files changed, 487 insertions(+), 121 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 3b8e7c20b6..d68272ef1e 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -5141,6 +5141,52 @@ bool Converter::NeedsAssignmentBinding( return true; } if (!rhs_effects) { + auto stable_index = [&](auto &&self, const clang::Expr *expr, + const clang::VarDecl *decl) -> bool { + if (expr->HasSideEffects(ctx_)) { + return false; + } + if (expr->isIntegerConstantExpr(ctx_)) { + return true; + } + expr = expr->IgnoreParenImpCasts(); + if (const auto *ref = clang::dyn_cast(expr)) { + const auto *index = clang::dyn_cast(ref->getDecl()); + return index && index != decl && !index->isImplicit() && + !IsGlobalVar(index) && curr_function_ && + index->getDeclContext() == curr_function_ && + !index->getType()->isReferenceType(); + } + if (const auto *member = clang::dyn_cast(expr)) { + return !member->isArrow() && + !member->getMemberDecl()->getType()->isReferenceType() && + self(self, member->getBase(), decl); + } + if (const auto *element = + clang::dyn_cast(expr)) { + return element->getBase() + ->IgnoreParenImpCasts() + ->getType() + ->isArrayType() && + self(self, element->getBase(), decl) && + self(self, element->getIdx(), decl); + } + if (const auto *binary = clang::dyn_cast(expr); + binary && binary->isPtrMemOp()) { + return false; + } + if (clang::isa(expr) || + (clang::isa(expr) && + clang::cast(expr)->getOpcode() != + clang::UO_Deref)) { + return std::ranges::all_of(expr->children(), [&](const auto *child) { + const auto *value = clang::dyn_cast_or_null(child); + return value && self(self, value, decl); + }); + } + return false; + }; // Fixed array elements, including their fields, still select the same // storage after the write. Keep their compact lowering too. const auto *base = target; @@ -5164,51 +5210,9 @@ bool Converter::NeedsAssignmentBinding( if (decl && !decl->isImplicit() && decl->getType()->isArrayType()) { // An index made from independent by-value variables cannot change when // this array element is stored. References and indirect reads can. - auto stable_index = [&](auto &&self, const clang::Expr *expr) -> bool { - if (expr->isIntegerConstantExpr(ctx_)) { - return true; - } - expr = expr->IgnoreParenImpCasts(); - if (const auto *ref = clang::dyn_cast(expr)) { - const auto *index = clang::dyn_cast(ref->getDecl()); - return index && index != decl && !index->isImplicit() && - !index->getType()->isReferenceType(); - } - if (const auto *member = clang::dyn_cast(expr)) { - return !member->isArrow() && - !member->getMemberDecl()->getType()->isReferenceType() && - self(self, member->getBase()); - } - if (const auto *element = - clang::dyn_cast(expr)) { - return element->getBase() - ->IgnoreParenImpCasts() - ->getType() - ->isArrayType() && - self(self, element->getBase()) && - self(self, element->getIdx()); - } - if (const auto *binary = clang::dyn_cast(expr); - binary && binary->isPtrMemOp()) { - return false; - } - if (clang::isa(expr) || - (clang::isa(expr) && - clang::cast(expr)->getOpcode() != - clang::UO_Deref)) { - return std::ranges::all_of( - expr->children(), [&](const auto *child) { - const auto *value = - clang::dyn_cast_or_null(child); - return value && self(self, value); - }); - } - return false; - }; bool stable = true; for (const auto *element = subscript; element;) { - stable &= stable_index(stable_index, element->getIdx()); + stable &= stable_index(stable_index, element->getIdx(), decl); const auto *base = element->getBase()->IgnoreParenImpCasts(); stable &= base->getType()->isArrayType(); element = clang::dyn_cast(base); @@ -5229,12 +5233,49 @@ bool Converter::NeedsAssignmentBinding( return false; } } - // The standard flat-vector subscript is a call in the AST, but a constant - // index and an effect-free receiver keep selecting the same element. - if (const auto *call = clang::dyn_cast(target); - call && call->getOperator() == clang::OO_Subscript && - GetEnclosingObject(call) && !call->getArg(0)->HasSideEffects(ctx_) && - call->getArg(1)->isIntegerConstantExpr(ctx_)) { + // Standard flat-container subscripts are calls in the AST, but independent + // indices and effect-free receivers keep selecting the same element. + auto enclosing_target = [](const clang::Expr *expr) -> const clang::Expr * { + if (const auto *object = GetEnclosingObject(expr)) { + return object; + } + if (const auto *call = clang::dyn_cast(expr); + call && call->getOperator() == clang::OO_Subscript) { + const auto *object = call->getArg(0)->IgnoreParenImpCasts(); + const auto *record = object->getType()->getAsCXXRecordDecl(); + if (record && record->isInStdNamespace() && + (record->getName() == "array" || record->getName() == "vector" || + record->getName() == "basic_string")) { + return object; + } + } + return nullptr; + }; + const auto *container = target; + while (const auto *object = enclosing_target(container)) { + container = object->IgnoreParenImpCasts(); + } + const auto *container_ref = clang::dyn_cast(container); + const auto *container_decl = + container_ref + ? clang::dyn_cast(container_ref->getDecl()) + : nullptr; + bool stable_container = container_decl && !container_decl->isImplicit(); + bool has_subscript = false; + for (auto *part = target; stable_container && part != container;) { + if (const auto *call = clang::dyn_cast(part); + call && call->getOperator() == clang::OO_Subscript) { + has_subscript = true; + stable_container &= + stable_index(stable_index, call->getArg(1), container_decl); + } else if (const auto *element = + clang::dyn_cast(part)) { + stable_container &= + stable_index(stable_index, element->getIdx(), container_decl); + } + part = enclosing_target(part)->IgnoreParenImpCasts(); + } + if (stable_container && has_subscript) { return false; } auto storage_root = [](const clang::Expr *expr) { @@ -5301,6 +5342,14 @@ bool Converter::NeedsAssignmentBinding( !disjoint_members(place)) { return false; } + // A pointer-valued selector cannot overlap a non-character arithmetic + // target in a well-defined program. Still check its base and indices. + if (!clang::isa(place) && + place->getType()->isPointerType() && + lhs->getType()->isArithmeticType() && + !lhs->getType()->isAnyCharacterType()) { + return self(self, place); + } while ( clang::isa(place)) { if (const auto *member = clang::dyn_cast(place); diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index acd839b7eb..838dd980cb 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -1,5 +1,8 @@ // ADDITIONAL_COMPILE_FLAGS: -std=c++17 +#include #include +#include +#include #include #include @@ -267,7 +270,53 @@ void test_static_members() { } #undef TEST_MEMBERS +void test_stable_containers() { + int k = 1; + unsigned char key = 3; + std::vector buf(2, 10); + buf[k] ^= key; + std::array a{10, 20}; + a[k] += 1u; + std::string s = "ab"; + s[k] += 1; + struct Counts { + std::vector counts; + } owner{{10, 20}}; + owner.counts[k] += 1u; + std::vector v(2, 10); + std::vector vector_values(2, 10); + std::vector &vr = vector_values; + vr[k] += 1u; + struct Pair { + unsigned u; + int f; + }; + std::vector ps(2, Pair{10, 20}); + ps[k].u += 1u; + int compound = (v[k] += 1); + int simple = (v[k] = 2); + int member = (ps[k].f = 4); + std::vector> g(2, std::vector(2, 10)); + int nested = (g[k][k] = 5); + unsigned row[2] = {10, 20}; + unsigned *pointers[2] = {row, row}; + unsigned **rows = pointers; + int i = 0, j = 1; + unsigned indirect = (rows[i][j] = 3u); + std::printf("containers %u %u %d %u %u %u %d %d %d %d %u\n", unsigned(buf[k]), + a[k], int(s[k]), owner.counts[k], vr[k], ps[k].u, compound, + simple, member, nested, indirect); + // These two unsafe-model value expressions lacked a result on the base. + auto it = v.begin(); + unsigned iterator_value = (*it += 1u); + std::map m; + m[k] = 10; + unsigned mapped_value = (m[k] += 1u); + std::printf("nonflat values %u %u\n", iterator_value, mapped_value); +} + int main() { + test_stable_containers(); int a[2] = {10, 20}; int index = 1; int value = (a[index] = 99); diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index fb23b7cb79..ebeaf5acbd 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -1836,11 +1836,148 @@ thread_local!( }, ]))); ); +pub fn test_stable_containers_48() { + let k: Value = Rc::new(RefCell::new(1)); + let mut key: u8 = 3_u8; + let mut buf: Vec = vec![10_u8; 2_usize]; + { + let rhs_0 = ((buf[((*k.borrow()) as usize)] as i32) ^ (key as i32)) as u8; + buf[((*k.borrow()) as usize)] = rhs_0 + }; + let a: Value> = Rc::new(RefCell::new(Box::<[u32]>::from([10_u32, 20_u32]))); + { + let rhs_0 = ({ (*a.borrow())[((*k.borrow()) as usize)] }).wrapping_add((1_u32 as u32)); + (*a.borrow_mut())[((*k.borrow()) as usize)] = rhs_0 + }; + let mut s: Vec = { + let mut __bytes = Ptr::::from_string_literal(b"ab").to_c_bytes(); + __bytes.push(0); + __bytes + }; + { + let rhs_0 = ((s[((*k.borrow()) as usize)] as i32) + 1) as i8; + s[((*k.borrow()) as usize)] = rhs_0 + }; + let mut owner: Counts_49 = Counts_49 { + counts: Vec::from([10_u32, 20_u32]), + }; + { + let rhs_0 = (owner.counts[((*k.borrow()) as usize)]).wrapping_add((1_u32 as u32)); + owner.counts[((*k.borrow()) as usize)] = rhs_0 + }; + let v: Value> = Rc::new(RefCell::new(vec![10; 2_usize])); + let vector_values: Value> = Rc::new(RefCell::new(vec![10_u32; 2_usize])); + let vr: Ptr> = vector_values.as_pointer(); + { + let rhs_0 = (index!(vr, ((*k.borrow()) as usize)).read()).wrapping_add((1_u32 as u32)); + index!(vr, ((*k.borrow()) as usize)).write(rhs_0) + }; + let mut ps: Vec = vec![(Pair_50 { u: 10_u32, f: 20 }); 2_usize]; + { + let rhs_0 = (ps[((*k.borrow()) as usize)].u).wrapping_add((1_u32 as u32)); + ps[((*k.borrow()) as usize)].u = rhs_0 + }; + let mut compound: i32 = ({ + (*v.borrow_mut())[((*k.borrow()) as usize)] += 1; + { (*v.borrow())[((*k.borrow()) as usize)] } + }); + let mut simple: i32 = ({ + (*v.borrow_mut())[((*k.borrow()) as usize)] = 2; + { (*v.borrow())[((*k.borrow()) as usize)] } + }); + let mut member: i32 = ({ + ps[((*k.borrow()) as usize)].f = 4; + ps[((*k.borrow()) as usize)].f + }); + let g: Value>> = Rc::new(RefCell::new(vec![vec![10; 2_usize]; 2_usize])); + let mut nested: i32 = ({ + index!( + elem!(g.decay(), ((*k.borrow()) as usize)), + ((*k.borrow()) as usize) + ) + .write(5); + (index!( + elem!(g.decay(), ((*k.borrow()) as usize)), + ((*k.borrow()) as usize) + ) + .read()) + }); + let row: Value> = Rc::new(RefCell::new(Box::new([10_u32, 20_u32]))); + let pointers: Value]>> = + Rc::new(RefCell::new(Box::new([row.decay(), row.decay()]))); + let mut rows: Ptr> = pointers.decay(); + let mut i: i32 = 0; + let mut j: i32 = 1; + let mut indirect: u32 = ({ + elem!((elem!(rows, i).read()), j).write(3_u32); + (elem!((elem!(rows, i).read()), j).read()) + }); + printf!( + b"containers %u %u %d %u %u %u %d %d %d %d %u\n", + (buf[((*k.borrow()) as usize)] as u32), + { (*a.borrow())[((*k.borrow()) as usize)] }, + (s[((*k.borrow()) as usize)] as i32), + owner.counts[((*k.borrow()) as usize)], + (index!(vr, ((*k.borrow()) as usize)).read()), + ps[((*k.borrow()) as usize)].u, + compound, + simple, + member, + nested, + indirect + ); + let it: Value> = Rc::new(RefCell::new(v.decay().begin())); + let mut iterator_value: u32 = (({ + match ({ 1_u32 }, &({ (*it.borrow()).iter_deref() })) { + (__tmp_132, __tmp_133) => __tmp_133.with_mut(|__tmp_133| { + (*__tmp_133) = (((*__tmp_133) as u32).wrapping_add((__tmp_132 as u32))) as i32; + (*__tmp_133).clone() + }), + } + }) as u32); + let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); + ({ (*m.borrow_mut()).subscript(k.as_pointer(), || 0_u32) }).write(10_u32); + let mut mapped_value: u32 = ({ + match ( + { 1_u32 }, + &({ (*m.borrow_mut()).subscript(k.as_pointer(), || 0_u32) }), + ) { + (__tmp_134, __tmp_135) => __tmp_135.with_mut(|__tmp_135| { + (*__tmp_135) = (((*__tmp_135) as u32).wrapping_add((__tmp_134 as u32))) as u32; + (*__tmp_135).clone() + }), + } + }); + printf!(b"nonflat values %u %u\n", iterator_value, mapped_value); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[byte_size(24)] +pub struct Counts_49 { + #[offset(0)] + #[byte_size(24)] + pub counts: Vec, +} +impl Counts_49 { + pub fn move_from(_a0: Ptr) -> Self { + Self { + counts: field!(_a0, counts).with_mut(std::mem::take), + } + } +} +#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct Pair_50 { + #[offset(0)] + pub u: u32, + #[offset(4)] + pub f: i32, +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { + ({ test_stable_containers_48() }); let a: Value> = Rc::new(RefCell::new(Box::new([10, 20]))); let mut index: i32 = 1; let mut value: i32 = ({ @@ -1864,7 +2001,7 @@ fn main_0() -> i32 { (*a.borrow())[(0) as usize], (*a.borrow())[(1) as usize] ); - let mut selector: Index_48 = Index_48 { value: 1 }; + let mut selector: Index_51 = Index_51 { value: 1 }; value = ({ (*a.borrow_mut())[(selector.value) as usize] = 88; (*a.borrow())[(selector.value) as usize] @@ -1885,12 +2022,12 @@ fn main_0() -> i32 { alias.write(0); let __rhs = ({ match ({ 1 }, { - let __tmp_133 = a.decay().offset((alias.read())); - __tmp_133 + let __tmp_137 = a.decay().offset((alias.read())); + __tmp_137 }) { - (__tmp_132, __tmp_133) => __tmp_133.with_mut(|__tmp_133| { - (*__tmp_133) = __tmp_132; - (*__tmp_133).clone() + (__tmp_136, __tmp_137) => __tmp_137.with_mut(|__tmp_137| { + (*__tmp_137) = __tmp_136; + (*__tmp_137).clone() }), } }); @@ -1946,7 +2083,7 @@ fn main_0() -> i32 { deref_value, (*a.borrow())[(1) as usize] ); - let mut owner: Owner_49 = Owner_49 { + let mut owner: Owner_52 = Owner_52 { values: Box::new([0, 20]), index: 0, }; @@ -1955,9 +2092,9 @@ fn main_0() -> i32 { { 1 }, &mut (owner.values[(owner.values[(0) as usize]) as usize]), ) { - (__tmp_134, __tmp_135) => { - (*__tmp_135) = __tmp_134; - (*__tmp_135).clone() + (__tmp_138, __tmp_139) => { + (*__tmp_139) = __tmp_138; + (*__tmp_139).clone() } } }); @@ -1972,16 +2109,16 @@ fn main_0() -> i32 { owner.values[(0) as usize], owner.values[(1) as usize] ); - let alias_selector: Value = Rc::new(RefCell::new(Index_48 { value: 0 })); + let alias_selector: Value = Rc::new(RefCell::new(Index_51 { value: 0 })); let mut member_alias: Ptr = (field_ptr!(alias_selector.as_pointer(), value)); let __rhs = ({ match ({ 1 }, { - let __tmp_137 = member_alias.offset(({ (*alias_selector.borrow()).value }) as isize); - __tmp_137 + let __tmp_141 = member_alias.offset(({ (*alias_selector.borrow()).value }) as isize); + __tmp_141 }) { - (__tmp_136, __tmp_137) => __tmp_137.with_mut(|__tmp_137| { - (*__tmp_137) = __tmp_136; - (*__tmp_137).clone() + (__tmp_140, __tmp_141) => __tmp_141.with_mut(|__tmp_141| { + (*__tmp_141) = __tmp_140; + (*__tmp_141).clone() }), } }); @@ -1993,12 +2130,12 @@ fn main_0() -> i32 { let mut self_: Ptr = (self_index.as_pointer()); let __rhs = ({ match ({ 1 }, { - let __tmp_139 = self_.offset((*self_index.borrow()) as isize); - __tmp_139 + let __tmp_143 = self_.offset((*self_index.borrow()) as isize); + __tmp_143 }) { - (__tmp_138, __tmp_139) => __tmp_139.with_mut(|__tmp_139| { - (*__tmp_139) = __tmp_138; - (*__tmp_139).clone() + (__tmp_142, __tmp_143) => __tmp_143.with_mut(|__tmp_143| { + (*__tmp_143) = __tmp_142; + (*__tmp_143).clone() }), } }); @@ -2014,13 +2151,13 @@ fn main_0() -> i32 { || -> i32 { return ({ match ({ 10000 }, { - let __tmp_141 = + let __tmp_145 = (captured_pointer.read()).offset((captured_index.read()) as isize); - __tmp_141 + __tmp_145 }) { - (__tmp_140, __tmp_141) => __tmp_141.with_mut(|__tmp_141| { - (*__tmp_141) = __tmp_140; - (*__tmp_141).clone() + (__tmp_144, __tmp_145) => __tmp_145.with_mut(|__tmp_145| { + (*__tmp_145) = __tmp_144; + (*__tmp_145).clone() }), } }); @@ -2060,9 +2197,9 @@ fn main_0() -> i32 { 0 )), ) { - (__tmp_142, __tmp_143) => __tmp_143.with_mut(|__tmp_143| { - (*__tmp_143) = (((*__tmp_143) as u32).wrapping_add((__tmp_142 as u32))) as u32; - (*__tmp_143).clone() + (__tmp_146, __tmp_147) => __tmp_147.with_mut(|__tmp_147| { + (*__tmp_147) = (((*__tmp_147) as u32).wrapping_add((__tmp_146 as u32))) as u32; + (*__tmp_147).clone() }), } }); @@ -2079,17 +2216,17 @@ fn main_0() -> i32 { ({ test_boxed_array_39() }); let mut global_result: u32 = ({ match ({ 1_u32 }, { - let __tmp_145 = global_array_41.with(|v| v.decay()).offset( + let __tmp_149 = global_array_41.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; global_array_41.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_145 + __tmp_149 }) { - (__tmp_144, __tmp_145) => __tmp_145.with_mut(|__tmp_145| { - (*__tmp_145) = (((*__tmp_145) as u32).wrapping_add((__tmp_144 as u32))) as u32; - (*__tmp_145).clone() + (__tmp_148, __tmp_149) => __tmp_149.with_mut(|__tmp_149| { + (*__tmp_149) = (((*__tmp_149) as u32).wrapping_add((__tmp_148 as u32))) as u32; + (*__tmp_149).clone() }), } }); @@ -2104,7 +2241,7 @@ fn main_0() -> i32 { i = 0; result = ({ match ({ 1_u32 }, { - let __tmp_147 = global_rows_42 + let __tmp_151 = global_rows_42 .with(|v| v.decay()) .offset( ({ @@ -2115,11 +2252,11 @@ fn main_0() -> i32 { ) .decay() .offset(0); - __tmp_147 + __tmp_151 }) { - (__tmp_146, __tmp_147) => __tmp_147.with_mut(|__tmp_147| { - (*__tmp_147) = (((*__tmp_147) as u32).wrapping_add((__tmp_146 as u32))) as u32; - (*__tmp_147).clone() + (__tmp_150, __tmp_151) => __tmp_151.with_mut(|__tmp_151| { + (*__tmp_151) = (((*__tmp_151) as u32).wrapping_add((__tmp_150 as u32))) as u32; + (*__tmp_151).clone() }), } }); @@ -2142,29 +2279,40 @@ fn main_0() -> i32 { } #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(4)] -pub struct Index_48 { +pub struct Index_51 { #[offset(0)] pub value: i32, } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] #[byte_size(12)] -pub struct Owner_49 { +pub struct Owner_52 { #[offset(0)] #[byte_size(8)] pub values: Box<[i32]>, #[offset(8)] pub index: i32, } -impl Default for Owner_49 { +impl Default for Owner_52 { fn default() -> Self { { - Owner_49 { + Owner_52 { values: (0..2).map(|_| 0_i32).collect::>(), index: 0_i32, } } } } +pub trait Counts_49Impl { + fn move_assign(&self, _a0: Ptr) -> Ptr; +} +impl Counts_49Impl for Ptr { + fn move_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), counts).with_mut(|__b0| { + (*__b0) = field!(_a0, counts).with_mut(std::mem::take); + }); + return (*self).clone(); + } +} pub trait IndexedBindingImpl { fn get_1_0(&self) -> Ptr; } diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 2621bbe4cc..91a55857f7 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -1694,6 +1694,125 @@ static mut a_47: std::cell::LazyCell<[IndexedMember; 2]> = std::cell::LazyCell:: }, ] }); +pub unsafe fn test_stable_containers_48() { + let mut k: i32 = 1; + let mut key: u8 = 3_u8; + let mut buf: Vec = vec![10_u8; 2_usize]; + buf[(k as usize)] = ((buf[(k as usize)] as i32) ^ (key as i32)) as u8; + let mut a: [u32; 2] = [10_u32, 20_u32]; + a[(k as usize)] = (a[(k as usize)]).wrapping_add((1_u32 as u32)); + let mut s: Vec = std::slice::from_raw_parts( + c"ab".as_ptr(), + (0..).take_while(|&i| *c"ab".as_ptr().add(i) != 0).count() + 1, + ) + .to_vec(); + s[(k as usize)] = ((s[(k as usize)] as i32) + 1) as libc::c_char; + let mut owner: Counts_49 = Counts_49 { + counts: Vec::from([10_u32, 20_u32]), + }; + owner.counts[(k as usize)] = (owner.counts[(k as usize)]).wrapping_add((1_u32 as u32)); + let mut v: Vec = vec![10; 2_usize]; + let mut vector_values: Vec = vec![10_u32; 2_usize]; + let vr: *mut Vec = &mut vector_values; + (&mut (*vr))[(k as usize)] = ((&mut (*vr))[(k as usize)]).wrapping_add((1_u32 as u32)); + let mut ps: Vec = vec![(Pair_50 { u: 10_u32, f: 20 }); 2_usize]; + ps[(k as usize)].u = (ps[(k as usize)].u).wrapping_add((1_u32 as u32)); + let mut compound: i32 = ({ + v[(k as usize)] += 1; + v[(k as usize)] + }); + let mut simple: i32 = ({ + v[(k as usize)] = 2; + v[(k as usize)] + }); + let mut member: i32 = ({ + ps[(k as usize)].f = 4; + ps[(k as usize)].f + }); + let mut g: Vec> = vec![vec![10; 2_usize]; 2_usize]; + let mut nested: i32 = ({ + (*{ + let __idx = (k as usize); + &mut g[(k as usize)][__idx] + }) = 5; + (*{ + let __idx = (k as usize); + &mut g[(k as usize)][__idx] + }) + }); + let mut row: [u32; 2] = [10_u32, 20_u32]; + let mut pointers: [*mut u32; 2] = [row.as_mut_ptr(), row.as_mut_ptr()]; + let mut rows: *mut *mut u32 = pointers.as_mut_ptr(); + let mut i: i32 = 0; + let mut j: i32 = 1; + let mut indirect: u32 = ({ + (*(*rows.offset((i) as isize)).offset((j) as isize)) = 3_u32; + (*(*rows.offset((i) as isize)).offset((j) as isize)) + }); + (unsafe { + libc::printf( + c"containers %u %u %d %u %u %u %d %d %d %d %u\n".as_ptr() as *const libc::c_char, + (buf[(k as usize)] as u32), + (a[(k as usize)]), + (s[(k as usize)] as i32), + (owner.counts[(k as usize)]), + ((&mut (*vr))[(k as usize)]), + (ps[(k as usize)].u), + (compound), + (simple), + (member), + (nested), + (indirect), + ) + }); + let mut it: UnsafeRandomAccessIterator = v.begin(); + let mut iterator_value: u32 = ((match ({ 1_u32 }, &mut (*it.iter_deref())) { + (__tmp_136, __tmp_137) => { + (*__tmp_137) = (((*__tmp_137) as u32).wrapping_add((__tmp_136 as u32))) as i32; + (*__tmp_137).clone() + } + }) as u32); + let mut m: UnsafeMap = UnsafeMap::new(); + (*m.subscript(&k, || 0_u32)) = 10_u32; + let mut mapped_value: u32 = (match ({ 1_u32 }, &mut (*m.subscript(&k, || 0_u32))) { + (__tmp_138, __tmp_139) => { + (*__tmp_139) = (((*__tmp_139) as u32).wrapping_add((__tmp_138 as u32))) as u32; + (*__tmp_139).clone() + } + }); + (unsafe { + libc::printf( + c"nonflat values %u %u\n".as_ptr() as *const libc::c_char, + (iterator_value), + (mapped_value), + ) + }); +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, MoveCtorUnsafe, MoveAssignUnsafe, Default)] +pub struct Counts_49 { + pub counts: Vec, +} +impl Counts_49 { + pub unsafe fn move_from(_a0: *mut Counts_49) -> Self { + let mut this = Self { + counts: std::mem::take(&mut (*_a0).counts), + }; + this + } + pub unsafe fn move_assign(&mut self, _a0: *mut Counts_49) -> *mut Counts_49 { + { + self.counts = std::mem::take(&mut (*_a0).counts); + }; + return &mut (*(self as *mut Counts_49)); + } +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Pair_50 { + pub u: u32, + pub f: i32, +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -1701,6 +1820,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { + (unsafe { test_stable_containers_48() }); let mut a: [i32; 2] = [10, 20]; let mut index: i32 = 1; let mut value: i32 = ({ @@ -1728,7 +1848,7 @@ unsafe fn main_0() -> i32 { (a[(1) as usize]), ) }); - let mut selector: Index_48 = Index_48 { value: 1 }; + let mut selector: Index_51 = Index_51 { value: 1 }; value = ({ a[(selector.value) as usize] = 88; a[(selector.value) as usize] @@ -1749,9 +1869,9 @@ unsafe fn main_0() -> i32 { let alias: *mut i32 = &mut a[(0) as usize]; (*alias) = 0; value = (match ({ 1 }, &mut (a[(*alias) as usize])) { - (__tmp_136, __tmp_137) => { - (*__tmp_137) = __tmp_136; - (*__tmp_137).clone() + (__tmp_140, __tmp_141) => { + (*__tmp_141) = __tmp_140; + (*__tmp_141).clone() } }); (unsafe { @@ -1808,7 +1928,7 @@ unsafe fn main_0() -> i32 { (a[(1) as usize]), ) }); - let mut owner: Owner_49 = Owner_49 { + let mut owner: Owner_52 = Owner_52 { values: [0, 20], index: 0, }; @@ -1816,9 +1936,9 @@ unsafe fn main_0() -> i32 { { 1 }, &mut (owner.values[(owner.values[(0) as usize]) as usize]), ) { - (__tmp_138, __tmp_139) => { - (*__tmp_139) = __tmp_138; - (*__tmp_139).clone() + (__tmp_142, __tmp_143) => { + (*__tmp_143) = __tmp_142; + (*__tmp_143).clone() } }); reference_value = ({ @@ -1834,15 +1954,15 @@ unsafe fn main_0() -> i32 { (owner.values[(1) as usize]), ) }); - let mut alias_selector: Index_48 = Index_48 { value: 0 }; + let mut alias_selector: Index_51 = Index_51 { value: 0 }; let mut member_alias: *mut i32 = (&mut alias_selector.value as *mut i32); value = (match ( { 1 }, &mut (*member_alias.offset((alias_selector.value) as isize)), ) { - (__tmp_140, __tmp_141) => { - (*__tmp_141) = __tmp_140; - (*__tmp_141).clone() + (__tmp_144, __tmp_145) => { + (*__tmp_145) = __tmp_144; + (*__tmp_145).clone() } }); (unsafe { @@ -1855,9 +1975,9 @@ unsafe fn main_0() -> i32 { let mut self_index: i32 = 0; let mut self_: *mut i32 = (&mut self_index as *mut i32); value = (match ({ 1 }, &mut (*self_.offset((self_index) as isize))) { - (__tmp_142, __tmp_143) => { - (*__tmp_143) = __tmp_142; - (*__tmp_143).clone() + (__tmp_146, __tmp_147) => { + (*__tmp_147) = __tmp_146; + (*__tmp_147).clone() } }); (unsafe { @@ -1879,9 +1999,9 @@ unsafe fn main_0() -> i32 { { 10000 }, &mut (*(*captured_pointer).offset((*captured_index) as isize)), ) { - (__tmp_144, __tmp_145) => { - (*__tmp_145) = __tmp_144; - (*__tmp_145).clone() + (__tmp_148, __tmp_149) => { + (*__tmp_149) = __tmp_148; + (*__tmp_149).clone() } }); } @@ -1918,9 +2038,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_146, __tmp_147) => { - (*__tmp_147) = (((*__tmp_147) as u32).wrapping_add((__tmp_146 as u32))) as u32; - (*__tmp_147).clone() + (__tmp_150, __tmp_151) => { + (*__tmp_151) = (((*__tmp_151) as u32).wrapping_add((__tmp_150 as u32))) as u32; + (*__tmp_151).clone() } }); (unsafe { @@ -1942,9 +2062,9 @@ unsafe fn main_0() -> i32 { [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_41))[(0) as usize]) as usize]), ) { - (__tmp_148, __tmp_149) => { - (*__tmp_149) = (((*__tmp_149) as u32).wrapping_add((__tmp_148 as u32))) as u32; - (*__tmp_149).clone() + (__tmp_152, __tmp_153) => { + (*__tmp_153) = (((*__tmp_153) as u32).wrapping_add((__tmp_152 as u32))) as u32; + (*__tmp_153).clone() } }); (unsafe { @@ -1961,9 +2081,9 @@ unsafe fn main_0() -> i32 { [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_42)) [(i.postfix_inc()) as usize][(0) as usize]) as usize][(0) as usize]), ) { - (__tmp_150, __tmp_151) => { - (*__tmp_151) = (((*__tmp_151) as u32).wrapping_add((__tmp_150 as u32))) as u32; - (*__tmp_151).clone() + (__tmp_154, __tmp_155) => { + (*__tmp_155) = (((*__tmp_155) as u32).wrapping_add((__tmp_154 as u32))) as u32; + (*__tmp_155).clone() } }); (unsafe { @@ -1981,12 +2101,12 @@ unsafe fn main_0() -> i32 { } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Index_48 { +pub struct Index_51 { pub value: i32, } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Owner_49 { +pub struct Owner_52 { pub values: [i32; 2], pub index: i32, } From 6035b1c965c4086c7709afb20ded846062794b03 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Sat, 28 Nov 2026 21:19:51 +0000 Subject: [PATCH 17/25] Retain conservative bindings for nonlocal pointer selectors Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 3 +- tests/unit/assignment_single_eval.cpp | 19 + .../out/refcount/assignment_single_eval.rs | 417 +++++++++++------- .../unit/out/unsafe/assignment_single_eval.rs | 317 ++++++++----- 4 files changed, 489 insertions(+), 267 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index d68272ef1e..824029e7dd 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -5328,7 +5328,8 @@ bool Converter::NeedsAssignmentBinding( } if (const auto *ref = clang::dyn_cast(stmt)) { const auto *decl = clang::dyn_cast(ref->getDecl()); - if (!decl || decl->isImplicit()) { + if (!decl || decl->isImplicit() || !curr_function_ || + decl->getDeclContext() != curr_function_ || IsGlobalVar(decl)) { return false; } } diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index 838dd980cb..0d66e1bc55 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -270,6 +270,24 @@ void test_static_members() { } #undef TEST_MEMBERS +unsigned scoped_values[2] = {10, 20}; +unsigned *scoped_pointers[1] = {scoped_values}; +struct PointerSelector { + unsigned *ptr; +}; +PointerSelector scoped_record{scoped_values}; + +void test_scoped_pointer_selectors() { + int i = 0, j = 1; + unsigned a = (scoped_pointers[i][j] = 3u); + static unsigned *saved[1] = {scoped_values}; + unsigned b = (saved[i][j] = 4u); + unsigned c = (scoped_record.ptr[j] = 5u); + static PointerSelector saved_record{scoped_values}; + unsigned d = (saved_record.ptr[j] = 6u); + std::printf("scoped pointers %u %u %u %u %u\n", a, b, c, d, scoped_values[j]); +} + void test_stable_containers() { int k = 1; unsigned char key = 3; @@ -317,6 +335,7 @@ void test_stable_containers() { int main() { test_stable_containers(); + test_scoped_pointer_selectors(); int a[2] = {10, 20}; int index = 1; int value = (a[index] = 99); diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index ebeaf5acbd..a830e99cf1 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -1082,20 +1082,27 @@ pub fn test_borrows_25() { b"%d\n", ({ observe_record_22({ - (*global_record_21.with(Value::clone).borrow_mut()) - .inner - .value = 99; - { global_record_21.with(|rc| *rc.borrow()).inner.value } + match ( + { 99 }, + &mut ((*global_record_21.with(Value::clone).borrow_mut()) + .inner + .value), + ) { + (__tmp_92, __tmp_93) => { + (*__tmp_93) = __tmp_92; + (*__tmp_93).clone() + } + } }) }) ); let mut shifted: Ptr = ({ - let __tmp_92 = { + let __tmp_94 = { cursor_24 .with(|rc| *rc.borrow_mut() = targets_23.with(|v| v.decay()).offset((1) as isize)); 1 }; - cursor_24.with(|rc| *rc.borrow_mut() -= (__tmp_92 as isize)); + cursor_24.with(|rc| *rc.borrow_mut() -= (__tmp_94 as isize)); (*cursor_24.with(Value::clone).borrow()).clone() }); printf!( @@ -1164,9 +1171,9 @@ pub fn test_borrows_25() { { (second.as_pointer()) }, &(field!((selector.read()), next)), ) { - (__tmp_93, __tmp_94) => __tmp_94.with_mut(|__tmp_94| { - (*__tmp_94) = __tmp_93; - (*__tmp_94).clone() + (__tmp_95, __tmp_96) => __tmp_96.with_mut(|__tmp_96| { + (*__tmp_96) = __tmp_95; + (*__tmp_96).clone() }), } }); @@ -1231,9 +1238,9 @@ pub fn test_binding_31() { let value: Ptr = ({ IndexedBindingImpl::get_1_0(&__decomp_32) }); let mut result: u32 = ({ match ({ 1_u32 }, &({ IndexedBindingImpl::get_1_0(&__decomp_32) })) { - (__tmp_95, __tmp_96) => __tmp_96.with_mut(|__tmp_96| { - (*__tmp_96) = (((*__tmp_96) as u32).wrapping_add((__tmp_95 as u32))) as u32; - (*__tmp_96).clone() + (__tmp_97, __tmp_98) => __tmp_98.with_mut(|__tmp_98| { + (*__tmp_98) = (((*__tmp_98) as u32).wrapping_add((__tmp_97 as u32))) as u32; + (*__tmp_98).clone() }), } }); @@ -1256,10 +1263,10 @@ pub fn mutate_initializer_34() -> u32 { thread_local!( pub static initializer_result_35: Value = Rc::new(RefCell::new( ({ - let __tmp_97 = ({ mutate_initializer_34() }); + let __tmp_99 = ({ mutate_initializer_34() }); { let rhs_0 = ((initializer_target_33.with(|rc| *rc.borrow()) as u32) - .wrapping_add((__tmp_97 as u32))) as u32; + .wrapping_add((__tmp_99 as u32))) as u32; { let __rhs = rhs_0; initializer_target_33.with(|rc| *rc.borrow_mut() = __rhs) @@ -1282,9 +1289,9 @@ pub fn test_alias_scopes_36(parameter: i16) { }, &mut (*parameter.borrow_mut()), ) { - (__tmp_98, __tmp_99) => { - (*__tmp_99) = (((*__tmp_99) as f64) + (__tmp_98 as f64)) as i16; - (*__tmp_99).clone() + (__tmp_100, __tmp_101) => { + (*__tmp_101) = (((*__tmp_101) as f64) + (__tmp_100 as f64)) as i16; + (*__tmp_101).clone() } } }); @@ -1308,9 +1315,9 @@ pub fn test_alias_scopes_36(parameter: i16) { { ({ (*mutate.borrow()).call() }).clone() }, &mut (*local.borrow_mut()), ) { - (__tmp_100, __tmp_101) => { - (*__tmp_101) = (((*__tmp_101) as f64) + (__tmp_100 as f64)) as i16; - (*__tmp_101).clone() + (__tmp_102, __tmp_103) => { + (*__tmp_103) = (((*__tmp_103) as f64) + (__tmp_102 as f64)) as i16; + (*__tmp_103).clone() } } }); @@ -1331,12 +1338,12 @@ pub fn test_boxed_array_37() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_103 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_103 + let __tmp_105 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_105 }) { - (__tmp_102, __tmp_103) => __tmp_103.with_mut(|__tmp_103| { - (*__tmp_103) = (((*__tmp_103) as u32).wrapping_add((__tmp_102 as u32))) as u32; - (*__tmp_103).clone() + (__tmp_104, __tmp_105) => __tmp_105.with_mut(|__tmp_105| { + (*__tmp_105) = (((*__tmp_105) as u32).wrapping_add((__tmp_104 as u32))) as u32; + (*__tmp_105).clone() }), } }); @@ -1351,12 +1358,12 @@ pub fn test_boxed_array_37() { i = 0; result = ({ match ({ 1_u32 }, { - let __tmp_105 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_105 + let __tmp_107 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_107 }) { - (__tmp_104, __tmp_105) => __tmp_105.with_mut(|__tmp_105| { - (*__tmp_105) = __tmp_104; - (*__tmp_105).clone() + (__tmp_106, __tmp_107) => __tmp_107.with_mut(|__tmp_107| { + (*__tmp_107) = __tmp_106; + (*__tmp_107).clone() }), } }); @@ -1369,17 +1376,17 @@ pub fn test_boxed_array_37() { ); result = ({ match ({ 1_u32 }, { - let __tmp_107 = saved_38.with(|v| v.decay()).offset( + let __tmp_109 = saved_38.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; saved_38.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_107 + __tmp_109 }) { - (__tmp_106, __tmp_107) => __tmp_107.with_mut(|__tmp_107| { - (*__tmp_107) = (((*__tmp_107) as u32).wrapping_add((__tmp_106 as u32))) as u32; - (*__tmp_107).clone() + (__tmp_108, __tmp_109) => __tmp_109.with_mut(|__tmp_109| { + (*__tmp_109) = (((*__tmp_109) as u32).wrapping_add((__tmp_108 as u32))) as u32; + (*__tmp_109).clone() }), } }); @@ -1398,12 +1405,12 @@ pub fn test_boxed_array_39() { let mut i: i32 = 0; let mut result: i16 = ({ match ({ 1 }, { - let __tmp_109 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_109 + let __tmp_111 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_111 }) { - (__tmp_108, __tmp_109) => __tmp_109.with_mut(|__tmp_109| { - (*__tmp_109) = (((*__tmp_109) as i32) + (__tmp_108 as i32)) as i16; - (*__tmp_109).clone() + (__tmp_110, __tmp_111) => __tmp_111.with_mut(|__tmp_111| { + (*__tmp_111) = (((*__tmp_111) as i32) + (__tmp_110 as i32)) as i16; + (*__tmp_111).clone() }), } }); @@ -1418,12 +1425,12 @@ pub fn test_boxed_array_39() { i = 0; result = ({ match ({ 1_i16 }, { - let __tmp_111 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_111 + let __tmp_113 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); + __tmp_113 }) { - (__tmp_110, __tmp_111) => __tmp_111.with_mut(|__tmp_111| { - (*__tmp_111) = __tmp_110; - (*__tmp_111).clone() + (__tmp_112, __tmp_113) => __tmp_113.with_mut(|__tmp_113| { + (*__tmp_113) = __tmp_112; + (*__tmp_113).clone() }), } }); @@ -1436,17 +1443,17 @@ pub fn test_boxed_array_39() { ); result = ({ match ({ 1 }, { - let __tmp_113 = saved_40.with(|v| v.decay()).offset( + let __tmp_115 = saved_40.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; saved_40.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_113 + __tmp_115 }) { - (__tmp_112, __tmp_113) => __tmp_113.with_mut(|__tmp_113| { - (*__tmp_113) = (((*__tmp_113) as i32) + (__tmp_112 as i32)) as i16; - (*__tmp_113).clone() + (__tmp_114, __tmp_115) => __tmp_115.with_mut(|__tmp_115| { + (*__tmp_115) = (((*__tmp_115) as i32) + (__tmp_114 as i32)) as i16; + (*__tmp_115).clone() }), } }); @@ -1516,16 +1523,16 @@ pub fn test_local_members_44() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_115 = field_ptr!( + let __tmp_117 = field_ptr!( a.decay() .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), value ); - __tmp_115 + __tmp_117 }) { - (__tmp_114, __tmp_115) => __tmp_115.with_mut(|__tmp_115| { - (*__tmp_115) = (((*__tmp_115) as u32).wrapping_add((__tmp_114 as u32))) as u32; - (*__tmp_115).clone() + (__tmp_116, __tmp_117) => __tmp_117.with_mut(|__tmp_117| { + (*__tmp_117) = (((*__tmp_117) as u32).wrapping_add((__tmp_116 as u32))) as u32; + (*__tmp_117).clone() }), } }); @@ -1539,15 +1546,15 @@ pub fn test_local_members_44() { i = 0; { match ({ 1 }, { - let __tmp_117 = field_ptr!( + let __tmp_119 = field_ptr!( a.decay() .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), promoted ); - __tmp_117 + __tmp_119 }) { - (__tmp_116, __tmp_117) => __tmp_117.with_mut(|__tmp_117| { - (*__tmp_117) = (((*__tmp_117) as i32) + (__tmp_116 as i32)) as i16; + (__tmp_118, __tmp_119) => __tmp_119.with_mut(|__tmp_119| { + (*__tmp_119) = (((*__tmp_119) as i32) + (__tmp_118 as i32)) as i16; }), } }; @@ -1560,16 +1567,16 @@ pub fn test_local_members_44() { i = 0; result = ({ match ({ 99_u32 }, { - let __tmp_119 = field_ptr!( + let __tmp_121 = field_ptr!( a.decay() .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), value ); - __tmp_119 + __tmp_121 }) { - (__tmp_118, __tmp_119) => __tmp_119.with_mut(|__tmp_119| { - (*__tmp_119) = __tmp_118; - (*__tmp_119).clone() + (__tmp_120, __tmp_121) => __tmp_121.with_mut(|__tmp_121| { + (*__tmp_121) = __tmp_120; + (*__tmp_121).clone() }), } }); @@ -1586,7 +1593,7 @@ pub fn test_global_members_45() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_121 = field_ptr!( + let __tmp_123 = field_ptr!( global_members_43.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; @@ -1596,11 +1603,11 @@ pub fn test_global_members_45() { }), value ); - __tmp_121 + __tmp_123 }) { - (__tmp_120, __tmp_121) => __tmp_121.with_mut(|__tmp_121| { - (*__tmp_121) = (((*__tmp_121) as u32).wrapping_add((__tmp_120 as u32))) as u32; - (*__tmp_121).clone() + (__tmp_122, __tmp_123) => __tmp_123.with_mut(|__tmp_123| { + (*__tmp_123) = (((*__tmp_123) as u32).wrapping_add((__tmp_122 as u32))) as u32; + (*__tmp_123).clone() }), } }); @@ -1626,7 +1633,7 @@ pub fn test_global_members_45() { i = 0; { match ({ 1 }, { - let __tmp_123 = field_ptr!( + let __tmp_125 = field_ptr!( global_members_43.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; @@ -1636,10 +1643,10 @@ pub fn test_global_members_45() { }), promoted ); - __tmp_123 + __tmp_125 }) { - (__tmp_122, __tmp_123) => __tmp_123.with_mut(|__tmp_123| { - (*__tmp_123) = (((*__tmp_123) as i32) + (__tmp_122 as i32)) as i16; + (__tmp_124, __tmp_125) => __tmp_125.with_mut(|__tmp_125| { + (*__tmp_125) = (((*__tmp_125) as i32) + (__tmp_124 as i32)) as i16; }), } }; @@ -1664,7 +1671,7 @@ pub fn test_global_members_45() { i = 0; result = ({ match ({ 99_u32 }, { - let __tmp_125 = field_ptr!( + let __tmp_127 = field_ptr!( global_members_43.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; @@ -1674,11 +1681,11 @@ pub fn test_global_members_45() { }), value ); - __tmp_125 + __tmp_127 }) { - (__tmp_124, __tmp_125) => __tmp_125.with_mut(|__tmp_125| { - (*__tmp_125) = __tmp_124; - (*__tmp_125).clone() + (__tmp_126, __tmp_127) => __tmp_127.with_mut(|__tmp_127| { + (*__tmp_127) = __tmp_126; + (*__tmp_127).clone() }), } }); @@ -1706,7 +1713,7 @@ pub fn test_static_members_46() { let mut i: i32 = 0; let mut result: u32 = ({ match ({ 1_u32 }, { - let __tmp_127 = field_ptr!( + let __tmp_129 = field_ptr!( a_47.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; @@ -1716,11 +1723,11 @@ pub fn test_static_members_46() { }), value ); - __tmp_127 + __tmp_129 }) { - (__tmp_126, __tmp_127) => __tmp_127.with_mut(|__tmp_127| { - (*__tmp_127) = (((*__tmp_127) as u32).wrapping_add((__tmp_126 as u32))) as u32; - (*__tmp_127).clone() + (__tmp_128, __tmp_129) => __tmp_129.with_mut(|__tmp_129| { + (*__tmp_129) = (((*__tmp_129) as u32).wrapping_add((__tmp_128 as u32))) as u32; + (*__tmp_129).clone() }), } }); @@ -1746,7 +1753,7 @@ pub fn test_static_members_46() { i = 0; { match ({ 1 }, { - let __tmp_129 = field_ptr!( + let __tmp_131 = field_ptr!( a_47.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; @@ -1756,10 +1763,10 @@ pub fn test_static_members_46() { }), promoted ); - __tmp_129 + __tmp_131 }) { - (__tmp_128, __tmp_129) => __tmp_129.with_mut(|__tmp_129| { - (*__tmp_129) = (((*__tmp_129) as i32) + (__tmp_128 as i32)) as i16; + (__tmp_130, __tmp_131) => __tmp_131.with_mut(|__tmp_131| { + (*__tmp_131) = (((*__tmp_131) as i32) + (__tmp_130 as i32)) as i16; }), } }; @@ -1784,7 +1791,7 @@ pub fn test_static_members_46() { i = 0; result = ({ match ({ 99_u32 }, { - let __tmp_131 = field_ptr!( + let __tmp_133 = field_ptr!( a_47.with(|v| v.decay()).offset({ ({ let __idx0 = (i.postfix_inc()) as usize; @@ -1794,11 +1801,11 @@ pub fn test_static_members_46() { }), value ); - __tmp_131 + __tmp_133 }) { - (__tmp_130, __tmp_131) => __tmp_131.with_mut(|__tmp_131| { - (*__tmp_131) = __tmp_130; - (*__tmp_131).clone() + (__tmp_132, __tmp_133) => __tmp_133.with_mut(|__tmp_133| { + (*__tmp_133) = __tmp_132; + (*__tmp_133).clone() }), } }); @@ -1836,7 +1843,107 @@ thread_local!( }, ]))); ); -pub fn test_stable_containers_48() { +thread_local!( + pub static scoped_values_48: Value> = + Rc::new(RefCell::new(Box::new([10_u32, 20_u32]))); +); +thread_local!( + pub static scoped_pointers_49: Value]>> = Rc::new(RefCell::new(Box::new([ + scoped_values_48.with(|v| v.decay()), + ]))); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct PointerSelector { + #[offset(0)] + #[byte_size(8)] + pub ptr: Ptr, +} +thread_local!( + pub static scoped_record_50: Value = Rc::new(RefCell::new(PointerSelector { + ptr: scoped_values_48.with(|v| v.decay()), + })); +); +pub fn test_scoped_pointer_selectors_51() { + let mut i: i32 = 0; + let mut j: i32 = 1; + let mut a: u32 = ({ + match ({ 3_u32 }, { + let __tmp_135 = ({ + let __idx0 = (i) as usize; + scoped_pointers_49.with(|rc| rc.borrow()[__idx0].clone()) + }) + .offset((j) as isize); + __tmp_135 + }) { + (__tmp_134, __tmp_135) => __tmp_135.with_mut(|__tmp_135| { + (*__tmp_135) = __tmp_134; + (*__tmp_135).clone() + }), + } + }); + let mut b: u32 = ({ + match ({ 4_u32 }, { + let __tmp_137 = ({ + let __idx0 = (i) as usize; + saved_52.with(|rc| rc.borrow()[__idx0].clone()) + }) + .offset((j) as isize); + __tmp_137 + }) { + (__tmp_136, __tmp_137) => __tmp_137.with_mut(|__tmp_137| { + (*__tmp_137) = __tmp_136; + (*__tmp_137).clone() + }), + } + }); + let mut c: u32 = ({ + match ({ 5_u32 }, { + let __tmp_139 = { (*scoped_record_50.with(Value::clone).borrow()).ptr.clone() } + .offset((j) as isize); + __tmp_139 + }) { + (__tmp_138, __tmp_139) => __tmp_139.with_mut(|__tmp_139| { + (*__tmp_139) = __tmp_138; + (*__tmp_139).clone() + }), + } + }); + let mut d: u32 = ({ + match ({ 6_u32 }, { + let __tmp_141 = + { (*saved_record_53.with(Value::clone).borrow()).ptr.clone() }.offset((j) as isize); + __tmp_141 + }) { + (__tmp_140, __tmp_141) => __tmp_141.with_mut(|__tmp_141| { + (*__tmp_141) = __tmp_140; + (*__tmp_141).clone() + }), + } + }); + printf!( + b"scoped pointers %u %u %u %u %u\n", + a, + b, + c, + d, + ({ + let __idx0 = (j) as usize; + scoped_values_48.with(|rc| rc.borrow()[__idx0]) + }) + ); +} +thread_local!( + static saved_52: Value]>> = Rc::new(RefCell::new(Box::new([ + scoped_values_48.with(|v| v.decay()) + ]))); +); +thread_local!( + static saved_record_53: Value = Rc::new(RefCell::new(PointerSelector { + ptr: scoped_values_48.with(|v| v.decay()), + })); +); +pub fn test_stable_containers_54() { let k: Value = Rc::new(RefCell::new(1)); let mut key: u8 = 3_u8; let mut buf: Vec = vec![10_u8; 2_usize]; @@ -1858,7 +1965,7 @@ pub fn test_stable_containers_48() { let rhs_0 = ((s[((*k.borrow()) as usize)] as i32) + 1) as i8; s[((*k.borrow()) as usize)] = rhs_0 }; - let mut owner: Counts_49 = Counts_49 { + let mut owner: Counts_55 = Counts_55 { counts: Vec::from([10_u32, 20_u32]), }; { @@ -1872,7 +1979,7 @@ pub fn test_stable_containers_48() { let rhs_0 = (index!(vr, ((*k.borrow()) as usize)).read()).wrapping_add((1_u32 as u32)); index!(vr, ((*k.borrow()) as usize)).write(rhs_0) }; - let mut ps: Vec = vec![(Pair_50 { u: 10_u32, f: 20 }); 2_usize]; + let mut ps: Vec = vec![(Pair_56 { u: 10_u32, f: 20 }); 2_usize]; { let rhs_0 = (ps[((*k.borrow()) as usize)].u).wrapping_add((1_u32 as u32)); ps[((*k.borrow()) as usize)].u = rhs_0 @@ -1929,9 +2036,9 @@ pub fn test_stable_containers_48() { let it: Value> = Rc::new(RefCell::new(v.decay().begin())); let mut iterator_value: u32 = (({ match ({ 1_u32 }, &({ (*it.borrow()).iter_deref() })) { - (__tmp_132, __tmp_133) => __tmp_133.with_mut(|__tmp_133| { - (*__tmp_133) = (((*__tmp_133) as u32).wrapping_add((__tmp_132 as u32))) as i32; - (*__tmp_133).clone() + (__tmp_142, __tmp_143) => __tmp_143.with_mut(|__tmp_143| { + (*__tmp_143) = (((*__tmp_143) as u32).wrapping_add((__tmp_142 as u32))) as i32; + (*__tmp_143).clone() }), } }) as u32); @@ -1942,9 +2049,9 @@ pub fn test_stable_containers_48() { { 1_u32 }, &({ (*m.borrow_mut()).subscript(k.as_pointer(), || 0_u32) }), ) { - (__tmp_134, __tmp_135) => __tmp_135.with_mut(|__tmp_135| { - (*__tmp_135) = (((*__tmp_135) as u32).wrapping_add((__tmp_134 as u32))) as u32; - (*__tmp_135).clone() + (__tmp_144, __tmp_145) => __tmp_145.with_mut(|__tmp_145| { + (*__tmp_145) = (((*__tmp_145) as u32).wrapping_add((__tmp_144 as u32))) as u32; + (*__tmp_145).clone() }), } }); @@ -1952,13 +2059,13 @@ pub fn test_stable_containers_48() { } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] #[byte_size(24)] -pub struct Counts_49 { +pub struct Counts_55 { #[offset(0)] #[byte_size(24)] pub counts: Vec, } -impl Counts_49 { - pub fn move_from(_a0: Ptr) -> Self { +impl Counts_55 { + pub fn move_from(_a0: Ptr) -> Self { Self { counts: field!(_a0, counts).with_mut(std::mem::take), } @@ -1966,7 +2073,7 @@ impl Counts_49 { } #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(8)] -pub struct Pair_50 { +pub struct Pair_56 { #[offset(0)] pub u: u32, #[offset(4)] @@ -1977,7 +2084,8 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ test_stable_containers_48() }); + ({ test_stable_containers_54() }); + ({ test_scoped_pointer_selectors_51() }); let a: Value> = Rc::new(RefCell::new(Box::new([10, 20]))); let mut index: i32 = 1; let mut value: i32 = ({ @@ -2001,7 +2109,7 @@ fn main_0() -> i32 { (*a.borrow())[(0) as usize], (*a.borrow())[(1) as usize] ); - let mut selector: Index_51 = Index_51 { value: 1 }; + let mut selector: Index_57 = Index_57 { value: 1 }; value = ({ (*a.borrow_mut())[(selector.value) as usize] = 88; (*a.borrow())[(selector.value) as usize] @@ -2022,12 +2130,12 @@ fn main_0() -> i32 { alias.write(0); let __rhs = ({ match ({ 1 }, { - let __tmp_137 = a.decay().offset((alias.read())); - __tmp_137 + let __tmp_147 = a.decay().offset((alias.read())); + __tmp_147 }) { - (__tmp_136, __tmp_137) => __tmp_137.with_mut(|__tmp_137| { - (*__tmp_137) = __tmp_136; - (*__tmp_137).clone() + (__tmp_146, __tmp_147) => __tmp_147.with_mut(|__tmp_147| { + (*__tmp_147) = __tmp_146; + (*__tmp_147).clone() }), } }); @@ -2083,7 +2191,7 @@ fn main_0() -> i32 { deref_value, (*a.borrow())[(1) as usize] ); - let mut owner: Owner_52 = Owner_52 { + let mut owner: Owner_58 = Owner_58 { values: Box::new([0, 20]), index: 0, }; @@ -2092,9 +2200,9 @@ fn main_0() -> i32 { { 1 }, &mut (owner.values[(owner.values[(0) as usize]) as usize]), ) { - (__tmp_138, __tmp_139) => { - (*__tmp_139) = __tmp_138; - (*__tmp_139).clone() + (__tmp_148, __tmp_149) => { + (*__tmp_149) = __tmp_148; + (*__tmp_149).clone() } } }); @@ -2109,16 +2217,16 @@ fn main_0() -> i32 { owner.values[(0) as usize], owner.values[(1) as usize] ); - let alias_selector: Value = Rc::new(RefCell::new(Index_51 { value: 0 })); + let alias_selector: Value = Rc::new(RefCell::new(Index_57 { value: 0 })); let mut member_alias: Ptr = (field_ptr!(alias_selector.as_pointer(), value)); let __rhs = ({ match ({ 1 }, { - let __tmp_141 = member_alias.offset(({ (*alias_selector.borrow()).value }) as isize); - __tmp_141 + let __tmp_151 = member_alias.offset(({ (*alias_selector.borrow()).value }) as isize); + __tmp_151 }) { - (__tmp_140, __tmp_141) => __tmp_141.with_mut(|__tmp_141| { - (*__tmp_141) = __tmp_140; - (*__tmp_141).clone() + (__tmp_150, __tmp_151) => __tmp_151.with_mut(|__tmp_151| { + (*__tmp_151) = __tmp_150; + (*__tmp_151).clone() }), } }); @@ -2130,12 +2238,12 @@ fn main_0() -> i32 { let mut self_: Ptr = (self_index.as_pointer()); let __rhs = ({ match ({ 1 }, { - let __tmp_143 = self_.offset((*self_index.borrow()) as isize); - __tmp_143 + let __tmp_153 = self_.offset((*self_index.borrow()) as isize); + __tmp_153 }) { - (__tmp_142, __tmp_143) => __tmp_143.with_mut(|__tmp_143| { - (*__tmp_143) = __tmp_142; - (*__tmp_143).clone() + (__tmp_152, __tmp_153) => __tmp_153.with_mut(|__tmp_153| { + (*__tmp_153) = __tmp_152; + (*__tmp_153).clone() }), } }); @@ -2151,13 +2259,13 @@ fn main_0() -> i32 { || -> i32 { return ({ match ({ 10000 }, { - let __tmp_145 = + let __tmp_155 = (captured_pointer.read()).offset((captured_index.read()) as isize); - __tmp_145 + __tmp_155 }) { - (__tmp_144, __tmp_145) => __tmp_145.with_mut(|__tmp_145| { - (*__tmp_145) = __tmp_144; - (*__tmp_145).clone() + (__tmp_154, __tmp_155) => __tmp_155.with_mut(|__tmp_155| { + (*__tmp_155) = __tmp_154; + (*__tmp_155).clone() }), } }); @@ -2197,9 +2305,9 @@ fn main_0() -> i32 { 0 )), ) { - (__tmp_146, __tmp_147) => __tmp_147.with_mut(|__tmp_147| { - (*__tmp_147) = (((*__tmp_147) as u32).wrapping_add((__tmp_146 as u32))) as u32; - (*__tmp_147).clone() + (__tmp_156, __tmp_157) => __tmp_157.with_mut(|__tmp_157| { + (*__tmp_157) = (((*__tmp_157) as u32).wrapping_add((__tmp_156 as u32))) as u32; + (*__tmp_157).clone() }), } }); @@ -2216,17 +2324,17 @@ fn main_0() -> i32 { ({ test_boxed_array_39() }); let mut global_result: u32 = ({ match ({ 1_u32 }, { - let __tmp_149 = global_array_41.with(|v| v.decay()).offset( + let __tmp_159 = global_array_41.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; global_array_41.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_149 + __tmp_159 }) { - (__tmp_148, __tmp_149) => __tmp_149.with_mut(|__tmp_149| { - (*__tmp_149) = (((*__tmp_149) as u32).wrapping_add((__tmp_148 as u32))) as u32; - (*__tmp_149).clone() + (__tmp_158, __tmp_159) => __tmp_159.with_mut(|__tmp_159| { + (*__tmp_159) = (((*__tmp_159) as u32).wrapping_add((__tmp_158 as u32))) as u32; + (*__tmp_159).clone() }), } }); @@ -2241,7 +2349,7 @@ fn main_0() -> i32 { i = 0; result = ({ match ({ 1_u32 }, { - let __tmp_151 = global_rows_42 + let __tmp_161 = global_rows_42 .with(|v| v.decay()) .offset( ({ @@ -2252,11 +2360,11 @@ fn main_0() -> i32 { ) .decay() .offset(0); - __tmp_151 + __tmp_161 }) { - (__tmp_150, __tmp_151) => __tmp_151.with_mut(|__tmp_151| { - (*__tmp_151) = (((*__tmp_151) as u32).wrapping_add((__tmp_150 as u32))) as u32; - (*__tmp_151).clone() + (__tmp_160, __tmp_161) => __tmp_161.with_mut(|__tmp_161| { + (*__tmp_161) = (((*__tmp_161) as u32).wrapping_add((__tmp_160 as u32))) as u32; + (*__tmp_161).clone() }), } }); @@ -2279,34 +2387,34 @@ fn main_0() -> i32 { } #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(4)] -pub struct Index_51 { +pub struct Index_57 { #[offset(0)] pub value: i32, } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] #[byte_size(12)] -pub struct Owner_52 { +pub struct Owner_58 { #[offset(0)] #[byte_size(8)] pub values: Box<[i32]>, #[offset(8)] pub index: i32, } -impl Default for Owner_52 { +impl Default for Owner_58 { fn default() -> Self { { - Owner_52 { + Owner_58 { values: (0..2).map(|_| 0_i32).collect::>(), index: 0_i32, } } } } -pub trait Counts_49Impl { - fn move_assign(&self, _a0: Ptr) -> Ptr; +pub trait Counts_55Impl { + fn move_assign(&self, _a0: Ptr) -> Ptr; } -impl Counts_49Impl for Ptr { - fn move_assign(&self, _a0: Ptr) -> Ptr { +impl Counts_55Impl for Ptr { + fn move_assign(&self, _a0: Ptr) -> Ptr { field!((*self), counts).with_mut(|__b0| { (*__b0) = field!(_a0, counts).with_mut(std::mem::take); }); @@ -2337,4 +2445,7 @@ pub fn __cpp2rust_init_globals() { let _ = global_array_41.with(|_| ()); let _ = global_rows_42.with(|_| ()); let _ = global_members_43.with(|_| ()); + let _ = scoped_values_48.with(|_| ()); + let _ = scoped_pointers_49.with(|_| ()); + let _ = scoped_record_50.with(|_| ()); } diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 91a55857f7..a5e8439bde 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -1056,14 +1056,19 @@ pub unsafe fn test_borrows_25() { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, (unsafe { - observe_record_22({ - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_21)) - .inner - .value = 99; - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_21)) - .inner - .value - }) + observe_record_22( + match ( + { 99 }, + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_21)) + .inner + .value), + ) { + (__tmp_94, __tmp_95) => { + (*__tmp_95) = __tmp_94; + (*__tmp_95).clone() + } + }, + ) }), ) }); @@ -1079,9 +1084,9 @@ pub unsafe fn test_borrows_25() { }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_24)), ) { - (__tmp_94, __tmp_95) => { - (*__tmp_95) = (*__tmp_95).offset(-(__tmp_94 as isize)); - (*__tmp_95).clone() + (__tmp_96, __tmp_97) => { + (*__tmp_97) = (*__tmp_97).offset(-(__tmp_96 as isize)); + (*__tmp_97).clone() } }); (unsafe { @@ -1159,9 +1164,9 @@ pub unsafe fn test_borrows_25() { { (&mut second as *mut Link_29) }, &mut ((*(*selector)).next), ) { - (__tmp_96, __tmp_97) => { - (*__tmp_97) = __tmp_96; - (*__tmp_97).clone() + (__tmp_98, __tmp_99) => { + (*__tmp_99) = __tmp_98; + (*__tmp_99).clone() } }); (unsafe { @@ -1231,9 +1236,9 @@ pub unsafe fn test_binding_31() { { 1_u32 }, &mut (*(unsafe { IndexedBinding::get_1_0(&mut (*__decomp_32)) })), ) { - (__tmp_98, __tmp_99) => { - (*__tmp_99) = (((*__tmp_99) as u32).wrapping_add((__tmp_98 as u32))) as u32; - (*__tmp_99).clone() + (__tmp_100, __tmp_101) => { + (*__tmp_101) = (((*__tmp_101) as u32).wrapping_add((__tmp_100 as u32))) as u32; + (*__tmp_101).clone() } }); (unsafe { @@ -1256,9 +1261,9 @@ pub static mut initializer_result_35: std::cell::LazyCell = { (unsafe { mutate_initializer_34() }) }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_33)), ) { - (__tmp_100, __tmp_101) => { - (*__tmp_101) = (((*__tmp_101) as u32).wrapping_add((__tmp_100 as u32))) as u32; - (*__tmp_101).clone() + (__tmp_102, __tmp_103) => { + (*__tmp_103) = (((*__tmp_103) as u32).wrapping_add((__tmp_102 as u32))) as u32; + (*__tmp_103).clone() } }) }); @@ -1273,9 +1278,9 @@ pub unsafe fn test_alias_scopes_36(mut parameter: i16) { }, &mut (parameter), ) { - (__tmp_102, __tmp_103) => { - (*__tmp_103) = (((*__tmp_103) as f64) + (__tmp_102 as f64)) as i16; - (*__tmp_103).clone() + (__tmp_104, __tmp_105) => { + (*__tmp_105) = (((*__tmp_105) as f64) + (__tmp_104 as f64)) as i16; + (*__tmp_105).clone() } }); (unsafe { @@ -1296,9 +1301,9 @@ pub unsafe fn test_alias_scopes_36(mut parameter: i16) { } ); result = (match ({ (unsafe { mutate.call() }).clone() }, &mut (local)) { - (__tmp_104, __tmp_105) => { - (*__tmp_105) = (((*__tmp_105) as f64) + (__tmp_104 as f64)) as i16; - (*__tmp_105).clone() + (__tmp_106, __tmp_107) => { + (*__tmp_107) = (((*__tmp_107) as f64) + (__tmp_106 as f64)) as i16; + (*__tmp_107).clone() } }); (unsafe { @@ -1324,9 +1329,9 @@ pub unsafe fn test_boxed_array_37() { { 1_u32 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), ) { - (__tmp_106, __tmp_107) => { - (*__tmp_107) = (((*__tmp_107) as u32).wrapping_add((__tmp_106 as u32))) as u32; - (*__tmp_107).clone() + (__tmp_108, __tmp_109) => { + (*__tmp_109) = (((*__tmp_109) as u32).wrapping_add((__tmp_108 as u32))) as u32; + (*__tmp_109).clone() } }); (unsafe { @@ -1344,9 +1349,9 @@ pub unsafe fn test_boxed_array_37() { { 1_u32 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), ) { - (__tmp_108, __tmp_109) => { - (*__tmp_109) = __tmp_108; - (*__tmp_109).clone() + (__tmp_110, __tmp_111) => { + (*__tmp_111) = __tmp_110; + (*__tmp_111).clone() } }); (unsafe { @@ -1363,9 +1368,9 @@ pub unsafe fn test_boxed_array_37() { &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_38)) [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_38))[(0) as usize]) as usize]), ) { - (__tmp_110, __tmp_111) => { - (*__tmp_111) = (((*__tmp_111) as u32).wrapping_add((__tmp_110 as u32))) as u32; - (*__tmp_111).clone() + (__tmp_112, __tmp_113) => { + (*__tmp_113) = (((*__tmp_113) as u32).wrapping_add((__tmp_112 as u32))) as u32; + (*__tmp_113).clone() } }); (unsafe { @@ -1381,9 +1386,9 @@ pub unsafe fn test_boxed_array_39() { let mut p: *mut i16 = a.as_mut_ptr(); let mut i: i32 = 0; let mut result: i16 = (match ({ 1 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize])) { - (__tmp_112, __tmp_113) => { - (*__tmp_113) = (((*__tmp_113) as i32) + (__tmp_112 as i32)) as i16; - (*__tmp_113).clone() + (__tmp_114, __tmp_115) => { + (*__tmp_115) = (((*__tmp_115) as i32) + (__tmp_114 as i32)) as i16; + (*__tmp_115).clone() } }); (unsafe { @@ -1401,9 +1406,9 @@ pub unsafe fn test_boxed_array_39() { { 1_i16 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), ) { - (__tmp_114, __tmp_115) => { - (*__tmp_115) = __tmp_114; - (*__tmp_115).clone() + (__tmp_116, __tmp_117) => { + (*__tmp_117) = __tmp_116; + (*__tmp_117).clone() } }); (unsafe { @@ -1420,9 +1425,9 @@ pub unsafe fn test_boxed_array_39() { &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_40)) [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_40))[(0) as usize]) as usize]), ) { - (__tmp_116, __tmp_117) => { - (*__tmp_117) = (((*__tmp_117) as i32) + (__tmp_116 as i32)) as i16; - (*__tmp_117).clone() + (__tmp_118, __tmp_119) => { + (*__tmp_119) = (((*__tmp_119) as i32) + (__tmp_118 as i32)) as i16; + (*__tmp_119).clone() } }); (unsafe { @@ -1482,9 +1487,9 @@ pub unsafe fn test_local_members_44() { { 1_u32 }, &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].value), ) { - (__tmp_118, __tmp_119) => { - (*__tmp_119) = (((*__tmp_119) as u32).wrapping_add((__tmp_118 as u32))) as u32; - (*__tmp_119).clone() + (__tmp_120, __tmp_121) => { + (*__tmp_121) = (((*__tmp_121) as u32).wrapping_add((__tmp_120 as u32))) as u32; + (*__tmp_121).clone() } }); (unsafe { @@ -1501,8 +1506,8 @@ pub unsafe fn test_local_members_44() { { 1 }, &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].promoted), ) { - (__tmp_120, __tmp_121) => { - (*__tmp_121) = (((*__tmp_121) as i32) + (__tmp_120 as i32)) as i16; + (__tmp_122, __tmp_123) => { + (*__tmp_123) = (((*__tmp_123) as i32) + (__tmp_122 as i32)) as i16; } }; (unsafe { @@ -1518,9 +1523,9 @@ pub unsafe fn test_local_members_44() { { 99_u32 }, &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].value), ) { - (__tmp_122, __tmp_123) => { - (*__tmp_123) = __tmp_122; - (*__tmp_123).clone() + (__tmp_124, __tmp_125) => { + (*__tmp_125) = __tmp_124; + (*__tmp_125).clone() } }); (unsafe { @@ -1549,9 +1554,9 @@ pub unsafe fn test_global_members_45() { .key) as usize] .value), ) { - (__tmp_124, __tmp_125) => { - (*__tmp_125) = (((*__tmp_125) as u32).wrapping_add((__tmp_124 as u32))) as u32; - (*__tmp_125).clone() + (__tmp_126, __tmp_127) => { + (*__tmp_127) = (((*__tmp_127) as u32).wrapping_add((__tmp_126 as u32))) as u32; + (*__tmp_127).clone() } }); (unsafe { @@ -1574,8 +1579,8 @@ pub unsafe fn test_global_members_45() { .key) as usize] .promoted), ) { - (__tmp_126, __tmp_127) => { - (*__tmp_127) = (((*__tmp_127) as i32) + (__tmp_126 as i32)) as i16; + (__tmp_128, __tmp_129) => { + (*__tmp_129) = (((*__tmp_129) as i32) + (__tmp_128 as i32)) as i16; } }; (unsafe { @@ -1597,9 +1602,9 @@ pub unsafe fn test_global_members_45() { .key) as usize] .value), ) { - (__tmp_128, __tmp_129) => { - (*__tmp_129) = __tmp_128; - (*__tmp_129).clone() + (__tmp_130, __tmp_131) => { + (*__tmp_131) = __tmp_130; + (*__tmp_131).clone() } }); (unsafe { @@ -1623,9 +1628,9 @@ pub unsafe fn test_static_members_46() { .key) as usize] .value), ) { - (__tmp_130, __tmp_131) => { - (*__tmp_131) = (((*__tmp_131) as u32).wrapping_add((__tmp_130 as u32))) as u32; - (*__tmp_131).clone() + (__tmp_132, __tmp_133) => { + (*__tmp_133) = (((*__tmp_133) as u32).wrapping_add((__tmp_132 as u32))) as u32; + (*__tmp_133).clone() } }); (unsafe { @@ -1645,8 +1650,8 @@ pub unsafe fn test_static_members_46() { .key) as usize] .promoted), ) { - (__tmp_132, __tmp_133) => { - (*__tmp_133) = (((*__tmp_133) as i32) + (__tmp_132 as i32)) as i16; + (__tmp_134, __tmp_135) => { + (*__tmp_135) = (((*__tmp_135) as i32) + (__tmp_134 as i32)) as i16; } }; (unsafe { @@ -1665,9 +1670,9 @@ pub unsafe fn test_static_members_46() { .key) as usize] .value), ) { - (__tmp_134, __tmp_135) => { - (*__tmp_135) = __tmp_134; - (*__tmp_135).clone() + (__tmp_136, __tmp_137) => { + (*__tmp_137) = __tmp_136; + (*__tmp_137).clone() } }); (unsafe { @@ -1694,7 +1699,89 @@ static mut a_47: std::cell::LazyCell<[IndexedMember; 2]> = std::cell::LazyCell:: }, ] }); -pub unsafe fn test_stable_containers_48() { +pub static mut scoped_values_48: std::cell::LazyCell<[u32; 2]> = + std::cell::LazyCell::new(|| unsafe { [10_u32, 20_u32] }); +pub static mut scoped_pointers_49: std::cell::LazyCell<[*mut u32; 1]> = + std::cell::LazyCell::new(|| unsafe { + [(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_values_48)).as_mut_ptr()] + }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct PointerSelector { + pub ptr: *mut u32, +} +pub static mut scoped_record_50: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { + PointerSelector { + ptr: (*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_values_48)).as_mut_ptr(), + } + }); +pub unsafe fn test_scoped_pointer_selectors_51() { + let mut i: i32 = 0; + let mut j: i32 = 1; + let mut a: u32 = (match ( + { 3_u32 }, + &mut (*(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_pointers_49))[(i) as usize] + .offset((j) as isize)), + ) { + (__tmp_138, __tmp_139) => { + (*__tmp_139) = __tmp_138; + (*__tmp_139).clone() + } + }); + let mut b: u32 = (match ( + { 4_u32 }, + &mut (*(*std::cell::LazyCell::force_mut(&mut *&raw mut saved_52))[(i) as usize] + .offset((j) as isize)), + ) { + (__tmp_140, __tmp_141) => { + (*__tmp_141) = __tmp_140; + (*__tmp_141).clone() + } + }); + let mut c: u32 = (match ( + { 5_u32 }, + &mut (*(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_record_50)) + .ptr + .offset((j) as isize)), + ) { + (__tmp_142, __tmp_143) => { + (*__tmp_143) = __tmp_142; + (*__tmp_143).clone() + } + }); + let mut d: u32 = (match ( + { 6_u32 }, + &mut (*(*std::cell::LazyCell::force_mut(&mut *&raw mut saved_record_53)) + .ptr + .offset((j) as isize)), + ) { + (__tmp_144, __tmp_145) => { + (*__tmp_145) = __tmp_144; + (*__tmp_145).clone() + } + }); + (unsafe { + libc::printf( + c"scoped pointers %u %u %u %u %u\n".as_ptr() as *const libc::c_char, + (a), + (b), + (c), + (d), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_values_48))[(j) as usize]), + ) + }); +} +static mut saved_52: std::cell::LazyCell<[*mut u32; 1]> = std::cell::LazyCell::new(|| unsafe { + [(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_values_48)).as_mut_ptr()] +}); +static mut saved_record_53: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { + PointerSelector { + ptr: (*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_values_48)).as_mut_ptr(), + } + }); +pub unsafe fn test_stable_containers_54() { let mut k: i32 = 1; let mut key: u8 = 3_u8; let mut buf: Vec = vec![10_u8; 2_usize]; @@ -1707,7 +1794,7 @@ pub unsafe fn test_stable_containers_48() { ) .to_vec(); s[(k as usize)] = ((s[(k as usize)] as i32) + 1) as libc::c_char; - let mut owner: Counts_49 = Counts_49 { + let mut owner: Counts_55 = Counts_55 { counts: Vec::from([10_u32, 20_u32]), }; owner.counts[(k as usize)] = (owner.counts[(k as usize)]).wrapping_add((1_u32 as u32)); @@ -1715,7 +1802,7 @@ pub unsafe fn test_stable_containers_48() { let mut vector_values: Vec = vec![10_u32; 2_usize]; let vr: *mut Vec = &mut vector_values; (&mut (*vr))[(k as usize)] = ((&mut (*vr))[(k as usize)]).wrapping_add((1_u32 as u32)); - let mut ps: Vec = vec![(Pair_50 { u: 10_u32, f: 20 }); 2_usize]; + let mut ps: Vec = vec![(Pair_56 { u: 10_u32, f: 20 }); 2_usize]; ps[(k as usize)].u = (ps[(k as usize)].u).wrapping_add((1_u32 as u32)); let mut compound: i32 = ({ v[(k as usize)] += 1; @@ -1767,17 +1854,17 @@ pub unsafe fn test_stable_containers_48() { }); let mut it: UnsafeRandomAccessIterator = v.begin(); let mut iterator_value: u32 = ((match ({ 1_u32 }, &mut (*it.iter_deref())) { - (__tmp_136, __tmp_137) => { - (*__tmp_137) = (((*__tmp_137) as u32).wrapping_add((__tmp_136 as u32))) as i32; - (*__tmp_137).clone() + (__tmp_146, __tmp_147) => { + (*__tmp_147) = (((*__tmp_147) as u32).wrapping_add((__tmp_146 as u32))) as i32; + (*__tmp_147).clone() } }) as u32); let mut m: UnsafeMap = UnsafeMap::new(); (*m.subscript(&k, || 0_u32)) = 10_u32; let mut mapped_value: u32 = (match ({ 1_u32 }, &mut (*m.subscript(&k, || 0_u32))) { - (__tmp_138, __tmp_139) => { - (*__tmp_139) = (((*__tmp_139) as u32).wrapping_add((__tmp_138 as u32))) as u32; - (*__tmp_139).clone() + (__tmp_148, __tmp_149) => { + (*__tmp_149) = (((*__tmp_149) as u32).wrapping_add((__tmp_148 as u32))) as u32; + (*__tmp_149).clone() } }); (unsafe { @@ -1790,26 +1877,26 @@ pub unsafe fn test_stable_containers_48() { } #[repr(C)] #[derive(Clone, VaArg, FnPtrArg, MoveCtorUnsafe, MoveAssignUnsafe, Default)] -pub struct Counts_49 { +pub struct Counts_55 { pub counts: Vec, } -impl Counts_49 { - pub unsafe fn move_from(_a0: *mut Counts_49) -> Self { +impl Counts_55 { + pub unsafe fn move_from(_a0: *mut Counts_55) -> Self { let mut this = Self { counts: std::mem::take(&mut (*_a0).counts), }; this } - pub unsafe fn move_assign(&mut self, _a0: *mut Counts_49) -> *mut Counts_49 { + pub unsafe fn move_assign(&mut self, _a0: *mut Counts_55) -> *mut Counts_55 { { self.counts = std::mem::take(&mut (*_a0).counts); }; - return &mut (*(self as *mut Counts_49)); + return &mut (*(self as *mut Counts_55)); } } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Pair_50 { +pub struct Pair_56 { pub u: u32, pub f: i32, } @@ -1820,7 +1907,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { test_stable_containers_48() }); + (unsafe { test_stable_containers_54() }); + (unsafe { test_scoped_pointer_selectors_51() }); let mut a: [i32; 2] = [10, 20]; let mut index: i32 = 1; let mut value: i32 = ({ @@ -1848,7 +1936,7 @@ unsafe fn main_0() -> i32 { (a[(1) as usize]), ) }); - let mut selector: Index_51 = Index_51 { value: 1 }; + let mut selector: Index_57 = Index_57 { value: 1 }; value = ({ a[(selector.value) as usize] = 88; a[(selector.value) as usize] @@ -1869,9 +1957,9 @@ unsafe fn main_0() -> i32 { let alias: *mut i32 = &mut a[(0) as usize]; (*alias) = 0; value = (match ({ 1 }, &mut (a[(*alias) as usize])) { - (__tmp_140, __tmp_141) => { - (*__tmp_141) = __tmp_140; - (*__tmp_141).clone() + (__tmp_150, __tmp_151) => { + (*__tmp_151) = __tmp_150; + (*__tmp_151).clone() } }); (unsafe { @@ -1928,7 +2016,7 @@ unsafe fn main_0() -> i32 { (a[(1) as usize]), ) }); - let mut owner: Owner_52 = Owner_52 { + let mut owner: Owner_58 = Owner_58 { values: [0, 20], index: 0, }; @@ -1936,9 +2024,9 @@ unsafe fn main_0() -> i32 { { 1 }, &mut (owner.values[(owner.values[(0) as usize]) as usize]), ) { - (__tmp_142, __tmp_143) => { - (*__tmp_143) = __tmp_142; - (*__tmp_143).clone() + (__tmp_152, __tmp_153) => { + (*__tmp_153) = __tmp_152; + (*__tmp_153).clone() } }); reference_value = ({ @@ -1954,15 +2042,15 @@ unsafe fn main_0() -> i32 { (owner.values[(1) as usize]), ) }); - let mut alias_selector: Index_51 = Index_51 { value: 0 }; + let mut alias_selector: Index_57 = Index_57 { value: 0 }; let mut member_alias: *mut i32 = (&mut alias_selector.value as *mut i32); value = (match ( { 1 }, &mut (*member_alias.offset((alias_selector.value) as isize)), ) { - (__tmp_144, __tmp_145) => { - (*__tmp_145) = __tmp_144; - (*__tmp_145).clone() + (__tmp_154, __tmp_155) => { + (*__tmp_155) = __tmp_154; + (*__tmp_155).clone() } }); (unsafe { @@ -1975,9 +2063,9 @@ unsafe fn main_0() -> i32 { let mut self_index: i32 = 0; let mut self_: *mut i32 = (&mut self_index as *mut i32); value = (match ({ 1 }, &mut (*self_.offset((self_index) as isize))) { - (__tmp_146, __tmp_147) => { - (*__tmp_147) = __tmp_146; - (*__tmp_147).clone() + (__tmp_156, __tmp_157) => { + (*__tmp_157) = __tmp_156; + (*__tmp_157).clone() } }); (unsafe { @@ -1999,9 +2087,9 @@ unsafe fn main_0() -> i32 { { 10000 }, &mut (*(*captured_pointer).offset((*captured_index) as isize)), ) { - (__tmp_148, __tmp_149) => { - (*__tmp_149) = __tmp_148; - (*__tmp_149).clone() + (__tmp_158, __tmp_159) => { + (*__tmp_159) = __tmp_158; + (*__tmp_159).clone() } }); } @@ -2038,9 +2126,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_150, __tmp_151) => { - (*__tmp_151) = (((*__tmp_151) as u32).wrapping_add((__tmp_150 as u32))) as u32; - (*__tmp_151).clone() + (__tmp_160, __tmp_161) => { + (*__tmp_161) = (((*__tmp_161) as u32).wrapping_add((__tmp_160 as u32))) as u32; + (*__tmp_161).clone() } }); (unsafe { @@ -2062,9 +2150,9 @@ unsafe fn main_0() -> i32 { [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_41))[(0) as usize]) as usize]), ) { - (__tmp_152, __tmp_153) => { - (*__tmp_153) = (((*__tmp_153) as u32).wrapping_add((__tmp_152 as u32))) as u32; - (*__tmp_153).clone() + (__tmp_162, __tmp_163) => { + (*__tmp_163) = (((*__tmp_163) as u32).wrapping_add((__tmp_162 as u32))) as u32; + (*__tmp_163).clone() } }); (unsafe { @@ -2081,9 +2169,9 @@ unsafe fn main_0() -> i32 { [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_42)) [(i.postfix_inc()) as usize][(0) as usize]) as usize][(0) as usize]), ) { - (__tmp_154, __tmp_155) => { - (*__tmp_155) = (((*__tmp_155) as u32).wrapping_add((__tmp_154 as u32))) as u32; - (*__tmp_155).clone() + (__tmp_164, __tmp_165) => { + (*__tmp_165) = (((*__tmp_165) as u32).wrapping_add((__tmp_164 as u32))) as u32; + (*__tmp_165).clone() } }); (unsafe { @@ -2101,12 +2189,12 @@ unsafe fn main_0() -> i32 { } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Index_51 { +pub struct Index_57 { pub value: i32, } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Owner_52 { +pub struct Owner_58 { pub values: [i32; 2], pub index: i32, } @@ -2121,4 +2209,7 @@ pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const global_array_41); std::cell::LazyCell::force(&*&raw const global_rows_42); std::cell::LazyCell::force(&*&raw const global_members_43); + std::cell::LazyCell::force(&*&raw const scoped_values_48); + std::cell::LazyCell::force(&*&raw const scoped_pointers_49); + std::cell::LazyCell::force(&*&raw const scoped_record_50); } From 1cbc95b2292e98daad488b3587dbcae55fbbdce2 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Sun, 29 Nov 2026 00:00:09 +0000 Subject: [PATCH 18/25] Keep stable nonlocal pointer selectors on compact assignment lowering Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 16 +- .../out/refcount/assignment_single_eval.rs | 170 +++++++++--------- .../unit/out/unsafe/assignment_single_eval.rs | 122 ++++++------- 3 files changed, 155 insertions(+), 153 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 824029e7dd..137e69f3f0 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -5345,11 +5345,21 @@ bool Converter::NeedsAssignmentBinding( } // A pointer-valued selector cannot overlap a non-character arithmetic // target in a well-defined program. Still check its base and indices. - if (!clang::isa(place) && - place->getType()->isPointerType() && + if (place->getType()->isPointerType() && lhs->getType()->isArithmeticType() && !lhs->getType()->isAnyCharacterType()) { - return self(self, place); + for (const auto *part = place;;) { + if (const auto *element = + clang::dyn_cast(part); + element && !self(self, element->getIdx())) { + return false; + } + const auto *object = GetEnclosingObject(part); + if (!object) { + return clang::isa(part) || self(self, part); + } + part = object->IgnoreParenImpCasts(); + } } while ( clang::isa(place)) { diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index a830e99cf1..91afc5bc25 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -1868,58 +1868,64 @@ pub fn test_scoped_pointer_selectors_51() { let mut i: i32 = 0; let mut j: i32 = 1; let mut a: u32 = ({ - match ({ 3_u32 }, { - let __tmp_135 = ({ + elem!( + ({ let __idx0 = (i) as usize; scoped_pointers_49.with(|rc| rc.borrow()[__idx0].clone()) - }) - .offset((j) as isize); - __tmp_135 - }) { - (__tmp_134, __tmp_135) => __tmp_135.with_mut(|__tmp_135| { - (*__tmp_135) = __tmp_134; - (*__tmp_135).clone() }), - } + j + ) + .write(3_u32); + (elem!( + ({ + let __idx0 = (i) as usize; + scoped_pointers_49.with(|rc| rc.borrow()[__idx0].clone()) + }), + j + ) + .read()) }); let mut b: u32 = ({ - match ({ 4_u32 }, { - let __tmp_137 = ({ + elem!( + ({ let __idx0 = (i) as usize; saved_52.with(|rc| rc.borrow()[__idx0].clone()) - }) - .offset((j) as isize); - __tmp_137 - }) { - (__tmp_136, __tmp_137) => __tmp_137.with_mut(|__tmp_137| { - (*__tmp_137) = __tmp_136; - (*__tmp_137).clone() }), - } + j + ) + .write(4_u32); + (elem!( + ({ + let __idx0 = (i) as usize; + saved_52.with(|rc| rc.borrow()[__idx0].clone()) + }), + j + ) + .read()) }); let mut c: u32 = ({ - match ({ 5_u32 }, { - let __tmp_139 = { (*scoped_record_50.with(Value::clone).borrow()).ptr.clone() } - .offset((j) as isize); - __tmp_139 - }) { - (__tmp_138, __tmp_139) => __tmp_139.with_mut(|__tmp_139| { - (*__tmp_139) = __tmp_138; - (*__tmp_139).clone() - }), - } + elem!( + { (*scoped_record_50.with(Value::clone).borrow()).ptr.clone() }, + j + ) + .write(5_u32); + (elem!( + { (*scoped_record_50.with(Value::clone).borrow()).ptr.clone() }, + j + ) + .read()) }); let mut d: u32 = ({ - match ({ 6_u32 }, { - let __tmp_141 = - { (*saved_record_53.with(Value::clone).borrow()).ptr.clone() }.offset((j) as isize); - __tmp_141 - }) { - (__tmp_140, __tmp_141) => __tmp_141.with_mut(|__tmp_141| { - (*__tmp_141) = __tmp_140; - (*__tmp_141).clone() - }), - } + elem!( + { (*saved_record_53.with(Value::clone).borrow()).ptr.clone() }, + j + ) + .write(6_u32); + (elem!( + { (*saved_record_53.with(Value::clone).borrow()).ptr.clone() }, + j + ) + .read()) }); printf!( b"scoped pointers %u %u %u %u %u\n", @@ -2036,9 +2042,9 @@ pub fn test_stable_containers_54() { let it: Value> = Rc::new(RefCell::new(v.decay().begin())); let mut iterator_value: u32 = (({ match ({ 1_u32 }, &({ (*it.borrow()).iter_deref() })) { - (__tmp_142, __tmp_143) => __tmp_143.with_mut(|__tmp_143| { - (*__tmp_143) = (((*__tmp_143) as u32).wrapping_add((__tmp_142 as u32))) as i32; - (*__tmp_143).clone() + (__tmp_134, __tmp_135) => __tmp_135.with_mut(|__tmp_135| { + (*__tmp_135) = (((*__tmp_135) as u32).wrapping_add((__tmp_134 as u32))) as i32; + (*__tmp_135).clone() }), } }) as u32); @@ -2049,9 +2055,9 @@ pub fn test_stable_containers_54() { { 1_u32 }, &({ (*m.borrow_mut()).subscript(k.as_pointer(), || 0_u32) }), ) { - (__tmp_144, __tmp_145) => __tmp_145.with_mut(|__tmp_145| { - (*__tmp_145) = (((*__tmp_145) as u32).wrapping_add((__tmp_144 as u32))) as u32; - (*__tmp_145).clone() + (__tmp_136, __tmp_137) => __tmp_137.with_mut(|__tmp_137| { + (*__tmp_137) = (((*__tmp_137) as u32).wrapping_add((__tmp_136 as u32))) as u32; + (*__tmp_137).clone() }), } }); @@ -2130,12 +2136,12 @@ fn main_0() -> i32 { alias.write(0); let __rhs = ({ match ({ 1 }, { - let __tmp_147 = a.decay().offset((alias.read())); - __tmp_147 + let __tmp_139 = a.decay().offset((alias.read())); + __tmp_139 }) { - (__tmp_146, __tmp_147) => __tmp_147.with_mut(|__tmp_147| { - (*__tmp_147) = __tmp_146; - (*__tmp_147).clone() + (__tmp_138, __tmp_139) => __tmp_139.with_mut(|__tmp_139| { + (*__tmp_139) = __tmp_138; + (*__tmp_139).clone() }), } }); @@ -2200,9 +2206,9 @@ fn main_0() -> i32 { { 1 }, &mut (owner.values[(owner.values[(0) as usize]) as usize]), ) { - (__tmp_148, __tmp_149) => { - (*__tmp_149) = __tmp_148; - (*__tmp_149).clone() + (__tmp_140, __tmp_141) => { + (*__tmp_141) = __tmp_140; + (*__tmp_141).clone() } } }); @@ -2221,12 +2227,12 @@ fn main_0() -> i32 { let mut member_alias: Ptr = (field_ptr!(alias_selector.as_pointer(), value)); let __rhs = ({ match ({ 1 }, { - let __tmp_151 = member_alias.offset(({ (*alias_selector.borrow()).value }) as isize); - __tmp_151 + let __tmp_143 = member_alias.offset(({ (*alias_selector.borrow()).value }) as isize); + __tmp_143 }) { - (__tmp_150, __tmp_151) => __tmp_151.with_mut(|__tmp_151| { - (*__tmp_151) = __tmp_150; - (*__tmp_151).clone() + (__tmp_142, __tmp_143) => __tmp_143.with_mut(|__tmp_143| { + (*__tmp_143) = __tmp_142; + (*__tmp_143).clone() }), } }); @@ -2238,12 +2244,12 @@ fn main_0() -> i32 { let mut self_: Ptr = (self_index.as_pointer()); let __rhs = ({ match ({ 1 }, { - let __tmp_153 = self_.offset((*self_index.borrow()) as isize); - __tmp_153 + let __tmp_145 = self_.offset((*self_index.borrow()) as isize); + __tmp_145 }) { - (__tmp_152, __tmp_153) => __tmp_153.with_mut(|__tmp_153| { - (*__tmp_153) = __tmp_152; - (*__tmp_153).clone() + (__tmp_144, __tmp_145) => __tmp_145.with_mut(|__tmp_145| { + (*__tmp_145) = __tmp_144; + (*__tmp_145).clone() }), } }); @@ -2259,13 +2265,13 @@ fn main_0() -> i32 { || -> i32 { return ({ match ({ 10000 }, { - let __tmp_155 = + let __tmp_147 = (captured_pointer.read()).offset((captured_index.read()) as isize); - __tmp_155 + __tmp_147 }) { - (__tmp_154, __tmp_155) => __tmp_155.with_mut(|__tmp_155| { - (*__tmp_155) = __tmp_154; - (*__tmp_155).clone() + (__tmp_146, __tmp_147) => __tmp_147.with_mut(|__tmp_147| { + (*__tmp_147) = __tmp_146; + (*__tmp_147).clone() }), } }); @@ -2305,9 +2311,9 @@ fn main_0() -> i32 { 0 )), ) { - (__tmp_156, __tmp_157) => __tmp_157.with_mut(|__tmp_157| { - (*__tmp_157) = (((*__tmp_157) as u32).wrapping_add((__tmp_156 as u32))) as u32; - (*__tmp_157).clone() + (__tmp_148, __tmp_149) => __tmp_149.with_mut(|__tmp_149| { + (*__tmp_149) = (((*__tmp_149) as u32).wrapping_add((__tmp_148 as u32))) as u32; + (*__tmp_149).clone() }), } }); @@ -2324,17 +2330,17 @@ fn main_0() -> i32 { ({ test_boxed_array_39() }); let mut global_result: u32 = ({ match ({ 1_u32 }, { - let __tmp_159 = global_array_41.with(|v| v.decay()).offset( + let __tmp_151 = global_array_41.with(|v| v.decay()).offset( ({ let __idx0 = (0) as usize; global_array_41.with(|rc| rc.borrow()[__idx0]) }), ); - __tmp_159 + __tmp_151 }) { - (__tmp_158, __tmp_159) => __tmp_159.with_mut(|__tmp_159| { - (*__tmp_159) = (((*__tmp_159) as u32).wrapping_add((__tmp_158 as u32))) as u32; - (*__tmp_159).clone() + (__tmp_150, __tmp_151) => __tmp_151.with_mut(|__tmp_151| { + (*__tmp_151) = (((*__tmp_151) as u32).wrapping_add((__tmp_150 as u32))) as u32; + (*__tmp_151).clone() }), } }); @@ -2349,7 +2355,7 @@ fn main_0() -> i32 { i = 0; result = ({ match ({ 1_u32 }, { - let __tmp_161 = global_rows_42 + let __tmp_153 = global_rows_42 .with(|v| v.decay()) .offset( ({ @@ -2360,11 +2366,11 @@ fn main_0() -> i32 { ) .decay() .offset(0); - __tmp_161 + __tmp_153 }) { - (__tmp_160, __tmp_161) => __tmp_161.with_mut(|__tmp_161| { - (*__tmp_161) = (((*__tmp_161) as u32).wrapping_add((__tmp_160 as u32))) as u32; - (*__tmp_161).clone() + (__tmp_152, __tmp_153) => __tmp_153.with_mut(|__tmp_153| { + (*__tmp_153) = (((*__tmp_153) as u32).wrapping_add((__tmp_152 as u32))) as u32; + (*__tmp_153).clone() }), } }); diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index a5e8439bde..5661aea59e 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -1719,47 +1719,33 @@ pub static mut scoped_record_50: std::cell::LazyCell = pub unsafe fn test_scoped_pointer_selectors_51() { let mut i: i32 = 0; let mut j: i32 = 1; - let mut a: u32 = (match ( - { 3_u32 }, - &mut (*(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_pointers_49))[(i) as usize] - .offset((j) as isize)), - ) { - (__tmp_138, __tmp_139) => { - (*__tmp_139) = __tmp_138; - (*__tmp_139).clone() - } - }); - let mut b: u32 = (match ( - { 4_u32 }, - &mut (*(*std::cell::LazyCell::force_mut(&mut *&raw mut saved_52))[(i) as usize] - .offset((j) as isize)), - ) { - (__tmp_140, __tmp_141) => { - (*__tmp_141) = __tmp_140; - (*__tmp_141).clone() - } - }); - let mut c: u32 = (match ( - { 5_u32 }, - &mut (*(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_record_50)) + let mut a: u32 = ({ + (*(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_pointers_49))[(i) as usize] + .offset((j) as isize)) = 3_u32; + (*(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_pointers_49))[(i) as usize] + .offset((j) as isize)) + }); + let mut b: u32 = ({ + (*(*std::cell::LazyCell::force_mut(&mut *&raw mut saved_52))[(i) as usize] + .offset((j) as isize)) = 4_u32; + (*(*std::cell::LazyCell::force_mut(&mut *&raw mut saved_52))[(i) as usize] + .offset((j) as isize)) + }); + let mut c: u32 = ({ + (*(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_record_50)) .ptr - .offset((j) as isize)), - ) { - (__tmp_142, __tmp_143) => { - (*__tmp_143) = __tmp_142; - (*__tmp_143).clone() - } + .offset((j) as isize)) = 5_u32; + (*(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_record_50)) + .ptr + .offset((j) as isize)) }); - let mut d: u32 = (match ( - { 6_u32 }, - &mut (*(*std::cell::LazyCell::force_mut(&mut *&raw mut saved_record_53)) + let mut d: u32 = ({ + (*(*std::cell::LazyCell::force_mut(&mut *&raw mut saved_record_53)) .ptr - .offset((j) as isize)), - ) { - (__tmp_144, __tmp_145) => { - (*__tmp_145) = __tmp_144; - (*__tmp_145).clone() - } + .offset((j) as isize)) = 6_u32; + (*(*std::cell::LazyCell::force_mut(&mut *&raw mut saved_record_53)) + .ptr + .offset((j) as isize)) }); (unsafe { libc::printf( @@ -1854,17 +1840,17 @@ pub unsafe fn test_stable_containers_54() { }); let mut it: UnsafeRandomAccessIterator = v.begin(); let mut iterator_value: u32 = ((match ({ 1_u32 }, &mut (*it.iter_deref())) { - (__tmp_146, __tmp_147) => { - (*__tmp_147) = (((*__tmp_147) as u32).wrapping_add((__tmp_146 as u32))) as i32; - (*__tmp_147).clone() + (__tmp_138, __tmp_139) => { + (*__tmp_139) = (((*__tmp_139) as u32).wrapping_add((__tmp_138 as u32))) as i32; + (*__tmp_139).clone() } }) as u32); let mut m: UnsafeMap = UnsafeMap::new(); (*m.subscript(&k, || 0_u32)) = 10_u32; let mut mapped_value: u32 = (match ({ 1_u32 }, &mut (*m.subscript(&k, || 0_u32))) { - (__tmp_148, __tmp_149) => { - (*__tmp_149) = (((*__tmp_149) as u32).wrapping_add((__tmp_148 as u32))) as u32; - (*__tmp_149).clone() + (__tmp_140, __tmp_141) => { + (*__tmp_141) = (((*__tmp_141) as u32).wrapping_add((__tmp_140 as u32))) as u32; + (*__tmp_141).clone() } }); (unsafe { @@ -1957,9 +1943,9 @@ unsafe fn main_0() -> i32 { let alias: *mut i32 = &mut a[(0) as usize]; (*alias) = 0; value = (match ({ 1 }, &mut (a[(*alias) as usize])) { - (__tmp_150, __tmp_151) => { - (*__tmp_151) = __tmp_150; - (*__tmp_151).clone() + (__tmp_142, __tmp_143) => { + (*__tmp_143) = __tmp_142; + (*__tmp_143).clone() } }); (unsafe { @@ -2024,9 +2010,9 @@ unsafe fn main_0() -> i32 { { 1 }, &mut (owner.values[(owner.values[(0) as usize]) as usize]), ) { - (__tmp_152, __tmp_153) => { - (*__tmp_153) = __tmp_152; - (*__tmp_153).clone() + (__tmp_144, __tmp_145) => { + (*__tmp_145) = __tmp_144; + (*__tmp_145).clone() } }); reference_value = ({ @@ -2048,9 +2034,9 @@ unsafe fn main_0() -> i32 { { 1 }, &mut (*member_alias.offset((alias_selector.value) as isize)), ) { - (__tmp_154, __tmp_155) => { - (*__tmp_155) = __tmp_154; - (*__tmp_155).clone() + (__tmp_146, __tmp_147) => { + (*__tmp_147) = __tmp_146; + (*__tmp_147).clone() } }); (unsafe { @@ -2063,9 +2049,9 @@ unsafe fn main_0() -> i32 { let mut self_index: i32 = 0; let mut self_: *mut i32 = (&mut self_index as *mut i32); value = (match ({ 1 }, &mut (*self_.offset((self_index) as isize))) { - (__tmp_156, __tmp_157) => { - (*__tmp_157) = __tmp_156; - (*__tmp_157).clone() + (__tmp_148, __tmp_149) => { + (*__tmp_149) = __tmp_148; + (*__tmp_149).clone() } }); (unsafe { @@ -2087,9 +2073,9 @@ unsafe fn main_0() -> i32 { { 10000 }, &mut (*(*captured_pointer).offset((*captured_index) as isize)), ) { - (__tmp_158, __tmp_159) => { - (*__tmp_159) = __tmp_158; - (*__tmp_159).clone() + (__tmp_150, __tmp_151) => { + (*__tmp_151) = __tmp_150; + (*__tmp_151).clone() } }); } @@ -2126,9 +2112,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_160, __tmp_161) => { - (*__tmp_161) = (((*__tmp_161) as u32).wrapping_add((__tmp_160 as u32))) as u32; - (*__tmp_161).clone() + (__tmp_152, __tmp_153) => { + (*__tmp_153) = (((*__tmp_153) as u32).wrapping_add((__tmp_152 as u32))) as u32; + (*__tmp_153).clone() } }); (unsafe { @@ -2150,9 +2136,9 @@ unsafe fn main_0() -> i32 { [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_41))[(0) as usize]) as usize]), ) { - (__tmp_162, __tmp_163) => { - (*__tmp_163) = (((*__tmp_163) as u32).wrapping_add((__tmp_162 as u32))) as u32; - (*__tmp_163).clone() + (__tmp_154, __tmp_155) => { + (*__tmp_155) = (((*__tmp_155) as u32).wrapping_add((__tmp_154 as u32))) as u32; + (*__tmp_155).clone() } }); (unsafe { @@ -2169,9 +2155,9 @@ unsafe fn main_0() -> i32 { [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_42)) [(i.postfix_inc()) as usize][(0) as usize]) as usize][(0) as usize]), ) { - (__tmp_164, __tmp_165) => { - (*__tmp_165) = (((*__tmp_165) as u32).wrapping_add((__tmp_164 as u32))) as u32; - (*__tmp_165).clone() + (__tmp_156, __tmp_157) => { + (*__tmp_157) = (((*__tmp_157) as u32).wrapping_add((__tmp_156 as u32))) as u32; + (*__tmp_157).clone() } }); (unsafe { From 14195c25f3c3905697991a2e72f54da0439f168e Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Sun, 29 Nov 2026 17:05:46 +0000 Subject: [PATCH 19/25] Reduce assignment single-evaluation regression to side-effecting targets Signed-off-by: Perfloop Agent --- tests/unit/assign_as_value.c | 9 - tests/unit/assignment_single_eval.cpp | 415 +-- tests/unit/out/refcount/assign_as_value.rs | 28 +- .../out/refcount/assignment_single_eval.rs | 2417 +---------------- tests/unit/out/unsafe/assign_as_value.rs | 20 - .../unit/out/unsafe/assignment_single_eval.rs | 2167 +-------------- 6 files changed, 59 insertions(+), 4997 deletions(-) diff --git a/tests/unit/assign_as_value.c b/tests/unit/assign_as_value.c index 1d313281ae..7ec44cbde6 100644 --- a/tests/unit/assign_as_value.c +++ b/tests/unit/assign_as_value.c @@ -5,15 +5,6 @@ int main(void) { char *p = buf, *q; q = p += 1; assert(q == buf + 1); - q = p -= 1; - assert(p == buf); - assert(q == buf); - p += 1; - int i = 0; - q = *(&p + i++) -= 1; - assert(i == 1); - assert(p == buf); - assert(q == buf); char out; switch (out = 'x') { diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index 0d66e1bc55..a8af331e4f 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -1,423 +1,16 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++17 -#include #include -#include -#include -#include -#include template void test() { - T a[3] = {10, 20, 30}; + T a[] = {10, 20, 30, 40}; int i = 0; a[i++] += 5; - std::printf("void %d %d %d\n", i, int(a[0]), int(a[1])); - - i = 0; - T sum = (a[i++] += 2); - std::printf("compound %d %d %d %d\n", i, int(sum), int(a[0]), int(a[1])); - - i = 0; + T compound = (a[i++] += 5); T assigned = (a[i++] = 99); - std::printf("simple %d %d %d %d\n", i, int(assigned), int(a[0]), int(a[1])); - - T plain = 10; - plain += 5; - T plain_result = (plain += 2); - std::printf("plain %d %d\n", int(plain_result), int(plain)); - - i = 0; - a[i] += (i = 1, T(5)); - std::printf("rhs target %d %d %d\n", i, int(a[0]), int(a[1])); - - a[0] = 0; - T selected = (a[a[0]] += 1); - std::printf("self compound %d %d %d\n", int(selected), int(a[0]), int(a[1])); - a[0] = 0; - selected = (a[a[0]] = 1); - std::printf("self simple %d %d %d\n", int(selected), int(a[0]), int(a[1])); -} - -template void test_comma() { - T x = 10; - int i = 0; - ((++i, x) += 5); - std::printf("direct void %d %d\n", i, int(x)); - T result = ((++i, x) += 2); - std::printf("direct compound %d %d %d\n", i, int(result), int(x)); - result = ((++i, x) = 99); - std::printf("direct simple %d %d %d\n", i, int(result), int(x)); - - T *p = &x; - ((++i, *p) += 5); - std::printf("indirect void %d %d\n", i, int(*p)); - result = ((++i, *p) += 2); - std::printf("indirect compound %d %d %d\n", i, int(result), int(*p)); - result = ((++i, *p) = 99); - std::printf("indirect simple %d %d %d\n", i, int(result), int(*p)); -} - -template void test_reference_members() { - struct Slot { - T &value; - }; - T index = 0, other = 77; - Slot a[2] = {{index}, {other}}; - a[index].value += 1; - std::printf("reference void %d %d\n", int(index), int(other)); - index = 0; - T result = (a[index].value += 1); - std::printf("reference compound %d %d %d\n", int(index), int(other), - int(result)); - index = 0; - result = (a[index].value = 1); - std::printf("reference simple %d %d %d\n", int(index), int(other), - int(result)); - index = 0; - result = (a[index++].value += 1); - std::printf("reference effect %d %d %d\n", int(index), int(other), - int(result)); - index = 0; - result = (a[index].value += (index = 1, T(2))); - std::printf("reference rhs %d %d %d\n", int(index), int(other), int(result)); -} - -void test_reference_pointer() { - struct Node { - Node *&link; - }; - Node *p = nullptr, *q = nullptr; - Node first{p}, second{q}; - p = &first; - q = &first; - Node *result = (p->link = &second); - std::printf("reference pointer %d %d\n", p == &second, result == &second); -} - -template void test_reference_subfields() { - struct Index { - T value; - }; - struct Slot { - Index &ref; - }; - Index index{0}, other{77}; - Slot a[2] = {{index}, {other}}; - T result = (a[index.value].ref.value += 1); - std::printf("reference subfield compound %d %d %d\n", int(result), - int(index.value), int(other.value)); - index.value = 0; - result = (a[index.value].ref.value = 1); - std::printf("reference subfield simple %d %d %d\n", int(result), - int(index.value), int(other.value)); -} - -void test_captured_alias() { - short x = 10; - short *p = &x; - auto f = [&]() { return (x += (*p = -1, 0.5)); }; - int result = f(); - std::printf("captured outer alias %d %d\n", result, int(x)); -} - -int global = 10; -int observe_global(int assigned) { return assigned + global; } -int observe(int assigned, const int *stored) { return assigned + *stored; } -struct GlobalRecord { - struct Inner { - int value; - } inner; -} global_record{{10}}; -int observe_record(int assigned) { - return assigned + global_record.inner.value; -} -int targets[2] = {10, 20}; -int *cursor = targets; - -void test_borrows() { - std::printf("%d\n", observe_global(global = 99)); - std::printf("%d\n", observe_global(global += 5)); - std::printf("%d\n", observe_global(global = observe(0, &global))); - static short promoted = 10; - int assigned = (promoted += (promoted = -1, 0.5)); - std::printf("%d %d\n", assigned, int(promoted)); - short aliased = 10; - short *alias = &aliased; - assigned = (aliased += (*alias = -1, 0.5)); - std::printf("%d %d\n", assigned, int(aliased)); - static bool flag = false; - bool enabled = (flag += (observe(0, &global), 0.5)); - std::printf("%d %d\n", int(enabled), int(flag)); - std::printf("%d\n", observe_record(global_record.inner.value = 99)); - int *shifted = (cursor -= (cursor = targets + 1, 1)); - std::printf("%d %d\n", cursor == targets, shifted == cursor); - - int local = 10; - std::printf("%d\n", observe(local = 99, &local)); - std::printf("%d\n", observe(local += 5, &local)); - - struct Record { - int value; - }; - Record record{10}; - std::printf("%d\n", observe(record.value = 99, &record.value)); - std::printf("%d\n", observe(record.value += 5, &record.value)); - - struct Link { - Link *next; - }; - Link first{&first}, second{&first}; - Link *&selector = first.next; - Link *selected = (selector->next = &second); - std::printf("%d %d\n", selected == &second, first.next == &second); - - std::vector values(1, 10); - std::printf("%d\n", observe(values[0] = 99, &values[0])); - std::printf("%d\n", observe(values[0] += 5, &values[0])); -} - -unsigned selected_values[3] = {0, 20, 30}; -struct IndexedBinding { - template __attribute__((pure)) unsigned &get() { - return selected_values[selected_values[0]]; - } -}; -namespace std { -template <> struct tuple_size { - static constexpr unsigned value = 1; -}; -template <> struct tuple_element<0, IndexedBinding> { - using type = unsigned; -}; -} // namespace std - -void test_binding() { - IndexedBinding owner; - auto &[value] = owner; - unsigned result = (value += 1); - std::printf("binding compound %u %u\n", result, selected_values[0]); -} - -unsigned initializer_target = 10; -unsigned mutate_initializer() { - initializer_target = 20; - return 1; -} -unsigned initializer_result = (initializer_target += mutate_initializer()); - -void test_alias_scopes(short parameter) { - short *p = ¶meter; - short result = (parameter += (*p = -1, 0.5)); - std::printf("parameter %d %d\n", int(result), int(parameter)); - short local = 10; - auto mutate = [&local]() { - local = -1; - return 0.5; - }; - result = (local += mutate()); - std::printf("capture %d %d\n", int(result), int(local)); - std::printf("initializer %u %u\n", initializer_result, initializer_target); -} - -template void test_boxed_array() { - T a[3] = {0, 20, 30}; - T *p = a; - int i = 0; - T result = (a[a[i++]] += 1); - std::printf("boxed compound %d %d %d %d\n", i, int(result), int(a[0]), - int(*p)); - a[0] = 0; - i = 0; - result = (a[a[i++]] = 1); - std::printf("boxed simple %d %d %d %d\n", i, int(result), int(a[0]), int(*p)); - static T saved[3] = {0, 20, 30}; - result = (saved[saved[0]] += 1); - std::printf("static array %d %d\n", int(result), int(saved[0])); -} -unsigned global_array[3] = {0, 20, 30}; -unsigned global_rows[2][2] = {{0, 10}, {20, 30}}; - -struct IndexedMember { - int key; - unsigned value; - short promoted; -}; -IndexedMember global_members[2] = {{0, 10, 10}, {1, 20, 20}}; - -#define TEST_MEMBERS(array) \ - int i = 0; \ - unsigned result = (array[array[i++].key].value += 1); \ - std::printf("member unsigned %d %u %u %u\n", i, result, array[0].value, \ - array[1].value); \ - i = 0; \ - array[array[i++].key].promoted += 1; \ - std::printf("member promoted %d %d %d\n", i, int(array[0].promoted), \ - int(array[1].promoted)); \ - i = 0; \ - result = (array[array[i++].key].value = 99); \ - std::printf("member simple %d %u %u %u\n", i, result, array[0].value, \ - array[1].value) - -void test_local_members() { - IndexedMember a[2] = {{0, 10, 10}, {1, 20, 20}}; - IndexedMember *p = a; - TEST_MEMBERS(a); - std::printf("member alias %u\n", p->value); -} -void test_global_members() { TEST_MEMBERS(global_members); } -void test_static_members() { - static IndexedMember a[2] = {{0, 10, 10}, {1, 20, 20}}; - TEST_MEMBERS(a); -} -#undef TEST_MEMBERS - -unsigned scoped_values[2] = {10, 20}; -unsigned *scoped_pointers[1] = {scoped_values}; -struct PointerSelector { - unsigned *ptr; -}; -PointerSelector scoped_record{scoped_values}; - -void test_scoped_pointer_selectors() { - int i = 0, j = 1; - unsigned a = (scoped_pointers[i][j] = 3u); - static unsigned *saved[1] = {scoped_values}; - unsigned b = (saved[i][j] = 4u); - unsigned c = (scoped_record.ptr[j] = 5u); - static PointerSelector saved_record{scoped_values}; - unsigned d = (saved_record.ptr[j] = 6u); - std::printf("scoped pointers %u %u %u %u %u\n", a, b, c, d, scoped_values[j]); -} - -void test_stable_containers() { - int k = 1; - unsigned char key = 3; - std::vector buf(2, 10); - buf[k] ^= key; - std::array a{10, 20}; - a[k] += 1u; - std::string s = "ab"; - s[k] += 1; - struct Counts { - std::vector counts; - } owner{{10, 20}}; - owner.counts[k] += 1u; - std::vector v(2, 10); - std::vector vector_values(2, 10); - std::vector &vr = vector_values; - vr[k] += 1u; - struct Pair { - unsigned u; - int f; - }; - std::vector ps(2, Pair{10, 20}); - ps[k].u += 1u; - int compound = (v[k] += 1); - int simple = (v[k] = 2); - int member = (ps[k].f = 4); - std::vector> g(2, std::vector(2, 10)); - int nested = (g[k][k] = 5); - unsigned row[2] = {10, 20}; - unsigned *pointers[2] = {row, row}; - unsigned **rows = pointers; - int i = 0, j = 1; - unsigned indirect = (rows[i][j] = 3u); - std::printf("containers %u %u %d %u %u %u %d %d %d %d %u\n", unsigned(buf[k]), - a[k], int(s[k]), owner.counts[k], vr[k], ps[k].u, compound, - simple, member, nested, indirect); - // These two unsafe-model value expressions lacked a result on the base. - auto it = v.begin(); - unsigned iterator_value = (*it += 1u); - std::map m; - m[k] = 10; - unsigned mapped_value = (m[k] += 1u); - std::printf("nonflat values %u %u\n", iterator_value, mapped_value); + std::printf("%d %d %d: %d %d %d %d\n", i, (int)compound, (int)assigned, + (int)a[0], (int)a[1], (int)a[2], (int)a[3]); } int main() { - test_stable_containers(); - test_scoped_pointer_selectors(); - int a[2] = {10, 20}; - int index = 1; - int value = (a[index] = 99); - std::printf("stable index %d %d %d %d\n", index, value, a[0], a[1]); - value = (a[index - 1] = 42); - std::printf("stable arithmetic %d %d %d\n", value, a[0], a[1]); - struct Index { - int value; - } selector{1}; - value = (a[selector.value] = 88); - int rows[2][2] = {{1, 2}, {3, 4}}; - int row_value = (rows[index][index] = 55); - std::printf("stable composite %d %d %d\n", value, a[1], row_value); - int &alias = a[0]; - alias = 0; - value = (a[alias] = 1); - std::printf("aliased index %d %d %d\n", value, a[0], a[1]); - int *pointer = a; - int (&reference)[2] = a; - value = (pointer[index] = 66); - int reference_value = (reference[index] = 77); - int deref_value = (*pointer = 55); - std::printf("stable indirect %d %d %d %d %d\n", value, reference_value, - deref_value, a[0], a[1]); - int indices[2] = {1, 0}; - value = (pointer[selector.value] = 55); - reference_value = (reference[indices[0]] = 44); - deref_value = (*(pointer + selector.value) = 33); - std::printf("aggregate selectors %d %d %d %d\n", value, reference_value, - deref_value, a[1]); - struct Owner { - int values[2]; - int index; - } owner{{0, 20}, 0}; - value = (owner.values[owner.values[0]] = 1); - reference_value = (owner.values[owner.index] = 11); - std::printf("owner selectors %d %d %d %d\n", value, reference_value, - owner.values[0], owner.values[1]); - Index alias_selector{0}; - int *member_alias = &alias_selector.value; - value = (member_alias[alias_selector.value] = 1); - std::printf("member alias %d %d\n", value, alias_selector.value); - int self_index = 0; - int *self = &self_index; - value = (self[self_index] = 1); - std::printf("aliased indirect %d %d\n", value, self_index); - int captured_index = 0; - int *captured_pointer = &captured_index; - auto assign_captured = [&] { - return (captured_pointer[captured_index] = 10000); - }; - value = assign_captured(); - std::printf("captured indirect %d %d\n", value, captured_index); - test_local_members(); - test_global_members(); - test_static_members(); - test_reference_members(); - test_reference_members(); - test_reference_pointer(); - test_reference_subfields(); - test_reference_subfields(); - test_captured_alias(); test(); test(); - test(); - test_comma(); - test_comma(); - unsigned values[2] = {10, 20}; - unsigned (&ref)[2] = values; - int i = 0; - unsigned result = ((++i, ref)[0] += 5); - std::printf("array reference %d %u %u\n", i, result, values[0]); - test_borrows(); - test_binding(); - test_alias_scopes(10); - test_boxed_array(); - test_boxed_array(); - unsigned global_result = (global_array[global_array[0]] += 1); - std::printf("global array %u %u\n", global_result, global_array[0]); - i = 0; - result = (global_rows[global_rows[i++][0]][0] += 1); - std::printf("nested array %d %u %u %u\n", i, result, global_rows[0][0], - global_rows[1][0]); - return 0; } diff --git a/tests/unit/out/refcount/assign_as_value.rs b/tests/unit/out/refcount/assign_as_value.rs index fc16954184..ca00769b39 100644 --- a/tests/unit/out/refcount/assign_as_value.rs +++ b/tests/unit/out/refcount/assign_as_value.rs @@ -12,35 +12,13 @@ pub fn main() { } fn main_0() -> i32 { let buf: Value> = Rc::new(RefCell::new((0..2).map(|_| 0_i8).collect::>())); - let p: Value> = Rc::new(RefCell::new(buf.decay())); + let mut p: Ptr = buf.decay(); let mut q: Ptr = Ptr::::null(); q = { - (*p.borrow_mut()) += 1; - (*p.borrow()).clone() + p += 1; + (p).clone() }; assert!(({ (q).clone() } == { buf.decay().offset((1) as isize) })); - q = { - (*p.borrow_mut()) -= 1; - (*p.borrow()).clone() - }; - assert!(({ ({ (*p.borrow()).clone() } == { buf.decay() }) })); - assert!(({ (q).clone() } == { buf.decay() })); - (*p.borrow_mut()) += 1; - let mut i: i32 = 0; - q = { - match ( - { 1 }, - &((p.as_pointer()).offset((i.postfix_inc()) as isize)), - ) { - (__tmp_0, __tmp_1) => __tmp_1.with_mut(|__tmp_1| { - (*__tmp_1) = (*__tmp_1).offset(-(__tmp_0 as isize)); - (*__tmp_1).clone() - }), - } - }; - assert!((i == 1)); - assert!(({ ({ (*p.borrow()).clone() } == { buf.decay() }) })); - assert!(({ (q).clone() } == { buf.decay() })); let mut out: i8 = 0_i8; 'switch: { match { diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 91afc5bc25..7e87d7ca85 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn test_0() { - let mut a: [u32; 3] = [10_u32, 20_u32, 30_u32]; + let mut a: [u32; 4] = [10_u32, 20_u32, 30_u32, 40_u32]; let mut i: i32 = 0; { match ({ 5_u32 }, &mut (a[(i.postfix_inc()) as usize])) { @@ -16,29 +16,14 @@ pub fn test_0() { } } }; - printf!( - b"void %d %d %d\n", - i, - (a[(0) as usize] as i32), - (a[(1) as usize] as i32) - ); - i = 0; - let mut sum: u32 = ({ - match ({ 2_u32 }, &mut (a[(i.postfix_inc()) as usize])) { + let mut compound: u32 = ({ + match ({ 5_u32 }, &mut (a[(i.postfix_inc()) as usize])) { (__tmp_2, __tmp_3) => { (*__tmp_3) = (((*__tmp_3) as u32).wrapping_add((__tmp_2 as u32))) as u32; (*__tmp_3).clone() } } }); - printf!( - b"compound %d %d %d %d\n", - i, - (sum as i32), - (a[(0) as usize] as i32), - (a[(1) as usize] as i32) - ); - i = 0; let mut assigned: u32 = ({ match ({ 99_u32 }, &mut (a[(i.postfix_inc()) as usize])) { (__tmp_4, __tmp_5) => { @@ -48,2410 +33,60 @@ pub fn test_0() { } }); printf!( - b"simple %d %d %d %d\n", + b"%d %d %d: %d %d %d %d\n", i, + (compound as i32), (assigned as i32), (a[(0) as usize] as i32), - (a[(1) as usize] as i32) - ); - let mut plain: u32 = 10_u32; - plain = { (plain).wrapping_add(5_u32) }; - let mut plain_result: u32 = ({ - plain = { (plain).wrapping_add(2_u32) }; - plain - }); - printf!(b"plain %d %d\n", (plain_result as i32), (plain as i32)); - i = 0; - { - match ( - { - { - i = 1; - 5_u32 - } - }, - &mut (a[(i) as usize]), - ) { - (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as u32).wrapping_add((__tmp_6 as u32))) as u32; - } - } - }; - printf!( - b"rhs target %d %d %d\n", - i, - (a[(0) as usize] as i32), - (a[(1) as usize] as i32) - ); - a[(0) as usize] = 0_u32; - let mut selected: u32 = ({ - match ({ 1_u32 }, &mut (a[(a[(0) as usize]) as usize])) { - (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as u32).wrapping_add((__tmp_8 as u32))) as u32; - (*__tmp_9).clone() - } - } - }); - printf!( - b"self compound %d %d %d\n", - (selected as i32), - (a[(0) as usize] as i32), - (a[(1) as usize] as i32) - ); - a[(0) as usize] = 0_u32; - selected = ({ - match ({ 1_u32 }, &mut (a[(a[(0) as usize]) as usize])) { - (__tmp_10, __tmp_11) => { - (*__tmp_11) = __tmp_10; - (*__tmp_11).clone() - } - } - }); - printf!( - b"self simple %d %d %d\n", - (selected as i32), - (a[(0) as usize] as i32), - (a[(1) as usize] as i32) + (a[(1) as usize] as i32), + (a[(2) as usize] as i32), + (a[(3) as usize] as i32) ); } pub fn test_1() { - let mut a: [i16; 3] = [10_i16, 20_i16, 30_i16]; + let mut a: [i16; 4] = [10_i16, 20_i16, 30_i16, 40_i16]; let mut i: i32 = 0; { match ({ 5 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = (((*__tmp_13) as i32) + (__tmp_12 as i32)) as i16; + (__tmp_6, __tmp_7) => { + (*__tmp_7) = (((*__tmp_7) as i32) + (__tmp_6 as i32)) as i16; } } }; - printf!( - b"void %d %d %d\n", - i, - (a[(0) as usize] as i32), - (a[(1) as usize] as i32) - ); - i = 0; - let mut sum: i16 = ({ - match ({ 2 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_14, __tmp_15) => { - (*__tmp_15) = (((*__tmp_15) as i32) + (__tmp_14 as i32)) as i16; - (*__tmp_15).clone() + let mut compound: i16 = ({ + match ({ 5 }, &mut (a[(i.postfix_inc()) as usize])) { + (__tmp_8, __tmp_9) => { + (*__tmp_9) = (((*__tmp_9) as i32) + (__tmp_8 as i32)) as i16; + (*__tmp_9).clone() } } }); - printf!( - b"compound %d %d %d %d\n", - i, - (sum as i32), - (a[(0) as usize] as i32), - (a[(1) as usize] as i32) - ); - i = 0; let mut assigned: i16 = ({ match ({ 99_i16 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_16, __tmp_17) => { - (*__tmp_17) = __tmp_16; - (*__tmp_17).clone() + (__tmp_10, __tmp_11) => { + (*__tmp_11) = __tmp_10; + (*__tmp_11).clone() } } }); printf!( - b"simple %d %d %d %d\n", + b"%d %d %d: %d %d %d %d\n", i, + (compound as i32), (assigned as i32), (a[(0) as usize] as i32), - (a[(1) as usize] as i32) - ); - let mut plain: i16 = 10_i16; - plain = { ((plain as i32) + 5) as i16 }; - let mut plain_result: i16 = ({ - plain = { ((plain as i32) + 2) as i16 }; - plain - }); - printf!(b"plain %d %d\n", (plain_result as i32), (plain as i32)); - i = 0; - { - match ( - { - ({ - i = 1; - 5_i16 - } as i32) - }, - &mut (a[(i) as usize]), - ) { - (__tmp_18, __tmp_19) => { - (*__tmp_19) = (((*__tmp_19) as i32) + (__tmp_18 as i32)) as i16; - } - } - }; - printf!( - b"rhs target %d %d %d\n", - i, - (a[(0) as usize] as i32), - (a[(1) as usize] as i32) - ); - a[(0) as usize] = 0_i16; - let mut selected: i16 = ({ - match ({ 1 }, &mut (a[(a[(0) as usize]) as usize])) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = (((*__tmp_21) as i32) + (__tmp_20 as i32)) as i16; - (*__tmp_21).clone() - } - } - }); - printf!( - b"self compound %d %d %d\n", - (selected as i32), - (a[(0) as usize] as i32), - (a[(1) as usize] as i32) - ); - a[(0) as usize] = 0_i16; - selected = ({ - match ({ 1_i16 }, &mut (a[(a[(0) as usize]) as usize])) { - (__tmp_22, __tmp_23) => { - (*__tmp_23) = __tmp_22; - (*__tmp_23).clone() - } - } - }); - printf!( - b"self simple %d %d %d\n", - (selected as i32), - (a[(0) as usize] as i32), - (a[(1) as usize] as i32) - ); -} -pub fn test_2() { - let mut a: [i32; 3] = [10, 20, 30]; - let mut i: i32 = 0; - a[(i.postfix_inc()) as usize] += 5; - printf!(b"void %d %d %d\n", i, a[(0) as usize], a[(1) as usize]); - i = 0; - let mut sum: i32 = ({ - match ({ 2 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_24, __tmp_25) => { - (*__tmp_25) = (((*__tmp_25) as i32) + (__tmp_24 as i32)) as i32; - (*__tmp_25).clone() - } - } - }); - printf!( - b"compound %d %d %d %d\n", - i, - sum, - a[(0) as usize], - a[(1) as usize] - ); - i = 0; - let mut assigned: i32 = ({ - match ({ 99 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_26, __tmp_27) => { - (*__tmp_27) = __tmp_26; - (*__tmp_27).clone() - } - } - }); - printf!( - b"simple %d %d %d %d\n", - i, - assigned, - a[(0) as usize], - a[(1) as usize] - ); - let mut plain: i32 = 10; - plain += 5; - let mut plain_result: i32 = ({ - plain += 2; - plain - }); - printf!(b"plain %d %d\n", plain_result, plain); - i = 0; - let __rhs = { - i = 1; - 5 - }; - a[(i) as usize] += __rhs; - printf!( - b"rhs target %d %d %d\n", - i, - a[(0) as usize], - a[(1) as usize] - ); - a[(0) as usize] = 0; - let mut selected: i32 = ({ - match ({ 1 }, &mut (a[(a[(0) as usize]) as usize])) { - (__tmp_28, __tmp_29) => { - (*__tmp_29) = (((*__tmp_29) as i32) + (__tmp_28 as i32)) as i32; - (*__tmp_29).clone() - } - } - }); - printf!( - b"self compound %d %d %d\n", - selected, - a[(0) as usize], - a[(1) as usize] - ); - a[(0) as usize] = 0; - selected = ({ - match ({ 1 }, &mut (a[(a[(0) as usize]) as usize])) { - (__tmp_30, __tmp_31) => { - (*__tmp_31) = __tmp_30; - (*__tmp_31).clone() - } - } - }); - printf!( - b"self simple %d %d %d\n", - selected, - a[(0) as usize], - a[(1) as usize] - ); -} -pub fn test_comma_3() { - let x: Value = Rc::new(RefCell::new(10_u32)); - let mut i: i32 = 0; - { - match ( - { 5_u32 }, - &({ - i.prefix_inc(); - x.as_pointer() - }), - ) { - (__tmp_32, __tmp_33) => __tmp_33.with_mut(|__tmp_33| { - (*__tmp_33) = (((*__tmp_33) as u32).wrapping_add((__tmp_32 as u32))) as u32; - }), - } - }; - printf!(b"direct void %d %d\n", i, ((*x.borrow()) as i32)); - let mut result: u32 = ({ - match ( - { 2_u32 }, - &({ - i.prefix_inc(); - x.as_pointer() - }), - ) { - (__tmp_34, __tmp_35) => __tmp_35.with_mut(|__tmp_35| { - (*__tmp_35) = (((*__tmp_35) as u32).wrapping_add((__tmp_34 as u32))) as u32; - (*__tmp_35).clone() - }), - } - }); - printf!( - b"direct compound %d %d %d\n", - i, - (result as i32), - ((*x.borrow()) as i32) - ); - result = ({ - match ( - { 99_u32 }, - &({ - i.prefix_inc(); - x.as_pointer() - }), - ) { - (__tmp_36, __tmp_37) => __tmp_37.with_mut(|__tmp_37| { - (*__tmp_37) = __tmp_36; - (*__tmp_37).clone() - }), - } - }); - printf!( - b"direct simple %d %d %d\n", - i, - (result as i32), - ((*x.borrow()) as i32) - ); - let mut p: Ptr = (x.as_pointer()); - { - match ( - { 5_u32 }, - &({ - i.prefix_inc(); - (p).clone() - }), - ) { - (__tmp_38, __tmp_39) => __tmp_39.with_mut(|__tmp_39| { - (*__tmp_39) = (((*__tmp_39) as u32).wrapping_add((__tmp_38 as u32))) as u32; - }), - } - }; - printf!(b"indirect void %d %d\n", i, ((p.read()) as i32)); - let __rhs = ({ - match ( - { 2_u32 }, - &({ - i.prefix_inc(); - (p).clone() - }), - ) { - (__tmp_40, __tmp_41) => __tmp_41.with_mut(|__tmp_41| { - (*__tmp_41) = (((*__tmp_41) as u32).wrapping_add((__tmp_40 as u32))) as u32; - (*__tmp_41).clone() - }), - } - }); - result = __rhs; - printf!( - b"indirect compound %d %d %d\n", - i, - (result as i32), - ((p.read()) as i32) + (a[(1) as usize] as i32), + (a[(2) as usize] as i32), + (a[(3) as usize] as i32) ); - let __rhs = ({ - match ( - { 99_u32 }, - &({ - i.prefix_inc(); - (p).clone() - }), - ) { - (__tmp_42, __tmp_43) => __tmp_43.with_mut(|__tmp_43| { - (*__tmp_43) = __tmp_42; - (*__tmp_43).clone() - }), - } - }); - result = __rhs; - printf!( - b"indirect simple %d %d %d\n", - i, - (result as i32), - ((p.read()) as i32) - ); -} -pub fn test_comma_4() { - let x: Value = Rc::new(RefCell::new(10_i16)); - let mut i: i32 = 0; - { - match ( - { 5 }, - &({ - i.prefix_inc(); - x.as_pointer() - }), - ) { - (__tmp_44, __tmp_45) => __tmp_45.with_mut(|__tmp_45| { - (*__tmp_45) = (((*__tmp_45) as i32) + (__tmp_44 as i32)) as i16; - }), - } - }; - printf!(b"direct void %d %d\n", i, ((*x.borrow()) as i32)); - let mut result: i16 = ({ - match ( - { 2 }, - &({ - i.prefix_inc(); - x.as_pointer() - }), - ) { - (__tmp_46, __tmp_47) => __tmp_47.with_mut(|__tmp_47| { - (*__tmp_47) = (((*__tmp_47) as i32) + (__tmp_46 as i32)) as i16; - (*__tmp_47).clone() - }), - } - }); - printf!( - b"direct compound %d %d %d\n", - i, - (result as i32), - ((*x.borrow()) as i32) - ); - result = ({ - match ( - { 99_i16 }, - &({ - i.prefix_inc(); - x.as_pointer() - }), - ) { - (__tmp_48, __tmp_49) => __tmp_49.with_mut(|__tmp_49| { - (*__tmp_49) = __tmp_48; - (*__tmp_49).clone() - }), - } - }); - printf!( - b"direct simple %d %d %d\n", - i, - (result as i32), - ((*x.borrow()) as i32) - ); - let mut p: Ptr = (x.as_pointer()); - { - match ( - { 5 }, - &({ - i.prefix_inc(); - (p).clone() - }), - ) { - (__tmp_50, __tmp_51) => __tmp_51.with_mut(|__tmp_51| { - (*__tmp_51) = (((*__tmp_51) as i32) + (__tmp_50 as i32)) as i16; - }), - } - }; - printf!(b"indirect void %d %d\n", i, ((p.read()) as i32)); - let __rhs = ({ - match ( - { 2 }, - &({ - i.prefix_inc(); - (p).clone() - }), - ) { - (__tmp_52, __tmp_53) => __tmp_53.with_mut(|__tmp_53| { - (*__tmp_53) = (((*__tmp_53) as i32) + (__tmp_52 as i32)) as i16; - (*__tmp_53).clone() - }), - } - }); - result = __rhs; - printf!( - b"indirect compound %d %d %d\n", - i, - (result as i32), - ((p.read()) as i32) - ); - let __rhs = ({ - match ( - { 99_i16 }, - &({ - i.prefix_inc(); - (p).clone() - }), - ) { - (__tmp_54, __tmp_55) => __tmp_55.with_mut(|__tmp_55| { - (*__tmp_55) = __tmp_54; - (*__tmp_55).clone() - }), - } - }); - result = __rhs; - printf!( - b"indirect simple %d %d %d\n", - i, - (result as i32), - ((p.read()) as i32) - ); -} -pub fn test_reference_members_5() { - let index: Value = Rc::new(RefCell::new(0_u32)); - let other: Value = Rc::new(RefCell::new(77_u32)); - let mut a: [Slot_6; 2] = [ - Slot_6 { - value: index.as_pointer(), - }, - Slot_6 { - value: other.as_pointer(), - }, - ]; - { - match ({ 1_u32 }, { - let __tmp_57 = (a[(*index.borrow()) as usize].value).clone(); - __tmp_57 - }) { - (__tmp_56, __tmp_57) => __tmp_57.with_mut(|__tmp_57| { - (*__tmp_57) = (((*__tmp_57) as u32).wrapping_add((__tmp_56 as u32))) as u32; - }), - } - }; - printf!( - b"reference void %d %d\n", - ((*index.borrow()) as i32), - ((*other.borrow()) as i32) - ); - (*index.borrow_mut()) = 0_u32; - let mut result: u32 = ({ - match ({ 1_u32 }, { - let __tmp_59 = (a[(*index.borrow()) as usize].value).clone(); - __tmp_59 - }) { - (__tmp_58, __tmp_59) => __tmp_59.with_mut(|__tmp_59| { - (*__tmp_59) = (((*__tmp_59) as u32).wrapping_add((__tmp_58 as u32))) as u32; - (*__tmp_59).clone() - }), - } - }); - printf!( - b"reference compound %d %d %d\n", - ((*index.borrow()) as i32), - ((*other.borrow()) as i32), - (result as i32) - ); - (*index.borrow_mut()) = 0_u32; - let __rhs = ({ - match ({ 1_u32 }, { - let __tmp_61 = (a[(*index.borrow()) as usize].value).clone(); - __tmp_61 - }) { - (__tmp_60, __tmp_61) => __tmp_61.with_mut(|__tmp_61| { - (*__tmp_61) = __tmp_60; - (*__tmp_61).clone() - }), - } - }); - result = __rhs; - printf!( - b"reference simple %d %d %d\n", - ((*index.borrow()) as i32), - ((*other.borrow()) as i32), - (result as i32) - ); - (*index.borrow_mut()) = 0_u32; - let __rhs = ({ - match ({ 1_u32 }, { - let __tmp_63 = (a[((*index.borrow_mut()).postfix_inc()) as usize].value).clone(); - __tmp_63 - }) { - (__tmp_62, __tmp_63) => __tmp_63.with_mut(|__tmp_63| { - (*__tmp_63) = (((*__tmp_63) as u32).wrapping_add((__tmp_62 as u32))) as u32; - (*__tmp_63).clone() - }), - } - }); - result = __rhs; - printf!( - b"reference effect %d %d %d\n", - ((*index.borrow()) as i32), - ((*other.borrow()) as i32), - (result as i32) - ); - (*index.borrow_mut()) = 0_u32; - let __rhs = ({ - match ( - { - { - (*index.borrow_mut()) = 1_u32; - 2_u32 - } - }, - { - let __tmp_65 = (a[(*index.borrow()) as usize].value).clone(); - __tmp_65 - }, - ) { - (__tmp_64, __tmp_65) => __tmp_65.with_mut(|__tmp_65| { - (*__tmp_65) = (((*__tmp_65) as u32).wrapping_add((__tmp_64 as u32))) as u32; - (*__tmp_65).clone() - }), - } - }); - result = __rhs; - printf!( - b"reference rhs %d %d %d\n", - ((*index.borrow()) as i32), - ((*other.borrow()) as i32), - (result as i32) - ); -} -pub fn test_reference_members_7() { - let index: Value = Rc::new(RefCell::new(0_i16)); - let other: Value = Rc::new(RefCell::new(77_i16)); - let mut a: [Slot_8; 2] = [ - Slot_8 { - value: index.as_pointer(), - }, - Slot_8 { - value: other.as_pointer(), - }, - ]; - { - match ({ 1 }, { - let __tmp_67 = (a[(*index.borrow()) as usize].value).clone(); - __tmp_67 - }) { - (__tmp_66, __tmp_67) => __tmp_67.with_mut(|__tmp_67| { - (*__tmp_67) = (((*__tmp_67) as i32) + (__tmp_66 as i32)) as i16; - }), - } - }; - printf!( - b"reference void %d %d\n", - ((*index.borrow()) as i32), - ((*other.borrow()) as i32) - ); - (*index.borrow_mut()) = 0_i16; - let mut result: i16 = ({ - match ({ 1 }, { - let __tmp_69 = (a[(*index.borrow()) as usize].value).clone(); - __tmp_69 - }) { - (__tmp_68, __tmp_69) => __tmp_69.with_mut(|__tmp_69| { - (*__tmp_69) = (((*__tmp_69) as i32) + (__tmp_68 as i32)) as i16; - (*__tmp_69).clone() - }), - } - }); - printf!( - b"reference compound %d %d %d\n", - ((*index.borrow()) as i32), - ((*other.borrow()) as i32), - (result as i32) - ); - (*index.borrow_mut()) = 0_i16; - let __rhs = ({ - match ({ 1_i16 }, { - let __tmp_71 = (a[(*index.borrow()) as usize].value).clone(); - __tmp_71 - }) { - (__tmp_70, __tmp_71) => __tmp_71.with_mut(|__tmp_71| { - (*__tmp_71) = __tmp_70; - (*__tmp_71).clone() - }), - } - }); - result = __rhs; - printf!( - b"reference simple %d %d %d\n", - ((*index.borrow()) as i32), - ((*other.borrow()) as i32), - (result as i32) - ); - (*index.borrow_mut()) = 0_i16; - let __rhs = ({ - match ({ 1 }, { - let __tmp_73 = (a[((*index.borrow_mut()).postfix_inc()) as usize].value).clone(); - __tmp_73 - }) { - (__tmp_72, __tmp_73) => __tmp_73.with_mut(|__tmp_73| { - (*__tmp_73) = (((*__tmp_73) as i32) + (__tmp_72 as i32)) as i16; - (*__tmp_73).clone() - }), - } - }); - result = __rhs; - printf!( - b"reference effect %d %d %d\n", - ((*index.borrow()) as i32), - ((*other.borrow()) as i32), - (result as i32) - ); - (*index.borrow_mut()) = 0_i16; - let __rhs = ({ - match ( - { - ({ - (*index.borrow_mut()) = 1_i16; - 2_i16 - } as i32) - }, - { - let __tmp_75 = (a[(*index.borrow()) as usize].value).clone(); - __tmp_75 - }, - ) { - (__tmp_74, __tmp_75) => __tmp_75.with_mut(|__tmp_75| { - (*__tmp_75) = (((*__tmp_75) as i32) + (__tmp_74 as i32)) as i16; - (*__tmp_75).clone() - }), - } - }); - result = __rhs; - printf!( - b"reference rhs %d %d %d\n", - ((*index.borrow()) as i32), - ((*other.borrow()) as i32), - (result as i32) - ); -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(8)] -pub struct Slot_6 { - #[offset(0)] - #[byte_size(8)] - pub value: Ptr, -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(8)] -pub struct Slot_8 { - #[offset(0)] - #[byte_size(8)] - pub value: Ptr, -} -pub fn test_reference_pointer_9() { - let p: Value> = Rc::new(RefCell::new(Ptr::::null())); - let q: Value> = Rc::new(RefCell::new(Ptr::::null())); - let first: Value = Rc::new(RefCell::new(Node_10 { - link: p.as_pointer(), - })); - let second: Value = Rc::new(RefCell::new(Node_10 { - link: q.as_pointer(), - })); - (*p.borrow_mut()) = (first.as_pointer()); - (*q.borrow_mut()) = (first.as_pointer()); - let mut result: Ptr = ({ - match ({ (second.as_pointer()) }, { - let __tmp_77 = ((*p.borrow()).with(|__s| __s.link.clone())).clone(); - __tmp_77 - }) { - (__tmp_76, __tmp_77) => __tmp_77.with_mut(|__tmp_77| { - (*__tmp_77) = __tmp_76; - (*__tmp_77).clone() - }), - } - }); - printf!( - b"reference pointer %d %d\n", - (({ (*p.borrow()).clone() } == { (second.as_pointer()) }) as i32), - (({ (result).clone() } == { (second.as_pointer()) }) as i32) - ); -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(8)] -pub struct Node_10 { - #[offset(0)] - #[byte_size(8)] - pub link: Ptr>, -} -pub fn test_reference_subfields_11() { - let index: Value = Rc::new(RefCell::new(Index_12 { value: 0_u32 })); - let other: Value = Rc::new(RefCell::new(Index_12 { value: 77_u32 })); - let mut a: [Slot_13; 2] = [ - Slot_13 { - ref_: index.as_pointer(), - }, - Slot_13 { - ref_: other.as_pointer(), - }, - ]; - let mut result: u32 = ({ - match ({ 1_u32 }, { - let __tmp_79 = (field!(a[({ (*index.borrow()).value }) as usize].ref_, value)).clone(); - __tmp_79 - }) { - (__tmp_78, __tmp_79) => __tmp_79.with_mut(|__tmp_79| { - (*__tmp_79) = (((*__tmp_79) as u32).wrapping_add((__tmp_78 as u32))) as u32; - (*__tmp_79).clone() - }), - } - }); - printf!( - b"reference subfield compound %d %d %d\n", - (result as i32), - ({ (*index.borrow()).value } as i32), - ({ (*other.borrow()).value } as i32) - ); - (*index.borrow_mut()).value = 0_u32; - result = ({ - match ({ 1_u32 }, { - let __tmp_81 = (field!(a[({ (*index.borrow()).value }) as usize].ref_, value)).clone(); - __tmp_81 - }) { - (__tmp_80, __tmp_81) => __tmp_81.with_mut(|__tmp_81| { - (*__tmp_81) = __tmp_80; - (*__tmp_81).clone() - }), - } - }); - printf!( - b"reference subfield simple %d %d %d\n", - (result as i32), - ({ (*index.borrow()).value } as i32), - ({ (*other.borrow()).value } as i32) - ); -} -pub fn test_reference_subfields_14() { - let index: Value = Rc::new(RefCell::new(Index_15 { value: 0_i16 })); - let other: Value = Rc::new(RefCell::new(Index_15 { value: 77_i16 })); - let mut a: [Slot_16; 2] = [ - Slot_16 { - ref_: index.as_pointer(), - }, - Slot_16 { - ref_: other.as_pointer(), - }, - ]; - let mut result: i16 = ({ - match ({ 1 }, { - let __tmp_83 = (field!(a[({ (*index.borrow()).value }) as usize].ref_, value)).clone(); - __tmp_83 - }) { - (__tmp_82, __tmp_83) => __tmp_83.with_mut(|__tmp_83| { - (*__tmp_83) = (((*__tmp_83) as i32) + (__tmp_82 as i32)) as i16; - (*__tmp_83).clone() - }), - } - }); - printf!( - b"reference subfield compound %d %d %d\n", - (result as i32), - ({ (*index.borrow()).value } as i32), - ({ (*other.borrow()).value } as i32) - ); - (*index.borrow_mut()).value = 0_i16; - result = ({ - match ({ 1_i16 }, { - let __tmp_85 = (field!(a[({ (*index.borrow()).value }) as usize].ref_, value)).clone(); - __tmp_85 - }) { - (__tmp_84, __tmp_85) => __tmp_85.with_mut(|__tmp_85| { - (*__tmp_85) = __tmp_84; - (*__tmp_85).clone() - }), - } - }); - printf!( - b"reference subfield simple %d %d %d\n", - (result as i32), - ({ (*index.borrow()).value } as i32), - ({ (*other.borrow()).value } as i32) - ); -} -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(4)] -pub struct Index_12 { - #[offset(0)] - pub value: u32, -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(8)] -pub struct Slot_13 { - #[offset(0)] - #[byte_size(8)] - pub ref_: Ptr, -} -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(2)] -pub struct Index_15 { - #[offset(0)] - pub value: i16, -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(8)] -pub struct Slot_16 { - #[offset(0)] - #[byte_size(8)] - pub ref_: Ptr, -} -pub fn test_captured_alias_17() { - let x: Value = Rc::new(RefCell::new(10_i16)); - let p: Value> = Rc::new(RefCell::new((x.as_pointer()))); - let f: Value i16>> = Rc::new(RefCell::new(lambda!( - { - let x: Ptr = x.as_pointer(); - let p: Ptr> = p.as_pointer(); - }, - || -> i16 { - return ({ - match ( - { - { - (p.read()).write((-1_i32 as i16)); - 0.5_f64 - } - }, - &(x), - ) { - (__tmp_86, __tmp_87) => __tmp_87.with_mut(|__tmp_87| { - (*__tmp_87) = (((*__tmp_87) as f64) + (__tmp_86 as f64)) as i16; - (*__tmp_87).clone() - }), - } - }); - } - ))); - let mut result: i32 = (({ (*f.borrow()).call() }) as i32); - printf!( - b"captured outer alias %d %d\n", - result, - ((*x.borrow()) as i32) - ); -} -thread_local!( - pub static global_18: Value = Rc::new(RefCell::new(10)); -); -pub fn observe_global_19(mut assigned: i32) -> i32 { - return (assigned + global_18.with(|rc| *rc.borrow())); -} -pub fn observe_20(mut assigned: i32, mut stored: Ptr) -> i32 { - return ({ assigned } + { (stored.read()) }); -} -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(4)] -pub struct GlobalRecord_Inner { - #[offset(0)] - pub value: i32, -} -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(4)] -pub struct GlobalRecord { - #[offset(0)] - #[byte_size(4)] - pub inner: GlobalRecord_Inner, -} -thread_local!( - pub static global_record_21: Value = Rc::new(RefCell::new(GlobalRecord { - inner: GlobalRecord_Inner { value: 10 }, - })); -); -pub fn observe_record_22(mut assigned: i32) -> i32 { - return (assigned + { global_record_21.with(|rc| *rc.borrow()).inner.value }); -} -thread_local!( - pub static targets_23: Value> = Rc::new(RefCell::new(Box::new([10, 20]))); -); -thread_local!( - pub static cursor_24: Value> = Rc::new(RefCell::new(targets_23.with(|v| v.decay()))); -); -pub fn test_borrows_25() { - printf!( - b"%d\n", - ({ - observe_global_19({ - global_18.with(|rc| *rc.borrow_mut() = 99); - global_18.with(|rc| *rc.borrow()) - }) - }) - ); - printf!( - b"%d\n", - ({ - observe_global_19({ - global_18.with(|rc| *rc.borrow_mut() += 5); - global_18.with(|rc| *rc.borrow()) - }) - }) - ); - printf!( - b"%d\n", - ({ - observe_global_19({ - let __rhs = ({ observe_20(0, (global_18.with(|v| v.as_pointer()))) }); - global_18.with(|rc| *rc.borrow_mut() = __rhs); - global_18.with(|rc| *rc.borrow()) - }) - }) - ); - let mut assigned: i32 = (({ - let __tmp_88 = { - promoted_26.with(|rc| *rc.borrow_mut() = (-1_i32 as i16)); - 0.5_f64 - }; - { - let rhs_0 = ((promoted_26.with(|rc| *rc.borrow()) as f64) + (__tmp_88 as f64)) as i16; - promoted_26.with(|rc| *rc.borrow_mut() = rhs_0); - promoted_26.with(|rc| *rc.borrow()) - } - }) as i32); - printf!( - b"%d %d\n", - assigned, - (promoted_26.with(|rc| *rc.borrow()) as i32) - ); - let aliased: Value = Rc::new(RefCell::new(10_i16)); - let mut alias: Ptr = (aliased.as_pointer()); - assigned = (({ - match ( - { - { - alias.write((-1_i32 as i16)); - 0.5_f64 - } - }, - &mut (*aliased.borrow_mut()), - ) { - (__tmp_89, __tmp_90) => { - (*__tmp_90) = (((*__tmp_90) as f64) + (__tmp_89 as f64)) as i16; - (*__tmp_90).clone() - } - } - }) as i32); - printf!(b"%d %d\n", assigned, ((*aliased.borrow()) as i32)); - let mut enabled: bool = ({ - let __tmp_91 = { - ({ observe_20(0, (global_18.with(|v| v.as_pointer()))) }); - 0.5_f64 - }; - { - let rhs_0 = ((flag_27.with(|rc| *rc.borrow()) as u8 as f64) + (__tmp_91 as f64)) != 0.0; - flag_27.with(|rc| *rc.borrow_mut() = rhs_0); - flag_27.with(|rc| *rc.borrow()) - } - }); - printf!( - b"%d %d\n", - (enabled as i32), - (flag_27.with(|rc| *rc.borrow()) as i32) - ); - printf!( - b"%d\n", - ({ - observe_record_22({ - match ( - { 99 }, - &mut ((*global_record_21.with(Value::clone).borrow_mut()) - .inner - .value), - ) { - (__tmp_92, __tmp_93) => { - (*__tmp_93) = __tmp_92; - (*__tmp_93).clone() - } - } - }) - }) - ); - let mut shifted: Ptr = ({ - let __tmp_94 = { - cursor_24 - .with(|rc| *rc.borrow_mut() = targets_23.with(|v| v.decay()).offset((1) as isize)); - 1 - }; - cursor_24.with(|rc| *rc.borrow_mut() -= (__tmp_94 as isize)); - (*cursor_24.with(Value::clone).borrow()).clone() - }); - printf!( - b"%d %d\n", - (({ (*cursor_24.with(Value::clone).borrow()).clone() } == { - targets_23.with(|v| v.decay()) - }) as i32), - (({ (shifted).clone() } == { (*cursor_24.with(Value::clone).borrow()).clone() }) as i32) - ); - let local: Value = Rc::new(RefCell::new(10)); - printf!( - b"%d\n", - ({ - let _assigned: i32 = { - (*local.borrow_mut()) = 99; - (*local.borrow()) - }; - let _stored: Ptr = (local.as_pointer()); - observe_20(_assigned, _stored) - }) - ); - printf!( - b"%d\n", - ({ - let _assigned: i32 = { - (*local.borrow_mut()) += 5; - (*local.borrow()) - }; - let _stored: Ptr = (local.as_pointer()); - observe_20(_assigned, _stored) - }) - ); - let record: Value = Rc::new(RefCell::new(Record_28 { value: 10 })); - printf!( - b"%d\n", - ({ - let _assigned: i32 = { - (*record.borrow_mut()).value = 99; - { (*record.borrow()).value } - }; - let _stored: Ptr = (field_ptr!(record.as_pointer(), value)); - observe_20(_assigned, _stored) - }) - ); - printf!( - b"%d\n", - ({ - let _assigned: i32 = { - (*record.borrow_mut()).value += 5; - { (*record.borrow()).value } - }; - let _stored: Ptr = (field_ptr!(record.as_pointer(), value)); - observe_20(_assigned, _stored) - }) - ); - let first: Value = >::default(); - *first.borrow_mut() = Link_29 { - next: (first.as_pointer()), - }; - let second: Value = Rc::new(RefCell::new(Link_29 { - next: (first.as_pointer()), - })); - let selector: Ptr> = field_ptr!(first.as_pointer(), next); - let mut selected: Ptr = ({ - match ( - { (second.as_pointer()) }, - &(field!((selector.read()), next)), - ) { - (__tmp_95, __tmp_96) => __tmp_96.with_mut(|__tmp_96| { - (*__tmp_96) = __tmp_95; - (*__tmp_96).clone() - }), - } - }); - printf!( - b"%d %d\n", - (({ (selected).clone() } == { (second.as_pointer()) }) as i32), - (({ { (*first.borrow()).next.clone() } } == { (second.as_pointer()) }) as i32) - ); - let values: Value> = Rc::new(RefCell::new(vec![10; 1_usize])); - printf!( - b"%d\n", - ({ - let _assigned: i32 = { - (*values.borrow_mut())[0_usize] = 99; - { (*values.borrow())[0_usize] } - }; - let _stored: Ptr = (values.decay().offset(0_usize)); - observe_20(_assigned, _stored) - }) - ); - printf!( - b"%d\n", - ({ - let _assigned: i32 = { - (*values.borrow_mut())[0_usize] += 5; - { (*values.borrow())[0_usize] } - }; - let _stored: Ptr = (values.decay().offset(0_usize)); - observe_20(_assigned, _stored) - }) - ); -} -thread_local!( - static promoted_26: Value = Rc::new(RefCell::new(10_i16)); -); -thread_local!( - static flag_27: Value = Rc::new(RefCell::new(false)); -); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(4)] -pub struct Record_28 { - #[offset(0)] - pub value: i32, -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(8)] -pub struct Link_29 { - #[offset(0)] - #[byte_size(8)] - pub next: Ptr, -} -thread_local!( - pub static selected_values_30: Value> = - Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); -); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(1)] -pub struct IndexedBinding {} -pub fn test_binding_31() { - let owner: Value = Rc::new(RefCell::new(::default())); - let __decomp_32: Ptr = owner.as_pointer(); - let value: Ptr = ({ IndexedBindingImpl::get_1_0(&__decomp_32) }); - let mut result: u32 = ({ - match ({ 1_u32 }, &({ IndexedBindingImpl::get_1_0(&__decomp_32) })) { - (__tmp_97, __tmp_98) => __tmp_98.with_mut(|__tmp_98| { - (*__tmp_98) = (((*__tmp_98) as u32).wrapping_add((__tmp_97 as u32))) as u32; - (*__tmp_98).clone() - }), - } - }); - printf!( - b"binding compound %u %u\n", - result, - ({ - let __idx0 = (0) as usize; - selected_values_30.with(|rc| rc.borrow()[__idx0]) - }) - ); -} -thread_local!( - pub static initializer_target_33: Value = Rc::new(RefCell::new(10_u32)); -); -pub fn mutate_initializer_34() -> u32 { - initializer_target_33.with(|rc| *rc.borrow_mut() = 20_u32); - return 1_u32; -} -thread_local!( - pub static initializer_result_35: Value = Rc::new(RefCell::new( - ({ - let __tmp_99 = ({ mutate_initializer_34() }); - { - let rhs_0 = ((initializer_target_33.with(|rc| *rc.borrow()) as u32) - .wrapping_add((__tmp_99 as u32))) as u32; - { - let __rhs = rhs_0; - initializer_target_33.with(|rc| *rc.borrow_mut() = __rhs) - }; - initializer_target_33.with(|rc| *rc.borrow()) - } - }), - )); -); -pub fn test_alias_scopes_36(parameter: i16) { - let parameter: Value = Rc::new(RefCell::new(parameter)); - let mut p: Ptr = (parameter.as_pointer()); - let mut result: i16 = ({ - match ( - { - { - p.write((-1_i32 as i16)); - 0.5_f64 - } - }, - &mut (*parameter.borrow_mut()), - ) { - (__tmp_100, __tmp_101) => { - (*__tmp_101) = (((*__tmp_101) as f64) + (__tmp_100 as f64)) as i16; - (*__tmp_101).clone() - } - } - }); - printf!( - b"parameter %d %d\n", - (result as i32), - ((*parameter.borrow()) as i32) - ); - let local: Value = Rc::new(RefCell::new(10_i16)); - let mutate: Value f64>> = Rc::new(RefCell::new(lambda!( - { - let local: Ptr = local.as_pointer(); - }, - || -> f64 { - local.write((-1_i32 as i16)); - return 0.5_f64; - } - ))); - result = ({ - match ( - { ({ (*mutate.borrow()).call() }).clone() }, - &mut (*local.borrow_mut()), - ) { - (__tmp_102, __tmp_103) => { - (*__tmp_103) = (((*__tmp_103) as f64) + (__tmp_102 as f64)) as i16; - (*__tmp_103).clone() - } - } - }); - printf!( - b"capture %d %d\n", - (result as i32), - ((*local.borrow()) as i32) - ); - printf!( - b"initializer %u %u\n", - initializer_result_35.with(|rc| *rc.borrow()), - initializer_target_33.with(|rc| *rc.borrow()) - ); -} -pub fn test_boxed_array_37() { - let a: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); - let mut p: Ptr = a.decay(); - let mut i: i32 = 0; - let mut result: u32 = ({ - match ({ 1_u32 }, { - let __tmp_105 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_105 - }) { - (__tmp_104, __tmp_105) => __tmp_105.with_mut(|__tmp_105| { - (*__tmp_105) = (((*__tmp_105) as u32).wrapping_add((__tmp_104 as u32))) as u32; - (*__tmp_105).clone() - }), - } - }); - printf!( - b"boxed compound %d %d %d %d\n", - i, - (result as i32), - ((*a.borrow())[(0) as usize] as i32), - ((p.read()) as i32) - ); - (*a.borrow_mut())[(0) as usize] = 0_u32; - i = 0; - result = ({ - match ({ 1_u32 }, { - let __tmp_107 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_107 - }) { - (__tmp_106, __tmp_107) => __tmp_107.with_mut(|__tmp_107| { - (*__tmp_107) = __tmp_106; - (*__tmp_107).clone() - }), - } - }); - printf!( - b"boxed simple %d %d %d %d\n", - i, - (result as i32), - ((*a.borrow())[(0) as usize] as i32), - ((p.read()) as i32) - ); - result = ({ - match ({ 1_u32 }, { - let __tmp_109 = saved_38.with(|v| v.decay()).offset( - ({ - let __idx0 = (0) as usize; - saved_38.with(|rc| rc.borrow()[__idx0]) - }), - ); - __tmp_109 - }) { - (__tmp_108, __tmp_109) => __tmp_109.with_mut(|__tmp_109| { - (*__tmp_109) = (((*__tmp_109) as u32).wrapping_add((__tmp_108 as u32))) as u32; - (*__tmp_109).clone() - }), - } - }); - printf!( - b"static array %d %d\n", - (result as i32), - (({ - let __idx0 = (0) as usize; - saved_38.with(|rc| rc.borrow()[__idx0]) - }) as i32) - ); -} -pub fn test_boxed_array_39() { - let a: Value> = Rc::new(RefCell::new(Box::new([0_i16, 20_i16, 30_i16]))); - let mut p: Ptr = a.decay(); - let mut i: i32 = 0; - let mut result: i16 = ({ - match ({ 1 }, { - let __tmp_111 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_111 - }) { - (__tmp_110, __tmp_111) => __tmp_111.with_mut(|__tmp_111| { - (*__tmp_111) = (((*__tmp_111) as i32) + (__tmp_110 as i32)) as i16; - (*__tmp_111).clone() - }), - } - }); - printf!( - b"boxed compound %d %d %d %d\n", - i, - (result as i32), - ((*a.borrow())[(0) as usize] as i32), - ((p.read()) as i32) - ); - (*a.borrow_mut())[(0) as usize] = 0_i16; - i = 0; - result = ({ - match ({ 1_i16 }, { - let __tmp_113 = a.decay().offset((*a.borrow())[(i.postfix_inc()) as usize]); - __tmp_113 - }) { - (__tmp_112, __tmp_113) => __tmp_113.with_mut(|__tmp_113| { - (*__tmp_113) = __tmp_112; - (*__tmp_113).clone() - }), - } - }); - printf!( - b"boxed simple %d %d %d %d\n", - i, - (result as i32), - ((*a.borrow())[(0) as usize] as i32), - ((p.read()) as i32) - ); - result = ({ - match ({ 1 }, { - let __tmp_115 = saved_40.with(|v| v.decay()).offset( - ({ - let __idx0 = (0) as usize; - saved_40.with(|rc| rc.borrow()[__idx0]) - }), - ); - __tmp_115 - }) { - (__tmp_114, __tmp_115) => __tmp_115.with_mut(|__tmp_115| { - (*__tmp_115) = (((*__tmp_115) as i32) + (__tmp_114 as i32)) as i16; - (*__tmp_115).clone() - }), - } - }); - printf!( - b"static array %d %d\n", - (result as i32), - (({ - let __idx0 = (0) as usize; - saved_40.with(|rc| rc.borrow()[__idx0]) - }) as i32) - ); -} -thread_local!( - static saved_38: Value> = Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); -); -thread_local!( - static saved_40: Value> = Rc::new(RefCell::new(Box::new([0_i16, 20_i16, 30_i16]))); -); -thread_local!( - pub static global_array_41: Value> = - Rc::new(RefCell::new(Box::new([0_u32, 20_u32, 30_u32]))); -); -thread_local!( - pub static global_rows_42: Value]>> = Rc::new(RefCell::new(Box::new([ - Box::new([0_u32, 10_u32]), - Box::new([20_u32, 30_u32]), - ]))); -); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(12)] -pub struct IndexedMember { - #[offset(0)] - pub key: i32, - #[offset(4)] - pub value: u32, - #[offset(8)] - pub promoted: i16, -} -thread_local!( - pub static global_members_43: Value> = Rc::new(RefCell::new(Box::new([ - IndexedMember { - key: 0, - value: 10_u32, - promoted: 10_i16, - }, - IndexedMember { - key: 1, - value: 20_u32, - promoted: 20_i16, - }, - ]))); -); -pub fn test_local_members_44() { - let a: Value> = Rc::new(RefCell::new(Box::new([ - IndexedMember { - key: 0, - value: 10_u32, - promoted: 10_i16, - }, - IndexedMember { - key: 1, - value: 20_u32, - promoted: 20_i16, - }, - ]))); - let mut p: Ptr = a.decay(); - let mut i: i32 = 0; - let mut result: u32 = ({ - match ({ 1_u32 }, { - let __tmp_117 = field_ptr!( - a.decay() - .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), - value - ); - __tmp_117 - }) { - (__tmp_116, __tmp_117) => __tmp_117.with_mut(|__tmp_117| { - (*__tmp_117) = (((*__tmp_117) as u32).wrapping_add((__tmp_116 as u32))) as u32; - (*__tmp_117).clone() - }), - } - }); - printf!( - b"member unsigned %d %u %u %u\n", - i, - result, - { (*a.borrow())[(0) as usize].value }, - { (*a.borrow())[(1) as usize].value } - ); - i = 0; - { - match ({ 1 }, { - let __tmp_119 = field_ptr!( - a.decay() - .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), - promoted - ); - __tmp_119 - }) { - (__tmp_118, __tmp_119) => __tmp_119.with_mut(|__tmp_119| { - (*__tmp_119) = (((*__tmp_119) as i32) + (__tmp_118 as i32)) as i16; - }), - } - }; - printf!( - b"member promoted %d %d %d\n", - i, - ({ (*a.borrow())[(0) as usize].promoted } as i32), - ({ (*a.borrow())[(1) as usize].promoted } as i32) - ); - i = 0; - result = ({ - match ({ 99_u32 }, { - let __tmp_121 = field_ptr!( - a.decay() - .offset({ (*a.borrow())[(i.postfix_inc()) as usize].key }), - value - ); - __tmp_121 - }) { - (__tmp_120, __tmp_121) => __tmp_121.with_mut(|__tmp_121| { - (*__tmp_121) = __tmp_120; - (*__tmp_121).clone() - }), - } - }); - printf!( - b"member simple %d %u %u %u\n", - i, - result, - { (*a.borrow())[(0) as usize].value }, - { (*a.borrow())[(1) as usize].value } - ); - printf!(b"member alias %u\n", p.with(|__s| __s.value)); -} -pub fn test_global_members_45() { - let mut i: i32 = 0; - let mut result: u32 = ({ - match ({ 1_u32 }, { - let __tmp_123 = field_ptr!( - global_members_43.with(|v| v.decay()).offset({ - ({ - let __idx0 = (i.postfix_inc()) as usize; - global_members_43.with(|rc| rc.borrow()[__idx0]) - }) - .key - }), - value - ); - __tmp_123 - }) { - (__tmp_122, __tmp_123) => __tmp_123.with_mut(|__tmp_123| { - (*__tmp_123) = (((*__tmp_123) as u32).wrapping_add((__tmp_122 as u32))) as u32; - (*__tmp_123).clone() - }), - } - }); - printf!( - b"member unsigned %d %u %u %u\n", - i, - result, - { - ({ - let __idx0 = (0) as usize; - global_members_43.with(|rc| rc.borrow()[__idx0]) - }) - .value - }, - { - ({ - let __idx0 = (1) as usize; - global_members_43.with(|rc| rc.borrow()[__idx0]) - }) - .value - } - ); - i = 0; - { - match ({ 1 }, { - let __tmp_125 = field_ptr!( - global_members_43.with(|v| v.decay()).offset({ - ({ - let __idx0 = (i.postfix_inc()) as usize; - global_members_43.with(|rc| rc.borrow()[__idx0]) - }) - .key - }), - promoted - ); - __tmp_125 - }) { - (__tmp_124, __tmp_125) => __tmp_125.with_mut(|__tmp_125| { - (*__tmp_125) = (((*__tmp_125) as i32) + (__tmp_124 as i32)) as i16; - }), - } - }; - printf!( - b"member promoted %d %d %d\n", - i, - ({ - ({ - let __idx0 = (0) as usize; - global_members_43.with(|rc| rc.borrow()[__idx0]) - }) - .promoted - } as i32), - ({ - ({ - let __idx0 = (1) as usize; - global_members_43.with(|rc| rc.borrow()[__idx0]) - }) - .promoted - } as i32) - ); - i = 0; - result = ({ - match ({ 99_u32 }, { - let __tmp_127 = field_ptr!( - global_members_43.with(|v| v.decay()).offset({ - ({ - let __idx0 = (i.postfix_inc()) as usize; - global_members_43.with(|rc| rc.borrow()[__idx0]) - }) - .key - }), - value - ); - __tmp_127 - }) { - (__tmp_126, __tmp_127) => __tmp_127.with_mut(|__tmp_127| { - (*__tmp_127) = __tmp_126; - (*__tmp_127).clone() - }), - } - }); - printf!( - b"member simple %d %u %u %u\n", - i, - result, - { - ({ - let __idx0 = (0) as usize; - global_members_43.with(|rc| rc.borrow()[__idx0]) - }) - .value - }, - { - ({ - let __idx0 = (1) as usize; - global_members_43.with(|rc| rc.borrow()[__idx0]) - }) - .value - } - ); -} -pub fn test_static_members_46() { - let mut i: i32 = 0; - let mut result: u32 = ({ - match ({ 1_u32 }, { - let __tmp_129 = field_ptr!( - a_47.with(|v| v.decay()).offset({ - ({ - let __idx0 = (i.postfix_inc()) as usize; - a_47.with(|rc| rc.borrow()[__idx0]) - }) - .key - }), - value - ); - __tmp_129 - }) { - (__tmp_128, __tmp_129) => __tmp_129.with_mut(|__tmp_129| { - (*__tmp_129) = (((*__tmp_129) as u32).wrapping_add((__tmp_128 as u32))) as u32; - (*__tmp_129).clone() - }), - } - }); - printf!( - b"member unsigned %d %u %u %u\n", - i, - result, - { - ({ - let __idx0 = (0) as usize; - a_47.with(|rc| rc.borrow()[__idx0]) - }) - .value - }, - { - ({ - let __idx0 = (1) as usize; - a_47.with(|rc| rc.borrow()[__idx0]) - }) - .value - } - ); - i = 0; - { - match ({ 1 }, { - let __tmp_131 = field_ptr!( - a_47.with(|v| v.decay()).offset({ - ({ - let __idx0 = (i.postfix_inc()) as usize; - a_47.with(|rc| rc.borrow()[__idx0]) - }) - .key - }), - promoted - ); - __tmp_131 - }) { - (__tmp_130, __tmp_131) => __tmp_131.with_mut(|__tmp_131| { - (*__tmp_131) = (((*__tmp_131) as i32) + (__tmp_130 as i32)) as i16; - }), - } - }; - printf!( - b"member promoted %d %d %d\n", - i, - ({ - ({ - let __idx0 = (0) as usize; - a_47.with(|rc| rc.borrow()[__idx0]) - }) - .promoted - } as i32), - ({ - ({ - let __idx0 = (1) as usize; - a_47.with(|rc| rc.borrow()[__idx0]) - }) - .promoted - } as i32) - ); - i = 0; - result = ({ - match ({ 99_u32 }, { - let __tmp_133 = field_ptr!( - a_47.with(|v| v.decay()).offset({ - ({ - let __idx0 = (i.postfix_inc()) as usize; - a_47.with(|rc| rc.borrow()[__idx0]) - }) - .key - }), - value - ); - __tmp_133 - }) { - (__tmp_132, __tmp_133) => __tmp_133.with_mut(|__tmp_133| { - (*__tmp_133) = __tmp_132; - (*__tmp_133).clone() - }), - } - }); - printf!( - b"member simple %d %u %u %u\n", - i, - result, - { - ({ - let __idx0 = (0) as usize; - a_47.with(|rc| rc.borrow()[__idx0]) - }) - .value - }, - { - ({ - let __idx0 = (1) as usize; - a_47.with(|rc| rc.borrow()[__idx0]) - }) - .value - } - ); -} -thread_local!( - static a_47: Value> = Rc::new(RefCell::new(Box::new([ - IndexedMember { - key: 0, - value: 10_u32, - promoted: 10_i16, - }, - IndexedMember { - key: 1, - value: 20_u32, - promoted: 20_i16, - }, - ]))); -); -thread_local!( - pub static scoped_values_48: Value> = - Rc::new(RefCell::new(Box::new([10_u32, 20_u32]))); -); -thread_local!( - pub static scoped_pointers_49: Value]>> = Rc::new(RefCell::new(Box::new([ - scoped_values_48.with(|v| v.decay()), - ]))); -); -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(8)] -pub struct PointerSelector { - #[offset(0)] - #[byte_size(8)] - pub ptr: Ptr, -} -thread_local!( - pub static scoped_record_50: Value = Rc::new(RefCell::new(PointerSelector { - ptr: scoped_values_48.with(|v| v.decay()), - })); -); -pub fn test_scoped_pointer_selectors_51() { - let mut i: i32 = 0; - let mut j: i32 = 1; - let mut a: u32 = ({ - elem!( - ({ - let __idx0 = (i) as usize; - scoped_pointers_49.with(|rc| rc.borrow()[__idx0].clone()) - }), - j - ) - .write(3_u32); - (elem!( - ({ - let __idx0 = (i) as usize; - scoped_pointers_49.with(|rc| rc.borrow()[__idx0].clone()) - }), - j - ) - .read()) - }); - let mut b: u32 = ({ - elem!( - ({ - let __idx0 = (i) as usize; - saved_52.with(|rc| rc.borrow()[__idx0].clone()) - }), - j - ) - .write(4_u32); - (elem!( - ({ - let __idx0 = (i) as usize; - saved_52.with(|rc| rc.borrow()[__idx0].clone()) - }), - j - ) - .read()) - }); - let mut c: u32 = ({ - elem!( - { (*scoped_record_50.with(Value::clone).borrow()).ptr.clone() }, - j - ) - .write(5_u32); - (elem!( - { (*scoped_record_50.with(Value::clone).borrow()).ptr.clone() }, - j - ) - .read()) - }); - let mut d: u32 = ({ - elem!( - { (*saved_record_53.with(Value::clone).borrow()).ptr.clone() }, - j - ) - .write(6_u32); - (elem!( - { (*saved_record_53.with(Value::clone).borrow()).ptr.clone() }, - j - ) - .read()) - }); - printf!( - b"scoped pointers %u %u %u %u %u\n", - a, - b, - c, - d, - ({ - let __idx0 = (j) as usize; - scoped_values_48.with(|rc| rc.borrow()[__idx0]) - }) - ); -} -thread_local!( - static saved_52: Value]>> = Rc::new(RefCell::new(Box::new([ - scoped_values_48.with(|v| v.decay()) - ]))); -); -thread_local!( - static saved_record_53: Value = Rc::new(RefCell::new(PointerSelector { - ptr: scoped_values_48.with(|v| v.decay()), - })); -); -pub fn test_stable_containers_54() { - let k: Value = Rc::new(RefCell::new(1)); - let mut key: u8 = 3_u8; - let mut buf: Vec = vec![10_u8; 2_usize]; - { - let rhs_0 = ((buf[((*k.borrow()) as usize)] as i32) ^ (key as i32)) as u8; - buf[((*k.borrow()) as usize)] = rhs_0 - }; - let a: Value> = Rc::new(RefCell::new(Box::<[u32]>::from([10_u32, 20_u32]))); - { - let rhs_0 = ({ (*a.borrow())[((*k.borrow()) as usize)] }).wrapping_add((1_u32 as u32)); - (*a.borrow_mut())[((*k.borrow()) as usize)] = rhs_0 - }; - let mut s: Vec = { - let mut __bytes = Ptr::::from_string_literal(b"ab").to_c_bytes(); - __bytes.push(0); - __bytes - }; - { - let rhs_0 = ((s[((*k.borrow()) as usize)] as i32) + 1) as i8; - s[((*k.borrow()) as usize)] = rhs_0 - }; - let mut owner: Counts_55 = Counts_55 { - counts: Vec::from([10_u32, 20_u32]), - }; - { - let rhs_0 = (owner.counts[((*k.borrow()) as usize)]).wrapping_add((1_u32 as u32)); - owner.counts[((*k.borrow()) as usize)] = rhs_0 - }; - let v: Value> = Rc::new(RefCell::new(vec![10; 2_usize])); - let vector_values: Value> = Rc::new(RefCell::new(vec![10_u32; 2_usize])); - let vr: Ptr> = vector_values.as_pointer(); - { - let rhs_0 = (index!(vr, ((*k.borrow()) as usize)).read()).wrapping_add((1_u32 as u32)); - index!(vr, ((*k.borrow()) as usize)).write(rhs_0) - }; - let mut ps: Vec = vec![(Pair_56 { u: 10_u32, f: 20 }); 2_usize]; - { - let rhs_0 = (ps[((*k.borrow()) as usize)].u).wrapping_add((1_u32 as u32)); - ps[((*k.borrow()) as usize)].u = rhs_0 - }; - let mut compound: i32 = ({ - (*v.borrow_mut())[((*k.borrow()) as usize)] += 1; - { (*v.borrow())[((*k.borrow()) as usize)] } - }); - let mut simple: i32 = ({ - (*v.borrow_mut())[((*k.borrow()) as usize)] = 2; - { (*v.borrow())[((*k.borrow()) as usize)] } - }); - let mut member: i32 = ({ - ps[((*k.borrow()) as usize)].f = 4; - ps[((*k.borrow()) as usize)].f - }); - let g: Value>> = Rc::new(RefCell::new(vec![vec![10; 2_usize]; 2_usize])); - let mut nested: i32 = ({ - index!( - elem!(g.decay(), ((*k.borrow()) as usize)), - ((*k.borrow()) as usize) - ) - .write(5); - (index!( - elem!(g.decay(), ((*k.borrow()) as usize)), - ((*k.borrow()) as usize) - ) - .read()) - }); - let row: Value> = Rc::new(RefCell::new(Box::new([10_u32, 20_u32]))); - let pointers: Value]>> = - Rc::new(RefCell::new(Box::new([row.decay(), row.decay()]))); - let mut rows: Ptr> = pointers.decay(); - let mut i: i32 = 0; - let mut j: i32 = 1; - let mut indirect: u32 = ({ - elem!((elem!(rows, i).read()), j).write(3_u32); - (elem!((elem!(rows, i).read()), j).read()) - }); - printf!( - b"containers %u %u %d %u %u %u %d %d %d %d %u\n", - (buf[((*k.borrow()) as usize)] as u32), - { (*a.borrow())[((*k.borrow()) as usize)] }, - (s[((*k.borrow()) as usize)] as i32), - owner.counts[((*k.borrow()) as usize)], - (index!(vr, ((*k.borrow()) as usize)).read()), - ps[((*k.borrow()) as usize)].u, - compound, - simple, - member, - nested, - indirect - ); - let it: Value> = Rc::new(RefCell::new(v.decay().begin())); - let mut iterator_value: u32 = (({ - match ({ 1_u32 }, &({ (*it.borrow()).iter_deref() })) { - (__tmp_134, __tmp_135) => __tmp_135.with_mut(|__tmp_135| { - (*__tmp_135) = (((*__tmp_135) as u32).wrapping_add((__tmp_134 as u32))) as i32; - (*__tmp_135).clone() - }), - } - }) as u32); - let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); - ({ (*m.borrow_mut()).subscript(k.as_pointer(), || 0_u32) }).write(10_u32); - let mut mapped_value: u32 = ({ - match ( - { 1_u32 }, - &({ (*m.borrow_mut()).subscript(k.as_pointer(), || 0_u32) }), - ) { - (__tmp_136, __tmp_137) => __tmp_137.with_mut(|__tmp_137| { - (*__tmp_137) = (((*__tmp_137) as u32).wrapping_add((__tmp_136 as u32))) as u32; - (*__tmp_137).clone() - }), - } - }); - printf!(b"nonflat values %u %u\n", iterator_value, mapped_value); -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] -#[byte_size(24)] -pub struct Counts_55 { - #[offset(0)] - #[byte_size(24)] - pub counts: Vec, -} -impl Counts_55 { - pub fn move_from(_a0: Ptr) -> Self { - Self { - counts: field!(_a0, counts).with_mut(std::mem::take), - } - } -} -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(8)] -pub struct Pair_56 { - #[offset(0)] - pub u: u32, - #[offset(4)] - pub f: i32, } pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ test_stable_containers_54() }); - ({ test_scoped_pointer_selectors_51() }); - let a: Value> = Rc::new(RefCell::new(Box::new([10, 20]))); - let mut index: i32 = 1; - let mut value: i32 = ({ - (*a.borrow_mut())[(index) as usize] = 99; - (*a.borrow())[(index) as usize] - }); - printf!( - b"stable index %d %d %d %d\n", - index, - value, - (*a.borrow())[(0) as usize], - (*a.borrow())[(1) as usize] - ); - value = ({ - (*a.borrow_mut())[(index - 1) as usize] = 42; - (*a.borrow())[(index - 1) as usize] - }); - printf!( - b"stable arithmetic %d %d %d\n", - value, - (*a.borrow())[(0) as usize], - (*a.borrow())[(1) as usize] - ); - let mut selector: Index_57 = Index_57 { value: 1 }; - value = ({ - (*a.borrow_mut())[(selector.value) as usize] = 88; - (*a.borrow())[(selector.value) as usize] - }); - let rows: Value]>> = - Rc::new(RefCell::new(Box::new([Box::new([1, 2]), Box::new([3, 4])]))); - let mut row_value: i32 = ({ - (*rows.borrow_mut())[(index) as usize][(index) as usize] = 55; - (*rows.borrow())[(index) as usize][(index) as usize] - }); - printf!( - b"stable composite %d %d %d\n", - value, - (*a.borrow())[(1) as usize], - row_value - ); - let alias: Ptr = a.decay().offset(0); - alias.write(0); - let __rhs = ({ - match ({ 1 }, { - let __tmp_139 = a.decay().offset((alias.read())); - __tmp_139 - }) { - (__tmp_138, __tmp_139) => __tmp_139.with_mut(|__tmp_139| { - (*__tmp_139) = __tmp_138; - (*__tmp_139).clone() - }), - } - }); - value = __rhs; - printf!( - b"aliased index %d %d %d\n", - value, - (*a.borrow())[(0) as usize], - (*a.borrow())[(1) as usize] - ); - let mut pointer: Ptr = a.decay(); - let reference: Ptr = a.decay(); - let __rhs = ({ - elem!(pointer, index).write(66); - (elem!(pointer, index).read()) - }); - value = __rhs; - let mut reference_value: i32 = ({ - elem!(reference, index).write(77); - (elem!(reference, index).read()) - }); - let mut deref_value: i32 = ({ - pointer.write(55); - (pointer.read()) - }); - printf!( - b"stable indirect %d %d %d %d %d\n", - value, - reference_value, - deref_value, - (*a.borrow())[(0) as usize], - (*a.borrow())[(1) as usize] - ); - let mut indices: [i32; 2] = [1, 0]; - let __rhs = ({ - elem!(pointer, selector.value).write(55); - (elem!(pointer, selector.value).read()) - }); - value = __rhs; - reference_value = ({ - elem!(reference, indices[(0) as usize]).write(44); - (elem!(reference, indices[(0) as usize]).read()) - }); - let __rhs = ({ - (pointer.offset((selector.value) as isize)).write(33); - ((pointer.offset((selector.value) as isize)).read()) - }); - deref_value = __rhs; - printf!( - b"aggregate selectors %d %d %d %d\n", - value, - reference_value, - deref_value, - (*a.borrow())[(1) as usize] - ); - let mut owner: Owner_58 = Owner_58 { - values: Box::new([0, 20]), - index: 0, - }; - value = ({ - match ( - { 1 }, - &mut (owner.values[(owner.values[(0) as usize]) as usize]), - ) { - (__tmp_140, __tmp_141) => { - (*__tmp_141) = __tmp_140; - (*__tmp_141).clone() - } - } - }); - reference_value = ({ - owner.values[(owner.index) as usize] = 11; - owner.values[(owner.index) as usize] - }); - printf!( - b"owner selectors %d %d %d %d\n", - value, - reference_value, - owner.values[(0) as usize], - owner.values[(1) as usize] - ); - let alias_selector: Value = Rc::new(RefCell::new(Index_57 { value: 0 })); - let mut member_alias: Ptr = (field_ptr!(alias_selector.as_pointer(), value)); - let __rhs = ({ - match ({ 1 }, { - let __tmp_143 = member_alias.offset(({ (*alias_selector.borrow()).value }) as isize); - __tmp_143 - }) { - (__tmp_142, __tmp_143) => __tmp_143.with_mut(|__tmp_143| { - (*__tmp_143) = __tmp_142; - (*__tmp_143).clone() - }), - } - }); - value = __rhs; - printf!(b"member alias %d %d\n", value, { - (*alias_selector.borrow()).value - }); - let self_index: Value = Rc::new(RefCell::new(0)); - let mut self_: Ptr = (self_index.as_pointer()); - let __rhs = ({ - match ({ 1 }, { - let __tmp_145 = self_.offset((*self_index.borrow()) as isize); - __tmp_145 - }) { - (__tmp_144, __tmp_145) => __tmp_145.with_mut(|__tmp_145| { - (*__tmp_145) = __tmp_144; - (*__tmp_145).clone() - }), - } - }); - value = __rhs; - printf!(b"aliased indirect %d %d\n", value, (*self_index.borrow())); - let captured_index: Value = Rc::new(RefCell::new(0)); - let captured_pointer: Value> = Rc::new(RefCell::new((captured_index.as_pointer()))); - let assign_captured: Value i32>> = Rc::new(RefCell::new(lambda!( - { - let captured_pointer: Ptr> = captured_pointer.as_pointer(); - let captured_index: Ptr = captured_index.as_pointer(); - }, - || -> i32 { - return ({ - match ({ 10000 }, { - let __tmp_147 = - (captured_pointer.read()).offset((captured_index.read()) as isize); - __tmp_147 - }) { - (__tmp_146, __tmp_147) => __tmp_147.with_mut(|__tmp_147| { - (*__tmp_147) = __tmp_146; - (*__tmp_147).clone() - }), - } - }); - } - ))); - value = ({ (*assign_captured.borrow()).call() }).clone(); - printf!( - b"captured indirect %d %d\n", - value, - (*captured_index.borrow()) - ); - ({ test_local_members_44() }); - ({ test_global_members_45() }); - ({ test_static_members_46() }); - ({ test_reference_members_5() }); - ({ test_reference_members_7() }); - ({ test_reference_pointer_9() }); - ({ test_reference_subfields_11() }); - ({ test_reference_subfields_14() }); - ({ test_captured_alias_17() }); ({ test_0() }); ({ test_1() }); - ({ test_2() }); - ({ test_comma_3() }); - ({ test_comma_4() }); - let values: Value> = Rc::new(RefCell::new(Box::new([10_u32, 20_u32]))); - let ref_: Ptr = values.decay(); - let mut i: i32 = 0; - let mut result: u32 = ({ - match ( - { 5_u32 }, - &(elem!( - { - i.prefix_inc(); - (ref_).clone() - }, - 0 - )), - ) { - (__tmp_148, __tmp_149) => __tmp_149.with_mut(|__tmp_149| { - (*__tmp_149) = (((*__tmp_149) as u32).wrapping_add((__tmp_148 as u32))) as u32; - (*__tmp_149).clone() - }), - } - }); - printf!( - b"array reference %d %u %u\n", - i, - result, - (*values.borrow())[(0) as usize] - ); - ({ test_borrows_25() }); - ({ test_binding_31() }); - ({ test_alias_scopes_36(10_i16) }); - ({ test_boxed_array_37() }); - ({ test_boxed_array_39() }); - let mut global_result: u32 = ({ - match ({ 1_u32 }, { - let __tmp_151 = global_array_41.with(|v| v.decay()).offset( - ({ - let __idx0 = (0) as usize; - global_array_41.with(|rc| rc.borrow()[__idx0]) - }), - ); - __tmp_151 - }) { - (__tmp_150, __tmp_151) => __tmp_151.with_mut(|__tmp_151| { - (*__tmp_151) = (((*__tmp_151) as u32).wrapping_add((__tmp_150 as u32))) as u32; - (*__tmp_151).clone() - }), - } - }); - printf!( - b"global array %u %u\n", - global_result, - ({ - let __idx0 = (0) as usize; - global_array_41.with(|rc| rc.borrow()[__idx0]) - }) - ); - i = 0; - result = ({ - match ({ 1_u32 }, { - let __tmp_153 = global_rows_42 - .with(|v| v.decay()) - .offset( - ({ - let __idx0 = (i.postfix_inc()) as usize; - let __idx1 = (0) as usize; - global_rows_42.with(|rc| rc.borrow()[__idx0][__idx1]) - }), - ) - .decay() - .offset(0); - __tmp_153 - }) { - (__tmp_152, __tmp_153) => __tmp_153.with_mut(|__tmp_153| { - (*__tmp_153) = (((*__tmp_153) as u32).wrapping_add((__tmp_152 as u32))) as u32; - (*__tmp_153).clone() - }), - } - }); - printf!( - b"nested array %d %u %u %u\n", - i, - result, - ({ - let __idx0 = (0) as usize; - let __idx1 = (0) as usize; - global_rows_42.with(|rc| rc.borrow()[__idx0][__idx1]) - }), - ({ - let __idx0 = (1) as usize; - let __idx1 = (0) as usize; - global_rows_42.with(|rc| rc.borrow()[__idx0][__idx1]) - }) - ); - return 0; -} -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(4)] -pub struct Index_57 { - #[offset(0)] - pub value: i32, -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] -#[byte_size(12)] -pub struct Owner_58 { - #[offset(0)] - #[byte_size(8)] - pub values: Box<[i32]>, - #[offset(8)] - pub index: i32, -} -impl Default for Owner_58 { - fn default() -> Self { - { - Owner_58 { - values: (0..2).map(|_| 0_i32).collect::>(), - index: 0_i32, - } - } - } -} -pub trait Counts_55Impl { - fn move_assign(&self, _a0: Ptr) -> Ptr; -} -impl Counts_55Impl for Ptr { - fn move_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), counts).with_mut(|__b0| { - (*__b0) = field!(_a0, counts).with_mut(std::mem::take); - }); - return (*self).clone(); - } -} -pub trait IndexedBindingImpl { - fn get_1_0(&self) -> Ptr; -} -impl IndexedBindingImpl for Ptr { - fn get_1_0(&self) -> Ptr { - return selected_values_30.with(|v| v.decay()).offset( - ({ - let __idx0 = (0) as usize; - selected_values_30.with(|rc| rc.borrow()[__idx0]) - }), - ); - } -} -pub fn __cpp2rust_init_globals() { - let _ = global_18.with(|_| ()); - let _ = global_record_21.with(|_| ()); - let _ = targets_23.with(|_| ()); - let _ = cursor_24.with(|_| ()); - let _ = selected_values_30.with(|_| ()); - let _ = initializer_target_33.with(|_| ()); - let _ = initializer_result_35.with(|_| ()); - let _ = global_array_41.with(|_| ()); - let _ = global_rows_42.with(|_| ()); - let _ = global_members_43.with(|_| ()); - let _ = scoped_values_48.with(|_| ()); - let _ = scoped_pointers_49.with(|_| ()); - let _ = scoped_record_50.with(|_| ()); + 0 } +pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/assign_as_value.rs b/tests/unit/out/unsafe/assign_as_value.rs index 55cbab8ae6..d49d3e54fb 100644 --- a/tests/unit/out/unsafe/assign_as_value.rs +++ b/tests/unit/out/unsafe/assign_as_value.rs @@ -21,26 +21,6 @@ unsafe fn main_0() -> i32 { p }; assert!(((q) == (buf.as_mut_ptr().offset((1) as isize)))); - q = { - p = (p).wrapping_sub((1 as i32) as usize); - p - }; - assert!(((p) == (buf.as_mut_ptr()))); - assert!(((q) == (buf.as_mut_ptr()))); - p = (p).wrapping_add((1 as i32) as usize); - let mut i: i32 = 0; - q = match ( - { 1 }, - &mut (*((&mut p as *mut *mut libc::c_char).offset((i.postfix_inc()) as isize))), - ) { - (__tmp_0, __tmp_1) => { - (*__tmp_1) = (*__tmp_1).offset(-(__tmp_0 as isize)); - (*__tmp_1).clone() - } - }; - assert!(((i) == (1))); - assert!(((p) == (buf.as_mut_ptr()))); - assert!(((q) == (buf.as_mut_ptr()))); let mut out: libc::c_char = (0 as libc::c_char); 'switch: { match { diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 5661aea59e..475afafa9e 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -7,38 +7,19 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn test_0() { - let mut a: [u32; 3] = [10_u32, 20_u32, 30_u32]; + let mut a: [u32; 4] = [10_u32, 20_u32, 30_u32, 40_u32]; let mut i: i32 = 0; match ({ 5_u32 }, &mut (a[(i.postfix_inc()) as usize])) { (__tmp_0, __tmp_1) => { (*__tmp_1) = (((*__tmp_1) as u32).wrapping_add((__tmp_0 as u32))) as u32; } }; - (unsafe { - libc::printf( - c"void %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (a[(0) as usize] as i32), - (a[(1) as usize] as i32), - ) - }); - i = 0; - let mut sum: u32 = (match ({ 2_u32 }, &mut (a[(i.postfix_inc()) as usize])) { + let mut compound: u32 = (match ({ 5_u32 }, &mut (a[(i.postfix_inc()) as usize])) { (__tmp_2, __tmp_3) => { (*__tmp_3) = (((*__tmp_3) as u32).wrapping_add((__tmp_2 as u32))) as u32; (*__tmp_3).clone() } }); - (unsafe { - libc::printf( - c"compound %d %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (sum as i32), - (a[(0) as usize] as i32), - (a[(1) as usize] as i32), - ) - }); - i = 0; let mut assigned: u32 = (match ({ 99_u32 }, &mut (a[(i.postfix_inc()) as usize])) { (__tmp_4, __tmp_5) => { (*__tmp_5) = __tmp_4; @@ -47,65 +28,32 @@ pub unsafe fn test_0() { }); (unsafe { libc::printf( - c"simple %d %d %d %d\n".as_ptr() as *const libc::c_char, + c"%d %d %d: %d %d %d %d\n".as_ptr() as *const libc::c_char, (i), + (compound as i32), (assigned as i32), (a[(0) as usize] as i32), (a[(1) as usize] as i32), + (a[(2) as usize] as i32), + (a[(3) as usize] as i32), ) }); - let mut plain: u32 = 10_u32; - plain = (plain).wrapping_add(5_u32); - let mut plain_result: u32 = ({ - plain = (plain).wrapping_add(2_u32); - plain - }); - (unsafe { - libc::printf( - c"plain %d %d\n".as_ptr() as *const libc::c_char, - (plain_result as i32), - (plain as i32), - ) - }); - i = 0; - match ( - { - { - i = 1; - 5_u32 - } - }, - &mut (a[(i) as usize]), - ) { +} +pub unsafe fn test_1() { + let mut a: [i16; 4] = [10_i16, 20_i16, 30_i16, 40_i16]; + let mut i: i32 = 0; + match ({ 5 }, &mut (a[(i.postfix_inc()) as usize])) { (__tmp_6, __tmp_7) => { - (*__tmp_7) = (((*__tmp_7) as u32).wrapping_add((__tmp_6 as u32))) as u32; + (*__tmp_7) = (((*__tmp_7) as i32) + (__tmp_6 as i32)) as i16; } }; - (unsafe { - libc::printf( - c"rhs target %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (a[(0) as usize] as i32), - (a[(1) as usize] as i32), - ) - }); - a[(0) as usize] = 0_u32; - let mut selected: u32 = (match ({ 1_u32 }, &mut (a[(a[(0) as usize]) as usize])) { + let mut compound: i16 = (match ({ 5 }, &mut (a[(i.postfix_inc()) as usize])) { (__tmp_8, __tmp_9) => { - (*__tmp_9) = (((*__tmp_9) as u32).wrapping_add((__tmp_8 as u32))) as u32; + (*__tmp_9) = (((*__tmp_9) as i32) + (__tmp_8 as i32)) as i16; (*__tmp_9).clone() } }); - (unsafe { - libc::printf( - c"self compound %d %d %d\n".as_ptr() as *const libc::c_char, - (selected as i32), - (a[(0) as usize] as i32), - (a[(1) as usize] as i32), - ) - }); - a[(0) as usize] = 0_u32; - selected = (match ({ 1_u32 }, &mut (a[(a[(0) as usize]) as usize])) { + let mut assigned: i16 = (match ({ 99_i16 }, &mut (a[(i.postfix_inc()) as usize])) { (__tmp_10, __tmp_11) => { (*__tmp_11) = __tmp_10; (*__tmp_11).clone() @@ -113,2089 +61,26 @@ pub unsafe fn test_0() { }); (unsafe { libc::printf( - c"self simple %d %d %d\n".as_ptr() as *const libc::c_char, - (selected as i32), - (a[(0) as usize] as i32), - (a[(1) as usize] as i32), - ) - }); -} -pub unsafe fn test_1() { - let mut a: [i16; 3] = [10_i16, 20_i16, 30_i16]; - let mut i: i32 = 0; - match ({ 5 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = (((*__tmp_13) as i32) + (__tmp_12 as i32)) as i16; - } - }; - (unsafe { - libc::printf( - c"void %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (a[(0) as usize] as i32), - (a[(1) as usize] as i32), - ) - }); - i = 0; - let mut sum: i16 = (match ({ 2 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_14, __tmp_15) => { - (*__tmp_15) = (((*__tmp_15) as i32) + (__tmp_14 as i32)) as i16; - (*__tmp_15).clone() - } - }); - (unsafe { - libc::printf( - c"compound %d %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (sum as i32), - (a[(0) as usize] as i32), - (a[(1) as usize] as i32), - ) - }); - i = 0; - let mut assigned: i16 = (match ({ 99_i16 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_16, __tmp_17) => { - (*__tmp_17) = __tmp_16; - (*__tmp_17).clone() - } - }); - (unsafe { - libc::printf( - c"simple %d %d %d %d\n".as_ptr() as *const libc::c_char, + c"%d %d %d: %d %d %d %d\n".as_ptr() as *const libc::c_char, (i), + (compound as i32), (assigned as i32), (a[(0) as usize] as i32), (a[(1) as usize] as i32), - ) - }); - let mut plain: i16 = 10_i16; - plain = ((plain as i32) + 5) as i16; - let mut plain_result: i16 = ({ - plain = ((plain as i32) + 2) as i16; - plain - }); - (unsafe { - libc::printf( - c"plain %d %d\n".as_ptr() as *const libc::c_char, - (plain_result as i32), - (plain as i32), - ) - }); - i = 0; - match ( - { - ({ - i = 1; - 5_i16 - } as i32) - }, - &mut (a[(i) as usize]), - ) { - (__tmp_18, __tmp_19) => { - (*__tmp_19) = (((*__tmp_19) as i32) + (__tmp_18 as i32)) as i16; - } - }; - (unsafe { - libc::printf( - c"rhs target %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (a[(0) as usize] as i32), - (a[(1) as usize] as i32), - ) - }); - a[(0) as usize] = 0_i16; - let mut selected: i16 = (match ({ 1 }, &mut (a[(a[(0) as usize]) as usize])) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = (((*__tmp_21) as i32) + (__tmp_20 as i32)) as i16; - (*__tmp_21).clone() - } - }); - (unsafe { - libc::printf( - c"self compound %d %d %d\n".as_ptr() as *const libc::c_char, - (selected as i32), - (a[(0) as usize] as i32), - (a[(1) as usize] as i32), - ) - }); - a[(0) as usize] = 0_i16; - selected = (match ({ 1_i16 }, &mut (a[(a[(0) as usize]) as usize])) { - (__tmp_22, __tmp_23) => { - (*__tmp_23) = __tmp_22; - (*__tmp_23).clone() - } - }); - (unsafe { - libc::printf( - c"self simple %d %d %d\n".as_ptr() as *const libc::c_char, - (selected as i32), - (a[(0) as usize] as i32), - (a[(1) as usize] as i32), - ) - }); -} -pub unsafe fn test_2() { - let mut a: [i32; 3] = [10, 20, 30]; - let mut i: i32 = 0; - a[(i.postfix_inc()) as usize] += 5; - (unsafe { - libc::printf( - c"void %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (a[(0) as usize]), - (a[(1) as usize]), - ) - }); - i = 0; - let mut sum: i32 = (match ({ 2 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_24, __tmp_25) => { - (*__tmp_25) = (((*__tmp_25) as i32) + (__tmp_24 as i32)) as i32; - (*__tmp_25).clone() - } - }); - (unsafe { - libc::printf( - c"compound %d %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (sum), - (a[(0) as usize]), - (a[(1) as usize]), - ) - }); - i = 0; - let mut assigned: i32 = (match ({ 99 }, &mut (a[(i.postfix_inc()) as usize])) { - (__tmp_26, __tmp_27) => { - (*__tmp_27) = __tmp_26; - (*__tmp_27).clone() - } - }); - (unsafe { - libc::printf( - c"simple %d %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (assigned), - (a[(0) as usize]), - (a[(1) as usize]), - ) - }); - let mut plain: i32 = 10; - plain += 5; - let mut plain_result: i32 = ({ - plain += 2; - plain - }); - (unsafe { - libc::printf( - c"plain %d %d\n".as_ptr() as *const libc::c_char, - (plain_result), - (plain), - ) - }); - i = 0; - a[(i) as usize] += { - i = 1; - 5 - }; - (unsafe { - libc::printf( - c"rhs target %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (a[(0) as usize]), - (a[(1) as usize]), - ) - }); - a[(0) as usize] = 0; - let mut selected: i32 = (match ({ 1 }, &mut (a[(a[(0) as usize]) as usize])) { - (__tmp_28, __tmp_29) => { - (*__tmp_29) = (((*__tmp_29) as i32) + (__tmp_28 as i32)) as i32; - (*__tmp_29).clone() - } - }); - (unsafe { - libc::printf( - c"self compound %d %d %d\n".as_ptr() as *const libc::c_char, - (selected), - (a[(0) as usize]), - (a[(1) as usize]), - ) - }); - a[(0) as usize] = 0; - selected = (match ({ 1 }, &mut (a[(a[(0) as usize]) as usize])) { - (__tmp_30, __tmp_31) => { - (*__tmp_31) = __tmp_30; - (*__tmp_31).clone() - } - }); - (unsafe { - libc::printf( - c"self simple %d %d %d\n".as_ptr() as *const libc::c_char, - (selected), - (a[(0) as usize]), - (a[(1) as usize]), - ) - }); -} -pub unsafe fn test_comma_3() { - let mut x: u32 = 10_u32; - let mut i: i32 = 0; - match ( - { 5_u32 }, - &mut (*({ - i.prefix_inc(); - &mut x - })), - ) { - (__tmp_32, __tmp_33) => { - (*__tmp_33) = (((*__tmp_33) as u32).wrapping_add((__tmp_32 as u32))) as u32; - } - }; - (unsafe { - libc::printf( - c"direct void %d %d\n".as_ptr() as *const libc::c_char, - (i), - (x as i32), - ) - }); - let mut result: u32 = (match ( - { 2_u32 }, - &mut (*({ - i.prefix_inc(); - &mut x - })), - ) { - (__tmp_34, __tmp_35) => { - (*__tmp_35) = (((*__tmp_35) as u32).wrapping_add((__tmp_34 as u32))) as u32; - (*__tmp_35).clone() - } - }); - (unsafe { - libc::printf( - c"direct compound %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (result as i32), - (x as i32), - ) - }); - result = (match ( - { 99_u32 }, - &mut (*({ - i.prefix_inc(); - &mut x - })), - ) { - (__tmp_36, __tmp_37) => { - (*__tmp_37) = __tmp_36; - (*__tmp_37).clone() - } - }); - (unsafe { - libc::printf( - c"direct simple %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (result as i32), - (x as i32), - ) - }); - let mut p: *mut u32 = (&mut x as *mut u32); - match ( - { 5_u32 }, - &mut (*({ - i.prefix_inc(); - (p).clone() - })), - ) { - (__tmp_38, __tmp_39) => { - (*__tmp_39) = (((*__tmp_39) as u32).wrapping_add((__tmp_38 as u32))) as u32; - } - }; - (unsafe { - libc::printf( - c"indirect void %d %d\n".as_ptr() as *const libc::c_char, - (i), - ((*p) as i32), - ) - }); - result = (match ( - { 2_u32 }, - &mut (*({ - i.prefix_inc(); - (p).clone() - })), - ) { - (__tmp_40, __tmp_41) => { - (*__tmp_41) = (((*__tmp_41) as u32).wrapping_add((__tmp_40 as u32))) as u32; - (*__tmp_41).clone() - } - }); - (unsafe { - libc::printf( - c"indirect compound %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (result as i32), - ((*p) as i32), - ) - }); - result = (match ( - { 99_u32 }, - &mut (*({ - i.prefix_inc(); - (p).clone() - })), - ) { - (__tmp_42, __tmp_43) => { - (*__tmp_43) = __tmp_42; - (*__tmp_43).clone() - } - }); - (unsafe { - libc::printf( - c"indirect simple %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (result as i32), - ((*p) as i32), + (a[(2) as usize] as i32), + (a[(3) as usize] as i32), ) }); } -pub unsafe fn test_comma_4() { - let mut x: i16 = 10_i16; - let mut i: i32 = 0; - match ( - { 5 }, - &mut (*({ - i.prefix_inc(); - &mut x - })), - ) { - (__tmp_44, __tmp_45) => { - (*__tmp_45) = (((*__tmp_45) as i32) + (__tmp_44 as i32)) as i16; - } - }; - (unsafe { - libc::printf( - c"direct void %d %d\n".as_ptr() as *const libc::c_char, - (i), - (x as i32), - ) - }); - let mut result: i16 = (match ( - { 2 }, - &mut (*({ - i.prefix_inc(); - &mut x - })), - ) { - (__tmp_46, __tmp_47) => { - (*__tmp_47) = (((*__tmp_47) as i32) + (__tmp_46 as i32)) as i16; - (*__tmp_47).clone() - } - }); - (unsafe { - libc::printf( - c"direct compound %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (result as i32), - (x as i32), - ) - }); - result = (match ( - { 99_i16 }, - &mut (*({ - i.prefix_inc(); - &mut x - })), - ) { - (__tmp_48, __tmp_49) => { - (*__tmp_49) = __tmp_48; - (*__tmp_49).clone() - } - }); - (unsafe { - libc::printf( - c"direct simple %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (result as i32), - (x as i32), - ) - }); - let mut p: *mut i16 = (&mut x as *mut i16); - match ( - { 5 }, - &mut (*({ - i.prefix_inc(); - (p).clone() - })), - ) { - (__tmp_50, __tmp_51) => { - (*__tmp_51) = (((*__tmp_51) as i32) + (__tmp_50 as i32)) as i16; - } - }; - (unsafe { - libc::printf( - c"indirect void %d %d\n".as_ptr() as *const libc::c_char, - (i), - ((*p) as i32), - ) - }); - result = (match ( - { 2 }, - &mut (*({ - i.prefix_inc(); - (p).clone() - })), - ) { - (__tmp_52, __tmp_53) => { - (*__tmp_53) = (((*__tmp_53) as i32) + (__tmp_52 as i32)) as i16; - (*__tmp_53).clone() - } - }); - (unsafe { - libc::printf( - c"indirect compound %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (result as i32), - ((*p) as i32), - ) - }); - result = (match ( - { 99_i16 }, - &mut (*({ - i.prefix_inc(); - (p).clone() - })), - ) { - (__tmp_54, __tmp_55) => { - (*__tmp_55) = __tmp_54; - (*__tmp_55).clone() - } - }); - (unsafe { - libc::printf( - c"indirect simple %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (result as i32), - ((*p) as i32), - ) - }); -} -pub unsafe fn test_reference_members_5() { - let mut index: u32 = 0_u32; - let mut other: u32 = 77_u32; - let mut a: [Slot_6; 2] = [Slot_6 { value: &mut index }, Slot_6 { value: &mut other }]; - match ({ 1_u32 }, &mut (*a[(index) as usize].value)) { - (__tmp_56, __tmp_57) => { - (*__tmp_57) = (((*__tmp_57) as u32).wrapping_add((__tmp_56 as u32))) as u32; - } - }; - (unsafe { - libc::printf( - c"reference void %d %d\n".as_ptr() as *const libc::c_char, - (index as i32), - (other as i32), - ) - }); - index = 0_u32; - let mut result: u32 = (match ({ 1_u32 }, &mut (*a[(index) as usize].value)) { - (__tmp_58, __tmp_59) => { - (*__tmp_59) = (((*__tmp_59) as u32).wrapping_add((__tmp_58 as u32))) as u32; - (*__tmp_59).clone() - } - }); - (unsafe { - libc::printf( - c"reference compound %d %d %d\n".as_ptr() as *const libc::c_char, - (index as i32), - (other as i32), - (result as i32), - ) - }); - index = 0_u32; - result = (match ({ 1_u32 }, &mut (*a[(index) as usize].value)) { - (__tmp_60, __tmp_61) => { - (*__tmp_61) = __tmp_60; - (*__tmp_61).clone() - } - }); - (unsafe { - libc::printf( - c"reference simple %d %d %d\n".as_ptr() as *const libc::c_char, - (index as i32), - (other as i32), - (result as i32), - ) - }); - index = 0_u32; - result = (match ({ 1_u32 }, &mut (*a[(index.postfix_inc()) as usize].value)) { - (__tmp_62, __tmp_63) => { - (*__tmp_63) = (((*__tmp_63) as u32).wrapping_add((__tmp_62 as u32))) as u32; - (*__tmp_63).clone() - } - }); - (unsafe { - libc::printf( - c"reference effect %d %d %d\n".as_ptr() as *const libc::c_char, - (index as i32), - (other as i32), - (result as i32), - ) - }); - index = 0_u32; - result = (match ( - { - { - index = 1_u32; - 2_u32 - } - }, - &mut (*a[(index) as usize].value), - ) { - (__tmp_64, __tmp_65) => { - (*__tmp_65) = (((*__tmp_65) as u32).wrapping_add((__tmp_64 as u32))) as u32; - (*__tmp_65).clone() - } - }); - (unsafe { - libc::printf( - c"reference rhs %d %d %d\n".as_ptr() as *const libc::c_char, - (index as i32), - (other as i32), - (result as i32), - ) - }); -} -pub unsafe fn test_reference_members_7() { - let mut index: i16 = 0_i16; - let mut other: i16 = 77_i16; - let mut a: [Slot_8; 2] = [Slot_8 { value: &mut index }, Slot_8 { value: &mut other }]; - match ({ 1 }, &mut (*a[(index) as usize].value)) { - (__tmp_66, __tmp_67) => { - (*__tmp_67) = (((*__tmp_67) as i32) + (__tmp_66 as i32)) as i16; - } - }; - (unsafe { - libc::printf( - c"reference void %d %d\n".as_ptr() as *const libc::c_char, - (index as i32), - (other as i32), - ) - }); - index = 0_i16; - let mut result: i16 = (match ({ 1 }, &mut (*a[(index) as usize].value)) { - (__tmp_68, __tmp_69) => { - (*__tmp_69) = (((*__tmp_69) as i32) + (__tmp_68 as i32)) as i16; - (*__tmp_69).clone() - } - }); - (unsafe { - libc::printf( - c"reference compound %d %d %d\n".as_ptr() as *const libc::c_char, - (index as i32), - (other as i32), - (result as i32), - ) - }); - index = 0_i16; - result = (match ({ 1_i16 }, &mut (*a[(index) as usize].value)) { - (__tmp_70, __tmp_71) => { - (*__tmp_71) = __tmp_70; - (*__tmp_71).clone() - } - }); - (unsafe { - libc::printf( - c"reference simple %d %d %d\n".as_ptr() as *const libc::c_char, - (index as i32), - (other as i32), - (result as i32), - ) - }); - index = 0_i16; - result = (match ({ 1 }, &mut (*a[(index.postfix_inc()) as usize].value)) { - (__tmp_72, __tmp_73) => { - (*__tmp_73) = (((*__tmp_73) as i32) + (__tmp_72 as i32)) as i16; - (*__tmp_73).clone() - } - }); - (unsafe { - libc::printf( - c"reference effect %d %d %d\n".as_ptr() as *const libc::c_char, - (index as i32), - (other as i32), - (result as i32), - ) - }); - index = 0_i16; - result = (match ( - { - ({ - index = 1_i16; - 2_i16 - } as i32) - }, - &mut (*a[(index) as usize].value), - ) { - (__tmp_74, __tmp_75) => { - (*__tmp_75) = (((*__tmp_75) as i32) + (__tmp_74 as i32)) as i16; - (*__tmp_75).clone() - } - }); - (unsafe { - libc::printf( - c"reference rhs %d %d %d\n".as_ptr() as *const libc::c_char, - (index as i32), - (other as i32), - (result as i32), - ) - }); -} -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Slot_6 { - pub value: *mut u32, -} -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Slot_8 { - pub value: *mut i16, -} -pub unsafe fn test_reference_pointer_9() { - let mut p: *mut Node_10 = std::ptr::null_mut(); - let mut q: *mut Node_10 = std::ptr::null_mut(); - let mut first: Node_10 = Node_10 { link: &mut p }; - let mut second: Node_10 = Node_10 { link: &mut q }; - p = (&mut first as *mut Node_10); - q = (&mut first as *mut Node_10); - let mut result: *mut Node_10 = (match ({ (&mut second as *mut Node_10) }, &mut (*(*p).link)) { - (__tmp_76, __tmp_77) => { - (*__tmp_77) = __tmp_76; - (*__tmp_77).clone() - } - }); - (unsafe { - libc::printf( - c"reference pointer %d %d\n".as_ptr() as *const libc::c_char, - (((p) == (&mut second as *mut Node_10)) as i32), - (((result) == (&mut second as *mut Node_10)) as i32), - ) - }); -} -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Node_10 { - pub link: *mut *mut Node_10, -} -pub unsafe fn test_reference_subfields_11() { - let mut index: Index_12 = Index_12 { value: 0_u32 }; - let mut other: Index_12 = Index_12 { value: 77_u32 }; - let mut a: [Slot_13; 2] = [Slot_13 { ref_: &mut index }, Slot_13 { ref_: &mut other }]; - let mut result: u32 = (match ({ 1_u32 }, &mut ((*a[(index.value) as usize].ref_).value)) { - (__tmp_78, __tmp_79) => { - (*__tmp_79) = (((*__tmp_79) as u32).wrapping_add((__tmp_78 as u32))) as u32; - (*__tmp_79).clone() - } - }); - (unsafe { - libc::printf( - c"reference subfield compound %d %d %d\n".as_ptr() as *const libc::c_char, - (result as i32), - (index.value as i32), - (other.value as i32), - ) - }); - index.value = 0_u32; - result = (match ({ 1_u32 }, &mut ((*a[(index.value) as usize].ref_).value)) { - (__tmp_80, __tmp_81) => { - (*__tmp_81) = __tmp_80; - (*__tmp_81).clone() - } - }); - (unsafe { - libc::printf( - c"reference subfield simple %d %d %d\n".as_ptr() as *const libc::c_char, - (result as i32), - (index.value as i32), - (other.value as i32), - ) - }); -} -pub unsafe fn test_reference_subfields_14() { - let mut index: Index_15 = Index_15 { value: 0_i16 }; - let mut other: Index_15 = Index_15 { value: 77_i16 }; - let mut a: [Slot_16; 2] = [Slot_16 { ref_: &mut index }, Slot_16 { ref_: &mut other }]; - let mut result: i16 = (match ({ 1 }, &mut ((*a[(index.value) as usize].ref_).value)) { - (__tmp_82, __tmp_83) => { - (*__tmp_83) = (((*__tmp_83) as i32) + (__tmp_82 as i32)) as i16; - (*__tmp_83).clone() - } - }); - (unsafe { - libc::printf( - c"reference subfield compound %d %d %d\n".as_ptr() as *const libc::c_char, - (result as i32), - (index.value as i32), - (other.value as i32), - ) - }); - index.value = 0_i16; - result = (match ({ 1_i16 }, &mut ((*a[(index.value) as usize].ref_).value)) { - (__tmp_84, __tmp_85) => { - (*__tmp_85) = __tmp_84; - (*__tmp_85).clone() - } - }); - (unsafe { - libc::printf( - c"reference subfield simple %d %d %d\n".as_ptr() as *const libc::c_char, - (result as i32), - (index.value as i32), - (other.value as i32), - ) - }); -} -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Index_12 { - pub value: u32, -} -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Slot_13 { - pub ref_: *mut Index_12, -} -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Index_15 { - pub value: i16, -} -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Slot_16 { - pub ref_: *mut Index_15, -} -pub unsafe fn test_captured_alias_17() { - let mut x: i16 = 10_i16; - let mut p: *mut i16 = (&mut x as *mut i16); - let mut f: FnPtr i16> = lambda_unsafe!( - { - let x: *mut i16 = &mut x; - let p: *mut *mut i16 = &mut p; - }, - || -> i16 { - return (match ( - { - { - (*(*p)) = (-1_i32 as i16); - 0.5_f64 - } - }, - &mut (*x), - ) { - (__tmp_86, __tmp_87) => { - (*__tmp_87) = (((*__tmp_87) as f64) + (__tmp_86 as f64)) as i16; - (*__tmp_87).clone() - } - }); - } - ); - let mut result: i32 = ((unsafe { f.call() }) as i32); - (unsafe { - libc::printf( - c"captured outer alias %d %d\n".as_ptr() as *const libc::c_char, - (result), - (x as i32), - ) - }); -} -pub static mut global_18: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10 }); -pub unsafe fn observe_global_19(mut assigned: i32) -> i32 { - return ((assigned) + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18))); -} -pub unsafe fn observe_20(mut assigned: i32, mut stored: *const i32) -> i32 { - return ((assigned) + (*stored)); -} -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct GlobalRecord_Inner { - pub value: i32, -} -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct GlobalRecord { - pub inner: GlobalRecord_Inner, -} -pub static mut global_record_21: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { - GlobalRecord { - inner: GlobalRecord_Inner { value: 10 }, - } - }); -pub unsafe fn observe_record_22(mut assigned: i32) -> i32 { - return ((assigned) - + ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_21)) - .inner - .value)); -} -pub static mut targets_23: std::cell::LazyCell<[i32; 2]> = - std::cell::LazyCell::new(|| unsafe { [10, 20] }); -pub static mut cursor_24: std::cell::LazyCell<*mut i32> = std::cell::LazyCell::new(|| unsafe { - (*std::cell::LazyCell::force_mut(&mut *&raw mut targets_23)).as_mut_ptr() -}); -pub unsafe fn test_borrows_25() { - (unsafe { - libc::printf( - c"%d\n".as_ptr() as *const libc::c_char, - (unsafe { - observe_global_19({ - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18)) = 99; - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18)) - }) - }), - ) - }); - (unsafe { - libc::printf( - c"%d\n".as_ptr() as *const libc::c_char, - (unsafe { - observe_global_19({ - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18)) += 5; - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18)) - }) - }), - ) - }); - (unsafe { - libc::printf( - c"%d\n".as_ptr() as *const libc::c_char, - (unsafe { - observe_global_19({ - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18)) = (unsafe { - observe_20( - 0, - (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18)) - as *mut i32) - .cast_const(), - ) - }); - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18)) - }) - }), - ) - }); - let mut assigned: i32 = ((match ( - { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_26)) = (-1_i32 as i16); - 0.5_f64 - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_26)), - ) { - (__tmp_88, __tmp_89) => { - (*__tmp_89) = (((*__tmp_89) as f64) + (__tmp_88 as f64)) as i16; - (*__tmp_89).clone() - } - }) as i32); - (unsafe { - libc::printf( - c"%d %d\n".as_ptr() as *const libc::c_char, - (assigned), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut promoted_26)) as i32), - ) - }); - let mut aliased: i16 = 10_i16; - let mut alias: *mut i16 = (&mut aliased as *mut i16); - assigned = ((match ( - { - { - (*alias) = (-1_i32 as i16); - 0.5_f64 - } - }, - &mut (aliased), - ) { - (__tmp_90, __tmp_91) => { - (*__tmp_91) = (((*__tmp_91) as f64) + (__tmp_90 as f64)) as i16; - (*__tmp_91).clone() - } - }) as i32); - (unsafe { - libc::printf( - c"%d %d\n".as_ptr() as *const libc::c_char, - (assigned), - (aliased as i32), - ) - }); - let mut enabled: bool = (match ( - { - { - (unsafe { - observe_20( - 0, - (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_18)) - as *mut i32) - .cast_const(), - ) - }); - 0.5_f64 - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut flag_27)), - ) { - (__tmp_92, __tmp_93) => { - (*__tmp_93) = (((*__tmp_93) as u8 as f64) + (__tmp_92 as f64)) != 0.0; - (*__tmp_93).clone() - } - }); - (unsafe { - libc::printf( - c"%d %d\n".as_ptr() as *const libc::c_char, - (enabled as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut flag_27)) as i32), - ) - }); - (unsafe { - libc::printf( - c"%d\n".as_ptr() as *const libc::c_char, - (unsafe { - observe_record_22( - match ( - { 99 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_record_21)) - .inner - .value), - ) { - (__tmp_94, __tmp_95) => { - (*__tmp_95) = __tmp_94; - (*__tmp_95).clone() - } - }, - ) - }), - ) - }); - let mut shifted: *mut i32 = (match ( - { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_24)) = - (*std::cell::LazyCell::force_mut(&mut *&raw mut targets_23)) - .as_mut_ptr() - .offset((1) as isize); - 1 - } - }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_24)), - ) { - (__tmp_96, __tmp_97) => { - (*__tmp_97) = (*__tmp_97).offset(-(__tmp_96 as isize)); - (*__tmp_97).clone() - } - }); - (unsafe { - libc::printf( - c"%d %d\n".as_ptr() as *const libc::c_char, - (((*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_24)) - == ((*std::cell::LazyCell::force_mut(&mut *&raw mut targets_23)).as_mut_ptr())) - as i32), - (((shifted) == (*std::cell::LazyCell::force_mut(&mut *&raw mut cursor_24))) as i32), - ) - }); - let mut local: i32 = 10; - (unsafe { - libc::printf( - c"%d\n".as_ptr() as *const libc::c_char, - (unsafe { - let _assigned: i32 = { - local = 99; - local - }; - let _stored: *const i32 = (&mut local as *mut i32).cast_const(); - observe_20(_assigned, _stored) - }), - ) - }); - (unsafe { - libc::printf( - c"%d\n".as_ptr() as *const libc::c_char, - (unsafe { - let _assigned: i32 = { - local += 5; - local - }; - let _stored: *const i32 = (&mut local as *mut i32).cast_const(); - observe_20(_assigned, _stored) - }), - ) - }); - let mut record: Record_28 = Record_28 { value: 10 }; - (unsafe { - libc::printf( - c"%d\n".as_ptr() as *const libc::c_char, - (unsafe { - let _assigned: i32 = { - record.value = 99; - record.value - }; - let _stored: *const i32 = (&mut record.value as *mut i32).cast_const(); - observe_20(_assigned, _stored) - }), - ) - }); - (unsafe { - libc::printf( - c"%d\n".as_ptr() as *const libc::c_char, - (unsafe { - let _assigned: i32 = { - record.value += 5; - record.value - }; - let _stored: *const i32 = (&mut record.value as *mut i32).cast_const(); - observe_20(_assigned, _stored) - }), - ) - }); - let mut first: Link_29 = ::default(); - first = Link_29 { - next: (&mut first as *mut Link_29), - }; - let mut second: Link_29 = Link_29 { - next: (&mut first as *mut Link_29), - }; - let selector: *mut *mut Link_29 = &mut first.next; - let mut selected: *mut Link_29 = (match ( - { (&mut second as *mut Link_29) }, - &mut ((*(*selector)).next), - ) { - (__tmp_98, __tmp_99) => { - (*__tmp_99) = __tmp_98; - (*__tmp_99).clone() - } - }); - (unsafe { - libc::printf( - c"%d %d\n".as_ptr() as *const libc::c_char, - (((selected) == (&mut second as *mut Link_29)) as i32), - (((first.next) == (&mut second as *mut Link_29)) as i32), - ) - }); - let mut values: Vec = vec![10; 1_usize]; - (unsafe { - libc::printf( - c"%d\n".as_ptr() as *const libc::c_char, - (unsafe { - let _assigned: i32 = { - values[(0_usize)] = 99; - values[(0_usize)] - }; - let _stored: *const i32 = (&mut values[(0_usize)] as *mut i32).cast_const(); - observe_20(_assigned, _stored) - }), - ) - }); - (unsafe { - libc::printf( - c"%d\n".as_ptr() as *const libc::c_char, - (unsafe { - let _assigned: i32 = { - values[(0_usize)] += 5; - values[(0_usize)] - }; - let _stored: *const i32 = (&mut values[(0_usize)] as *mut i32).cast_const(); - observe_20(_assigned, _stored) - }), - ) - }); -} -static mut promoted_26: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10_i16 }); -static mut flag_27: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { false }); -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Record_28 { - pub value: i32, -} -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Link_29 { - pub next: *mut Link_29, -} -pub static mut selected_values_30: std::cell::LazyCell<[u32; 3]> = - std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct IndexedBinding {} -impl IndexedBinding { - pub unsafe fn get_1_0(&mut self) -> *mut u32 { - return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_30)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_30))[(0) as usize]) - as usize]; - } -} -pub unsafe fn test_binding_31() { - let mut owner: IndexedBinding = ::default(); - let __decomp_32: *mut IndexedBinding = &mut owner; - let value: *mut u32 = (unsafe { IndexedBinding::get_1_0(&mut (*__decomp_32)) }); - let mut result: u32 = (match ( - { 1_u32 }, - &mut (*(unsafe { IndexedBinding::get_1_0(&mut (*__decomp_32)) })), - ) { - (__tmp_100, __tmp_101) => { - (*__tmp_101) = (((*__tmp_101) as u32).wrapping_add((__tmp_100 as u32))) as u32; - (*__tmp_101).clone() - } - }); - (unsafe { - libc::printf( - c"binding compound %u %u\n".as_ptr() as *const libc::c_char, - (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_30))[(0) as usize]), - ) - }); -} -pub static mut initializer_target_33: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { 10_u32 }); -pub unsafe fn mutate_initializer_34() -> u32 { - (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_33)) = 20_u32; - return 1_u32; -} -pub static mut initializer_result_35: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { - (match ( - { (unsafe { mutate_initializer_34() }) }, - &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_33)), - ) { - (__tmp_102, __tmp_103) => { - (*__tmp_103) = (((*__tmp_103) as u32).wrapping_add((__tmp_102 as u32))) as u32; - (*__tmp_103).clone() - } - }) - }); -pub unsafe fn test_alias_scopes_36(mut parameter: i16) { - let mut p: *mut i16 = (&mut parameter as *mut i16); - let mut result: i16 = (match ( - { - { - (*p) = (-1_i32 as i16); - 0.5_f64 - } - }, - &mut (parameter), - ) { - (__tmp_104, __tmp_105) => { - (*__tmp_105) = (((*__tmp_105) as f64) + (__tmp_104 as f64)) as i16; - (*__tmp_105).clone() - } - }); - (unsafe { - libc::printf( - c"parameter %d %d\n".as_ptr() as *const libc::c_char, - (result as i32), - (parameter as i32), - ) - }); - let mut local: i16 = 10_i16; - let mut mutate: FnPtr f64> = lambda_unsafe!( - { - let local: *mut i16 = &mut local; - }, - || -> f64 { - (*local) = (-1_i32 as i16); - return 0.5_f64; - } - ); - result = (match ({ (unsafe { mutate.call() }).clone() }, &mut (local)) { - (__tmp_106, __tmp_107) => { - (*__tmp_107) = (((*__tmp_107) as f64) + (__tmp_106 as f64)) as i16; - (*__tmp_107).clone() - } - }); - (unsafe { - libc::printf( - c"capture %d %d\n".as_ptr() as *const libc::c_char, - (result as i32), - (local as i32), - ) - }); - (unsafe { - libc::printf( - c"initializer %u %u\n".as_ptr() as *const libc::c_char, - (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_result_35)), - (*std::cell::LazyCell::force_mut(&mut *&raw mut initializer_target_33)), - ) - }); -} -pub unsafe fn test_boxed_array_37() { - let mut a: [u32; 3] = [0_u32, 20_u32, 30_u32]; - let mut p: *mut u32 = a.as_mut_ptr(); - let mut i: i32 = 0; - let mut result: u32 = (match ( - { 1_u32 }, - &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), - ) { - (__tmp_108, __tmp_109) => { - (*__tmp_109) = (((*__tmp_109) as u32).wrapping_add((__tmp_108 as u32))) as u32; - (*__tmp_109).clone() - } - }); - (unsafe { - libc::printf( - c"boxed compound %d %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (result as i32), - (a[(0) as usize] as i32), - ((*p) as i32), - ) - }); - a[(0) as usize] = 0_u32; - i = 0; - result = (match ( - { 1_u32 }, - &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), - ) { - (__tmp_110, __tmp_111) => { - (*__tmp_111) = __tmp_110; - (*__tmp_111).clone() - } - }); - (unsafe { - libc::printf( - c"boxed simple %d %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (result as i32), - (a[(0) as usize] as i32), - ((*p) as i32), - ) - }); - result = (match ( - { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_38)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_38))[(0) as usize]) as usize]), - ) { - (__tmp_112, __tmp_113) => { - (*__tmp_113) = (((*__tmp_113) as u32).wrapping_add((__tmp_112 as u32))) as u32; - (*__tmp_113).clone() - } - }); - (unsafe { - libc::printf( - c"static array %d %d\n".as_ptr() as *const libc::c_char, - (result as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_38))[(0) as usize] as i32), - ) - }); -} -pub unsafe fn test_boxed_array_39() { - let mut a: [i16; 3] = [0_i16, 20_i16, 30_i16]; - let mut p: *mut i16 = a.as_mut_ptr(); - let mut i: i32 = 0; - let mut result: i16 = (match ({ 1 }, &mut (a[(a[(i.postfix_inc()) as usize]) as usize])) { - (__tmp_114, __tmp_115) => { - (*__tmp_115) = (((*__tmp_115) as i32) + (__tmp_114 as i32)) as i16; - (*__tmp_115).clone() - } - }); - (unsafe { - libc::printf( - c"boxed compound %d %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (result as i32), - (a[(0) as usize] as i32), - ((*p) as i32), - ) - }); - a[(0) as usize] = 0_i16; - i = 0; - result = (match ( - { 1_i16 }, - &mut (a[(a[(i.postfix_inc()) as usize]) as usize]), - ) { - (__tmp_116, __tmp_117) => { - (*__tmp_117) = __tmp_116; - (*__tmp_117).clone() - } - }); - (unsafe { - libc::printf( - c"boxed simple %d %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (result as i32), - (a[(0) as usize] as i32), - ((*p) as i32), - ) - }); - result = (match ( - { 1 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_40)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_40))[(0) as usize]) as usize]), - ) { - (__tmp_118, __tmp_119) => { - (*__tmp_119) = (((*__tmp_119) as i32) + (__tmp_118 as i32)) as i16; - (*__tmp_119).clone() - } - }); - (unsafe { - libc::printf( - c"static array %d %d\n".as_ptr() as *const libc::c_char, - (result as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut saved_40))[(0) as usize] as i32), - ) - }); -} -static mut saved_38: std::cell::LazyCell<[u32; 3]> = - std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); -static mut saved_40: std::cell::LazyCell<[i16; 3]> = - std::cell::LazyCell::new(|| unsafe { [0_i16, 20_i16, 30_i16] }); -pub static mut global_array_41: std::cell::LazyCell<[u32; 3]> = - std::cell::LazyCell::new(|| unsafe { [0_u32, 20_u32, 30_u32] }); -pub static mut global_rows_42: std::cell::LazyCell<[[u32; 2]; 2]> = - std::cell::LazyCell::new(|| unsafe { [[0_u32, 10_u32], [20_u32, 30_u32]] }); -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct IndexedMember { - pub key: i32, - pub value: u32, - pub promoted: i16, -} -pub static mut global_members_43: std::cell::LazyCell<[IndexedMember; 2]> = - std::cell::LazyCell::new(|| unsafe { - [ - IndexedMember { - key: 0, - value: 10_u32, - promoted: 10_i16, - }, - IndexedMember { - key: 1, - value: 20_u32, - promoted: 20_i16, - }, - ] - }); -pub unsafe fn test_local_members_44() { - let mut a: [IndexedMember; 2] = [ - IndexedMember { - key: 0, - value: 10_u32, - promoted: 10_i16, - }, - IndexedMember { - key: 1, - value: 20_u32, - promoted: 20_i16, - }, - ]; - let mut p: *mut IndexedMember = a.as_mut_ptr(); - let mut i: i32 = 0; - let mut result: u32 = (match ( - { 1_u32 }, - &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].value), - ) { - (__tmp_120, __tmp_121) => { - (*__tmp_121) = (((*__tmp_121) as u32).wrapping_add((__tmp_120 as u32))) as u32; - (*__tmp_121).clone() - } - }); - (unsafe { - libc::printf( - c"member unsigned %d %u %u %u\n".as_ptr() as *const libc::c_char, - (i), - (result), - (a[(0) as usize].value), - (a[(1) as usize].value), - ) - }); - i = 0; - match ( - { 1 }, - &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].promoted), - ) { - (__tmp_122, __tmp_123) => { - (*__tmp_123) = (((*__tmp_123) as i32) + (__tmp_122 as i32)) as i16; - } - }; - (unsafe { - libc::printf( - c"member promoted %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - (a[(0) as usize].promoted as i32), - (a[(1) as usize].promoted as i32), - ) - }); - i = 0; - result = (match ( - { 99_u32 }, - &mut (a[(a[(i.postfix_inc()) as usize].key) as usize].value), - ) { - (__tmp_124, __tmp_125) => { - (*__tmp_125) = __tmp_124; - (*__tmp_125).clone() - } - }); - (unsafe { - libc::printf( - c"member simple %d %u %u %u\n".as_ptr() as *const libc::c_char, - (i), - (result), - (a[(0) as usize].value), - (a[(1) as usize].value), - ) - }); - (unsafe { - libc::printf( - c"member alias %u\n".as_ptr() as *const libc::c_char, - ((*p).value), - ) - }); -} -pub unsafe fn test_global_members_45() { - let mut i: i32 = 0; - let mut result: u32 = (match ( - { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43)) - [(i.postfix_inc()) as usize] - .key) as usize] - .value), - ) { - (__tmp_126, __tmp_127) => { - (*__tmp_127) = (((*__tmp_127) as u32).wrapping_add((__tmp_126 as u32))) as u32; - (*__tmp_127).clone() - } - }); - (unsafe { - libc::printf( - c"member unsigned %d %u %u %u\n".as_ptr() as *const libc::c_char, - (i), - (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43))[(0) as usize] - .value), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43))[(1) as usize] - .value), - ) - }); - i = 0; - match ( - { 1 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43)) - [(i.postfix_inc()) as usize] - .key) as usize] - .promoted), - ) { - (__tmp_128, __tmp_129) => { - (*__tmp_129) = (((*__tmp_129) as i32) + (__tmp_128 as i32)) as i16; - } - }; - (unsafe { - libc::printf( - c"member promoted %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43))[(0) as usize] - .promoted as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43))[(1) as usize] - .promoted as i32), - ) - }); - i = 0; - result = (match ( - { 99_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43)) - [(i.postfix_inc()) as usize] - .key) as usize] - .value), - ) { - (__tmp_130, __tmp_131) => { - (*__tmp_131) = __tmp_130; - (*__tmp_131).clone() - } - }); - (unsafe { - libc::printf( - c"member simple %d %u %u %u\n".as_ptr() as *const libc::c_char, - (i), - (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43))[(0) as usize] - .value), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_members_43))[(1) as usize] - .value), - ) - }); -} -pub unsafe fn test_static_members_46() { - let mut i: i32 = 0; - let mut result: u32 = (match ( - { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(i.postfix_inc()) as usize] - .key) as usize] - .value), - ) { - (__tmp_132, __tmp_133) => { - (*__tmp_133) = (((*__tmp_133) as u32).wrapping_add((__tmp_132 as u32))) as u32; - (*__tmp_133).clone() - } - }); - (unsafe { - libc::printf( - c"member unsigned %d %u %u %u\n".as_ptr() as *const libc::c_char, - (i), - (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(0) as usize].value), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(1) as usize].value), - ) - }); - i = 0; - match ( - { 1 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(i.postfix_inc()) as usize] - .key) as usize] - .promoted), - ) { - (__tmp_134, __tmp_135) => { - (*__tmp_135) = (((*__tmp_135) as i32) + (__tmp_134 as i32)) as i16; - } - }; - (unsafe { - libc::printf( - c"member promoted %d %d %d\n".as_ptr() as *const libc::c_char, - (i), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(0) as usize].promoted as i32), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(1) as usize].promoted as i32), - ) - }); - i = 0; - result = (match ( - { 99_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(i.postfix_inc()) as usize] - .key) as usize] - .value), - ) { - (__tmp_136, __tmp_137) => { - (*__tmp_137) = __tmp_136; - (*__tmp_137).clone() - } - }); - (unsafe { - libc::printf( - c"member simple %d %u %u %u\n".as_ptr() as *const libc::c_char, - (i), - (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(0) as usize].value), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut a_47))[(1) as usize].value), - ) - }); -} -static mut a_47: std::cell::LazyCell<[IndexedMember; 2]> = std::cell::LazyCell::new(|| unsafe { - [ - IndexedMember { - key: 0, - value: 10_u32, - promoted: 10_i16, - }, - IndexedMember { - key: 1, - value: 20_u32, - promoted: 20_i16, - }, - ] -}); -pub static mut scoped_values_48: std::cell::LazyCell<[u32; 2]> = - std::cell::LazyCell::new(|| unsafe { [10_u32, 20_u32] }); -pub static mut scoped_pointers_49: std::cell::LazyCell<[*mut u32; 1]> = - std::cell::LazyCell::new(|| unsafe { - [(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_values_48)).as_mut_ptr()] - }); -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct PointerSelector { - pub ptr: *mut u32, -} -pub static mut scoped_record_50: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { - PointerSelector { - ptr: (*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_values_48)).as_mut_ptr(), - } - }); -pub unsafe fn test_scoped_pointer_selectors_51() { - let mut i: i32 = 0; - let mut j: i32 = 1; - let mut a: u32 = ({ - (*(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_pointers_49))[(i) as usize] - .offset((j) as isize)) = 3_u32; - (*(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_pointers_49))[(i) as usize] - .offset((j) as isize)) - }); - let mut b: u32 = ({ - (*(*std::cell::LazyCell::force_mut(&mut *&raw mut saved_52))[(i) as usize] - .offset((j) as isize)) = 4_u32; - (*(*std::cell::LazyCell::force_mut(&mut *&raw mut saved_52))[(i) as usize] - .offset((j) as isize)) - }); - let mut c: u32 = ({ - (*(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_record_50)) - .ptr - .offset((j) as isize)) = 5_u32; - (*(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_record_50)) - .ptr - .offset((j) as isize)) - }); - let mut d: u32 = ({ - (*(*std::cell::LazyCell::force_mut(&mut *&raw mut saved_record_53)) - .ptr - .offset((j) as isize)) = 6_u32; - (*(*std::cell::LazyCell::force_mut(&mut *&raw mut saved_record_53)) - .ptr - .offset((j) as isize)) - }); - (unsafe { - libc::printf( - c"scoped pointers %u %u %u %u %u\n".as_ptr() as *const libc::c_char, - (a), - (b), - (c), - (d), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_values_48))[(j) as usize]), - ) - }); -} -static mut saved_52: std::cell::LazyCell<[*mut u32; 1]> = std::cell::LazyCell::new(|| unsafe { - [(*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_values_48)).as_mut_ptr()] -}); -static mut saved_record_53: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { - PointerSelector { - ptr: (*std::cell::LazyCell::force_mut(&mut *&raw mut scoped_values_48)).as_mut_ptr(), - } - }); -pub unsafe fn test_stable_containers_54() { - let mut k: i32 = 1; - let mut key: u8 = 3_u8; - let mut buf: Vec = vec![10_u8; 2_usize]; - buf[(k as usize)] = ((buf[(k as usize)] as i32) ^ (key as i32)) as u8; - let mut a: [u32; 2] = [10_u32, 20_u32]; - a[(k as usize)] = (a[(k as usize)]).wrapping_add((1_u32 as u32)); - let mut s: Vec = std::slice::from_raw_parts( - c"ab".as_ptr(), - (0..).take_while(|&i| *c"ab".as_ptr().add(i) != 0).count() + 1, - ) - .to_vec(); - s[(k as usize)] = ((s[(k as usize)] as i32) + 1) as libc::c_char; - let mut owner: Counts_55 = Counts_55 { - counts: Vec::from([10_u32, 20_u32]), - }; - owner.counts[(k as usize)] = (owner.counts[(k as usize)]).wrapping_add((1_u32 as u32)); - let mut v: Vec = vec![10; 2_usize]; - let mut vector_values: Vec = vec![10_u32; 2_usize]; - let vr: *mut Vec = &mut vector_values; - (&mut (*vr))[(k as usize)] = ((&mut (*vr))[(k as usize)]).wrapping_add((1_u32 as u32)); - let mut ps: Vec = vec![(Pair_56 { u: 10_u32, f: 20 }); 2_usize]; - ps[(k as usize)].u = (ps[(k as usize)].u).wrapping_add((1_u32 as u32)); - let mut compound: i32 = ({ - v[(k as usize)] += 1; - v[(k as usize)] - }); - let mut simple: i32 = ({ - v[(k as usize)] = 2; - v[(k as usize)] - }); - let mut member: i32 = ({ - ps[(k as usize)].f = 4; - ps[(k as usize)].f - }); - let mut g: Vec> = vec![vec![10; 2_usize]; 2_usize]; - let mut nested: i32 = ({ - (*{ - let __idx = (k as usize); - &mut g[(k as usize)][__idx] - }) = 5; - (*{ - let __idx = (k as usize); - &mut g[(k as usize)][__idx] - }) - }); - let mut row: [u32; 2] = [10_u32, 20_u32]; - let mut pointers: [*mut u32; 2] = [row.as_mut_ptr(), row.as_mut_ptr()]; - let mut rows: *mut *mut u32 = pointers.as_mut_ptr(); - let mut i: i32 = 0; - let mut j: i32 = 1; - let mut indirect: u32 = ({ - (*(*rows.offset((i) as isize)).offset((j) as isize)) = 3_u32; - (*(*rows.offset((i) as isize)).offset((j) as isize)) - }); - (unsafe { - libc::printf( - c"containers %u %u %d %u %u %u %d %d %d %d %u\n".as_ptr() as *const libc::c_char, - (buf[(k as usize)] as u32), - (a[(k as usize)]), - (s[(k as usize)] as i32), - (owner.counts[(k as usize)]), - ((&mut (*vr))[(k as usize)]), - (ps[(k as usize)].u), - (compound), - (simple), - (member), - (nested), - (indirect), - ) - }); - let mut it: UnsafeRandomAccessIterator = v.begin(); - let mut iterator_value: u32 = ((match ({ 1_u32 }, &mut (*it.iter_deref())) { - (__tmp_138, __tmp_139) => { - (*__tmp_139) = (((*__tmp_139) as u32).wrapping_add((__tmp_138 as u32))) as i32; - (*__tmp_139).clone() - } - }) as u32); - let mut m: UnsafeMap = UnsafeMap::new(); - (*m.subscript(&k, || 0_u32)) = 10_u32; - let mut mapped_value: u32 = (match ({ 1_u32 }, &mut (*m.subscript(&k, || 0_u32))) { - (__tmp_140, __tmp_141) => { - (*__tmp_141) = (((*__tmp_141) as u32).wrapping_add((__tmp_140 as u32))) as u32; - (*__tmp_141).clone() - } - }); - (unsafe { - libc::printf( - c"nonflat values %u %u\n".as_ptr() as *const libc::c_char, - (iterator_value), - (mapped_value), - ) - }); -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, MoveCtorUnsafe, MoveAssignUnsafe, Default)] -pub struct Counts_55 { - pub counts: Vec, -} -impl Counts_55 { - pub unsafe fn move_from(_a0: *mut Counts_55) -> Self { - let mut this = Self { - counts: std::mem::take(&mut (*_a0).counts), - }; - this - } - pub unsafe fn move_assign(&mut self, _a0: *mut Counts_55) -> *mut Counts_55 { - { - self.counts = std::mem::take(&mut (*_a0).counts); - }; - return &mut (*(self as *mut Counts_55)); - } -} -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Pair_56 { - pub u: u32, - pub f: i32, -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - libcc2rs::cpp2rust_exit(main_0() as i32); - } +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0() as i32); + } } unsafe fn main_0() -> i32 { - (unsafe { test_stable_containers_54() }); - (unsafe { test_scoped_pointer_selectors_51() }); - let mut a: [i32; 2] = [10, 20]; - let mut index: i32 = 1; - let mut value: i32 = ({ - a[(index) as usize] = 99; - a[(index) as usize] - }); - (unsafe { - libc::printf( - c"stable index %d %d %d %d\n".as_ptr() as *const libc::c_char, - (index), - (value), - (a[(0) as usize]), - (a[(1) as usize]), - ) - }); - value = ({ - a[((index) - (1)) as usize] = 42; - a[((index) - (1)) as usize] - }); - (unsafe { - libc::printf( - c"stable arithmetic %d %d %d\n".as_ptr() as *const libc::c_char, - (value), - (a[(0) as usize]), - (a[(1) as usize]), - ) - }); - let mut selector: Index_57 = Index_57 { value: 1 }; - value = ({ - a[(selector.value) as usize] = 88; - a[(selector.value) as usize] - }); - let mut rows: [[i32; 2]; 2] = [[1, 2], [3, 4]]; - let mut row_value: i32 = ({ - rows[(index) as usize][(index) as usize] = 55; - rows[(index) as usize][(index) as usize] - }); - (unsafe { - libc::printf( - c"stable composite %d %d %d\n".as_ptr() as *const libc::c_char, - (value), - (a[(1) as usize]), - (row_value), - ) - }); - let alias: *mut i32 = &mut a[(0) as usize]; - (*alias) = 0; - value = (match ({ 1 }, &mut (a[(*alias) as usize])) { - (__tmp_142, __tmp_143) => { - (*__tmp_143) = __tmp_142; - (*__tmp_143).clone() - } - }); - (unsafe { - libc::printf( - c"aliased index %d %d %d\n".as_ptr() as *const libc::c_char, - (value), - (a[(0) as usize]), - (a[(1) as usize]), - ) - }); - let mut pointer: *mut i32 = a.as_mut_ptr(); - let reference: *mut [i32; 2] = &mut a; - value = ({ - (*pointer.offset((index) as isize)) = 66; - (*pointer.offset((index) as isize)) - }); - let mut reference_value: i32 = ({ - (*reference)[(index) as usize] = 77; - (*reference)[(index) as usize] - }); - let mut deref_value: i32 = ({ - (*pointer) = 55; - (*pointer) - }); - (unsafe { - libc::printf( - c"stable indirect %d %d %d %d %d\n".as_ptr() as *const libc::c_char, - (value), - (reference_value), - (deref_value), - (a[(0) as usize]), - (a[(1) as usize]), - ) - }); - let mut indices: [i32; 2] = [1, 0]; - value = ({ - (*pointer.offset((selector.value) as isize)) = 55; - (*pointer.offset((selector.value) as isize)) - }); - reference_value = ({ - (*reference)[(indices[(0) as usize]) as usize] = 44; - (*reference)[(indices[(0) as usize]) as usize] - }); - deref_value = ({ - (*(pointer.offset((selector.value) as isize))) = 33; - (*(pointer.offset((selector.value) as isize))) - }); - (unsafe { - libc::printf( - c"aggregate selectors %d %d %d %d\n".as_ptr() as *const libc::c_char, - (value), - (reference_value), - (deref_value), - (a[(1) as usize]), - ) - }); - let mut owner: Owner_58 = Owner_58 { - values: [0, 20], - index: 0, - }; - value = (match ( - { 1 }, - &mut (owner.values[(owner.values[(0) as usize]) as usize]), - ) { - (__tmp_144, __tmp_145) => { - (*__tmp_145) = __tmp_144; - (*__tmp_145).clone() - } - }); - reference_value = ({ - owner.values[(owner.index) as usize] = 11; - owner.values[(owner.index) as usize] - }); - (unsafe { - libc::printf( - c"owner selectors %d %d %d %d\n".as_ptr() as *const libc::c_char, - (value), - (reference_value), - (owner.values[(0) as usize]), - (owner.values[(1) as usize]), - ) - }); - let mut alias_selector: Index_57 = Index_57 { value: 0 }; - let mut member_alias: *mut i32 = (&mut alias_selector.value as *mut i32); - value = (match ( - { 1 }, - &mut (*member_alias.offset((alias_selector.value) as isize)), - ) { - (__tmp_146, __tmp_147) => { - (*__tmp_147) = __tmp_146; - (*__tmp_147).clone() - } - }); - (unsafe { - libc::printf( - c"member alias %d %d\n".as_ptr() as *const libc::c_char, - (value), - (alias_selector.value), - ) - }); - let mut self_index: i32 = 0; - let mut self_: *mut i32 = (&mut self_index as *mut i32); - value = (match ({ 1 }, &mut (*self_.offset((self_index) as isize))) { - (__tmp_148, __tmp_149) => { - (*__tmp_149) = __tmp_148; - (*__tmp_149).clone() - } - }); - (unsafe { - libc::printf( - c"aliased indirect %d %d\n".as_ptr() as *const libc::c_char, - (value), - (self_index), - ) - }); - let mut captured_index: i32 = 0; - let mut captured_pointer: *mut i32 = (&mut captured_index as *mut i32); - let mut assign_captured: FnPtr i32> = lambda_unsafe!( - { - let captured_pointer: *mut *mut i32 = &mut captured_pointer; - let captured_index: *mut i32 = &mut captured_index; - }, - || -> i32 { - return (match ( - { 10000 }, - &mut (*(*captured_pointer).offset((*captured_index) as isize)), - ) { - (__tmp_150, __tmp_151) => { - (*__tmp_151) = __tmp_150; - (*__tmp_151).clone() - } - }); - } - ); - value = (unsafe { assign_captured.call() }).clone(); - (unsafe { - libc::printf( - c"captured indirect %d %d\n".as_ptr() as *const libc::c_char, - (value), - (captured_index), - ) - }); - (unsafe { test_local_members_44() }); - (unsafe { test_global_members_45() }); - (unsafe { test_static_members_46() }); - (unsafe { test_reference_members_5() }); - (unsafe { test_reference_members_7() }); - (unsafe { test_reference_pointer_9() }); - (unsafe { test_reference_subfields_11() }); - (unsafe { test_reference_subfields_14() }); - (unsafe { test_captured_alias_17() }); (unsafe { test_0() }); (unsafe { test_1() }); - (unsafe { test_2() }); - (unsafe { test_comma_3() }); - (unsafe { test_comma_4() }); - let mut values: [u32; 2] = [10_u32, 20_u32]; - let ref_: *mut [u32; 2] = &mut values; - let mut i: i32 = 0; - let mut result: u32 = (match ( - { 5_u32 }, - &mut ((*({ - i.prefix_inc(); - (ref_).clone() - }))[(0) as usize]), - ) { - (__tmp_152, __tmp_153) => { - (*__tmp_153) = (((*__tmp_153) as u32).wrapping_add((__tmp_152 as u32))) as u32; - (*__tmp_153).clone() - } - }); - (unsafe { - libc::printf( - c"array reference %d %u %u\n".as_ptr() as *const libc::c_char, - (i), - (result), - (values[(0) as usize]), - ) - }); - (unsafe { test_borrows_25() }); - (unsafe { test_binding_31() }); - (unsafe { test_alias_scopes_36(10_i16) }); - (unsafe { test_boxed_array_37() }); - (unsafe { test_boxed_array_39() }); - let mut global_result: u32 = (match ( - { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_41)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_41))[(0) as usize]) - as usize]), - ) { - (__tmp_154, __tmp_155) => { - (*__tmp_155) = (((*__tmp_155) as u32).wrapping_add((__tmp_154 as u32))) as u32; - (*__tmp_155).clone() - } - }); - (unsafe { - libc::printf( - c"global array %u %u\n".as_ptr() as *const libc::c_char, - (global_result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_array_41))[(0) as usize]), - ) - }); - i = 0; - result = (match ( - { 1_u32 }, - &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_42)) - [((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_42)) - [(i.postfix_inc()) as usize][(0) as usize]) as usize][(0) as usize]), - ) { - (__tmp_156, __tmp_157) => { - (*__tmp_157) = (((*__tmp_157) as u32).wrapping_add((__tmp_156 as u32))) as u32; - (*__tmp_157).clone() - } - }); - (unsafe { - libc::printf( - c"nested array %d %u %u %u\n".as_ptr() as *const libc::c_char, - (i), - (result), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_42))[(0) as usize] - [(0) as usize]), - ((*std::cell::LazyCell::force_mut(&mut *&raw mut global_rows_42))[(1) as usize] - [(0) as usize]), - ) - }); - return 0; -} -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Index_57 { - pub value: i32, -} -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Owner_58 { - pub values: [i32; 2], - pub index: i32, -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const global_18); - std::cell::LazyCell::force(&*&raw const global_record_21); - std::cell::LazyCell::force(&*&raw const targets_23); - std::cell::LazyCell::force(&*&raw const cursor_24); - std::cell::LazyCell::force(&*&raw const selected_values_30); - std::cell::LazyCell::force(&*&raw const initializer_target_33); - std::cell::LazyCell::force(&*&raw const initializer_result_35); - std::cell::LazyCell::force(&*&raw const global_array_41); - std::cell::LazyCell::force(&*&raw const global_rows_42); - std::cell::LazyCell::force(&*&raw const global_members_43); - std::cell::LazyCell::force(&*&raw const scoped_values_48); - std::cell::LazyCell::force(&*&raw const scoped_pointers_49); - std::cell::LazyCell::force(&*&raw const scoped_record_50); + 0 } +pub unsafe fn __cpp2rust_init_globals() {} From ed4265cfa9dc3925a33290de62e14947c9e97d9f Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Sun, 29 Nov 2026 17:52:24 +0000 Subject: [PATCH 20/25] Keep boolean floating compound coverage in the small assignment test Signed-off-by: Perfloop Agent --- tests/unit/assignment_single_eval.cpp | 4 ++++ .../unit/out/refcount/assignment_single_eval.rs | 16 ++++++++++++++++ tests/unit/out/unsafe/assignment_single_eval.rs | 16 ++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index a8af331e4f..9276abd688 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -13,4 +13,8 @@ template void test() { int main() { test(); test(); + bool flags[] = {false}; + int i = 0; + bool result = (flags[i++] += 0.5); + std::printf("%d %d %d\n", i, (int)result, (int)flags[0]); } diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 7e87d7ca85..0169fbe6ba 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -87,6 +87,22 @@ pub fn main() { fn main_0() -> i32 { ({ test_0() }); ({ test_1() }); + let mut flags: [bool; 1] = [false]; + let mut i: i32 = 0; + let mut result: bool = ({ + match ({ 0.5_f64 }, &mut (flags[(i.postfix_inc()) as usize])) { + (__tmp_12, __tmp_13) => { + (*__tmp_13) = (((*__tmp_13) as u8 as f64) + (__tmp_12 as f64)) != 0.0; + (*__tmp_13).clone() + } + } + }); + printf!( + b"%d %d %d\n", + i, + (result as i32), + (flags[(0) as usize] as i32) + ); 0 } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 475afafa9e..20466c321a 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -81,6 +81,22 @@ pub fn main() { unsafe fn main_0() -> i32 { (unsafe { test_0() }); (unsafe { test_1() }); + let mut flags: [bool; 1] = [false]; + let mut i: i32 = 0; + let mut result: bool = (match ({ 0.5_f64 }, &mut (flags[(i.postfix_inc()) as usize])) { + (__tmp_12, __tmp_13) => { + (*__tmp_13) = (((*__tmp_13) as u8 as f64) + (__tmp_12 as f64)) != 0.0; + (*__tmp_13).clone() + } + }); + (unsafe { + libc::printf( + c"%d %d %d\n".as_ptr() as *const libc::c_char, + (i), + (result as i32), + (flags[(0) as usize] as i32), + ) + }); 0 } pub unsafe fn __cpp2rust_init_globals() {} From 0e9fb330217ab15004290261e18a471c9a62df7a Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Sun, 29 Nov 2026 19:11:11 +0000 Subject: [PATCH 21/25] Protect nested, reference-member and pointer assignment lowering Signed-off-by: Perfloop Agent --- tests/unit/assignment_single_eval.cpp | 20 +++ .../out/refcount/assignment_single_eval.rs | 117 ++++++++++++++++-- .../unit/out/unsafe/assignment_single_eval.rs | 95 ++++++++++++-- 3 files changed, 218 insertions(+), 14 deletions(-) diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index 9276abd688..df69c6e99c 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -1,5 +1,7 @@ #include +unsigned rows[2][2] = {{0, 10}, {20, 30}}; + template void test() { T a[] = {10, 20, 30, 40}; int i = 0; @@ -13,6 +15,24 @@ template void test() { int main() { test(); test(); + int row = 0; + unsigned nested = (rows[rows[row++][0]][0] += 1); + std::printf("%d %u %u\n", row, nested, rows[0][0]); + struct Slot { + unsigned &value; + }; + unsigned index = 0, other = 77; + Slot slots[] = {{index}, {other}}; + unsigned member = (slots[index].value += 1); + std::printf("%u %u %u\n", index, other, member); + index = 0; + member = (slots[index].value = 1); + std::printf("%u %u %u\n", index, other, member); + int values[2] = {1, 2}; + int *p = values + 1; + int j = 0; + int *q = (*(&p + j++) -= 1); + std::printf("%d %d %d\n", j, p == values, q == values); bool flags[] = {false}; int i = 0; bool result = (flags[i++] += 0.5); diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 0169fbe6ba..3e9fa51597 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -6,7 +6,13 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn test_0() { +thread_local!( + pub static rows_0: Value]>> = Rc::new(RefCell::new(Box::new([ + Box::new([0_u32, 10_u32]), + Box::new([20_u32, 30_u32]), + ]))); +); +pub fn test_1() { let mut a: [u32; 4] = [10_u32, 20_u32, 30_u32, 40_u32]; let mut i: i32 = 0; { @@ -43,7 +49,7 @@ pub fn test_0() { (a[(3) as usize] as i32) ); } -pub fn test_1() { +pub fn test_2() { let mut a: [i16; 4] = [10_i16, 20_i16, 30_i16, 40_i16]; let mut i: i32 = 0; { @@ -85,15 +91,103 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ test_0() }); ({ test_1() }); + ({ test_2() }); + let mut row: i32 = 0; + let mut nested: u32 = ({ + match ({ 1_u32 }, { + let __tmp_13 = rows_0 + .with(|v| v.decay()) + .offset( + ({ + let __idx0 = (row.postfix_inc()) as usize; + let __idx1 = (0) as usize; + rows_0.with(|rc| rc.borrow()[__idx0][__idx1]) + }), + ) + .decay() + .offset(0); + __tmp_13 + }) { + (__tmp_12, __tmp_13) => __tmp_13.with_mut(|__tmp_13| { + (*__tmp_13) = (((*__tmp_13) as u32).wrapping_add((__tmp_12 as u32))) as u32; + (*__tmp_13).clone() + }), + } + }); + printf!( + b"%d %u %u\n", + row, + nested, + ({ + let __idx0 = (0) as usize; + let __idx1 = (0) as usize; + rows_0.with(|rc| rc.borrow()[__idx0][__idx1]) + }) + ); + let index: Value = Rc::new(RefCell::new(0_u32)); + let other: Value = Rc::new(RefCell::new(77_u32)); + let mut slots: [Slot_3; 2] = [ + Slot_3 { + value: index.as_pointer(), + }, + Slot_3 { + value: other.as_pointer(), + }, + ]; + let mut member: u32 = ({ + match ({ 1_u32 }, { + let __tmp_15 = (slots[(*index.borrow()) as usize].value).clone(); + __tmp_15 + }) { + (__tmp_14, __tmp_15) => __tmp_15.with_mut(|__tmp_15| { + (*__tmp_15) = (((*__tmp_15) as u32).wrapping_add((__tmp_14 as u32))) as u32; + (*__tmp_15).clone() + }), + } + }); + printf!(b"%u %u %u\n", (*index.borrow()), (*other.borrow()), member); + (*index.borrow_mut()) = 0_u32; + let __rhs = ({ + match ({ 1_u32 }, { + let __tmp_17 = (slots[(*index.borrow()) as usize].value).clone(); + __tmp_17 + }) { + (__tmp_16, __tmp_17) => __tmp_17.with_mut(|__tmp_17| { + (*__tmp_17) = __tmp_16; + (*__tmp_17).clone() + }), + } + }); + member = __rhs; + printf!(b"%u %u %u\n", (*index.borrow()), (*other.borrow()), member); + let values: Value> = Rc::new(RefCell::new(Box::new([1, 2]))); + let p: Value> = Rc::new(RefCell::new(values.decay().offset((1) as isize))); + let mut j: i32 = 0; + let mut q: Ptr = ({ + match ( + { 1 }, + &((p.as_pointer()).offset((j.postfix_inc()) as isize)), + ) { + (__tmp_18, __tmp_19) => __tmp_19.with_mut(|__tmp_19| { + (*__tmp_19) = (*__tmp_19).offset(-(__tmp_18 as isize)); + (*__tmp_19).clone() + }), + } + }); + printf!( + b"%d %d %d\n", + j, + (({ (*p.borrow()).clone() } == { values.decay() }) as i32), + (({ (q).clone() } == { values.decay() }) as i32) + ); let mut flags: [bool; 1] = [false]; let mut i: i32 = 0; let mut result: bool = ({ match ({ 0.5_f64 }, &mut (flags[(i.postfix_inc()) as usize])) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = (((*__tmp_13) as u8 as f64) + (__tmp_12 as f64)) != 0.0; - (*__tmp_13).clone() + (__tmp_20, __tmp_21) => { + (*__tmp_21) = (((*__tmp_21) as u8 as f64) + (__tmp_20 as f64)) != 0.0; + (*__tmp_21).clone() } } }); @@ -105,4 +199,13 @@ fn main_0() -> i32 { ); 0 } -pub fn __cpp2rust_init_globals() {} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct Slot_3 { + #[offset(0)] + #[byte_size(8)] + pub value: Ptr, +} +pub fn __cpp2rust_init_globals() { + let _ = rows_0.with(|_| ()); +} diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 20466c321a..a878506abe 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -6,7 +6,9 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn test_0() { +pub static mut rows_0: std::cell::LazyCell<[[u32; 2]; 2]> = + std::cell::LazyCell::new(|| unsafe { [[0_u32, 10_u32], [20_u32, 30_u32]] }); +pub unsafe fn test_1() { let mut a: [u32; 4] = [10_u32, 20_u32, 30_u32, 40_u32]; let mut i: i32 = 0; match ({ 5_u32 }, &mut (a[(i.postfix_inc()) as usize])) { @@ -39,7 +41,7 @@ pub unsafe fn test_0() { ) }); } -pub unsafe fn test_1() { +pub unsafe fn test_2() { let mut a: [i16; 4] = [10_i16, 20_i16, 30_i16, 40_i16]; let mut i: i32 = 0; match ({ 5 }, &mut (a[(i.postfix_inc()) as usize])) { @@ -79,14 +81,86 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { test_0() }); (unsafe { test_1() }); + (unsafe { test_2() }); + let mut row: i32 = 0; + let mut nested: u32 = (match ( + { 1_u32 }, + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut rows_0)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut rows_0)) + [(row.postfix_inc()) as usize][(0) as usize]) as usize][(0) as usize]), + ) { + (__tmp_12, __tmp_13) => { + (*__tmp_13) = (((*__tmp_13) as u32).wrapping_add((__tmp_12 as u32))) as u32; + (*__tmp_13).clone() + } + }); + (unsafe { + libc::printf( + c"%d %u %u\n".as_ptr() as *const libc::c_char, + (row), + (nested), + ((*std::cell::LazyCell::force_mut(&mut *&raw mut rows_0))[(0) as usize][(0) as usize]), + ) + }); + let mut index: u32 = 0_u32; + let mut other: u32 = 77_u32; + let mut slots: [Slot_3; 2] = [Slot_3 { value: &mut index }, Slot_3 { value: &mut other }]; + let mut member: u32 = (match ({ 1_u32 }, &mut (*slots[(index) as usize].value)) { + (__tmp_14, __tmp_15) => { + (*__tmp_15) = (((*__tmp_15) as u32).wrapping_add((__tmp_14 as u32))) as u32; + (*__tmp_15).clone() + } + }); + (unsafe { + libc::printf( + c"%u %u %u\n".as_ptr() as *const libc::c_char, + (index), + (other), + (member), + ) + }); + index = 0_u32; + member = (match ({ 1_u32 }, &mut (*slots[(index) as usize].value)) { + (__tmp_16, __tmp_17) => { + (*__tmp_17) = __tmp_16; + (*__tmp_17).clone() + } + }); + (unsafe { + libc::printf( + c"%u %u %u\n".as_ptr() as *const libc::c_char, + (index), + (other), + (member), + ) + }); + let mut values: [i32; 2] = [1, 2]; + let mut p: *mut i32 = values.as_mut_ptr().offset((1) as isize); + let mut j: i32 = 0; + let mut q: *mut i32 = (match ( + { 1 }, + &mut (*((&mut p as *mut *mut i32).offset((j.postfix_inc()) as isize))), + ) { + (__tmp_18, __tmp_19) => { + (*__tmp_19) = (*__tmp_19).offset(-(__tmp_18 as isize)); + (*__tmp_19).clone() + } + }); + (unsafe { + libc::printf( + c"%d %d %d\n".as_ptr() as *const libc::c_char, + (j), + (((p) == (values.as_mut_ptr())) as i32), + (((q) == (values.as_mut_ptr())) as i32), + ) + }); let mut flags: [bool; 1] = [false]; let mut i: i32 = 0; let mut result: bool = (match ({ 0.5_f64 }, &mut (flags[(i.postfix_inc()) as usize])) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = (((*__tmp_13) as u8 as f64) + (__tmp_12 as f64)) != 0.0; - (*__tmp_13).clone() + (__tmp_20, __tmp_21) => { + (*__tmp_21) = (((*__tmp_21) as u8 as f64) + (__tmp_20 as f64)) != 0.0; + (*__tmp_21).clone() } }); (unsafe { @@ -99,4 +173,11 @@ unsafe fn main_0() -> i32 { }); 0 } -pub unsafe fn __cpp2rust_init_globals() {} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Slot_3 { + pub value: *mut u32, +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const rows_0); +} From 821a9a4214d1398942984b14bd9805abf089318d Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Sun, 29 Nov 2026 20:41:13 +0000 Subject: [PATCH 22/25] Cover assignment ordering through aliased and captured locals Signed-off-by: Perfloop Agent --- tests/unit/assignment_single_eval.cpp | 15 ++++++ .../out/refcount/assignment_single_eval.rs | 49 +++++++++++++++++-- .../unit/out/unsafe/assignment_single_eval.rs | 39 +++++++++++++-- 3 files changed, 97 insertions(+), 6 deletions(-) diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index df69c6e99c..7dafc39040 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -33,6 +33,21 @@ int main() { int j = 0; int *q = (*(&p + j++) -= 1); std::printf("%d %d %d\n", j, p == values, q == values); + unsigned x = 10; + unsigned *alias = &x; + auto mutate = [alias]() { + *alias = 20; + return 5u; + }; + x += mutate(); + std::printf("%u\n", x); + unsigned captured = 10; + auto change = [&captured]() { + captured = 20; + return 5u; + }; + captured += change(); + std::printf("%u\n", captured); bool flags[] = {false}; int i = 0; bool result = (flags[i++] += 0.5); diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 3e9fa51597..c607ed0db7 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -181,13 +181,56 @@ fn main_0() -> i32 { (({ (*p.borrow()).clone() } == { values.decay() }) as i32), (({ (q).clone() } == { values.decay() }) as i32) ); + let x: Value = Rc::new(RefCell::new(10_u32)); + let alias: Value> = Rc::new(RefCell::new((x.as_pointer()))); + let mutate: Value u32>> = Rc::new(RefCell::new(lambda!( + { + let alias: Value> = Rc::new(RefCell::new((*alias.borrow()).clone())); + }, + || -> u32 { + (*alias.borrow()).write(20_u32); + return 5_u32; + } + ))); + { + match ( + { ({ (*mutate.borrow()).call() }).clone() }, + &mut (*x.borrow_mut()), + ) { + (__tmp_20, __tmp_21) => { + (*__tmp_21) = (((*__tmp_21) as u32).wrapping_add((__tmp_20 as u32))) as u32; + } + } + }; + printf!(b"%u\n", (*x.borrow())); + let captured: Value = Rc::new(RefCell::new(10_u32)); + let change: Value u32>> = Rc::new(RefCell::new(lambda!( + { + let captured: Ptr = captured.as_pointer(); + }, + || -> u32 { + captured.write(20_u32); + return 5_u32; + } + ))); + { + match ( + { ({ (*change.borrow()).call() }).clone() }, + &mut (*captured.borrow_mut()), + ) { + (__tmp_22, __tmp_23) => { + (*__tmp_23) = (((*__tmp_23) as u32).wrapping_add((__tmp_22 as u32))) as u32; + } + } + }; + printf!(b"%u\n", (*captured.borrow())); let mut flags: [bool; 1] = [false]; let mut i: i32 = 0; let mut result: bool = ({ match ({ 0.5_f64 }, &mut (flags[(i.postfix_inc()) as usize])) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = (((*__tmp_21) as u8 as f64) + (__tmp_20 as f64)) != 0.0; - (*__tmp_21).clone() + (__tmp_24, __tmp_25) => { + (*__tmp_25) = (((*__tmp_25) as u8 as f64) + (__tmp_24 as f64)) != 0.0; + (*__tmp_25).clone() } } }); diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index a878506abe..e1f9ec6850 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -155,12 +155,45 @@ unsafe fn main_0() -> i32 { (((q) == (values.as_mut_ptr())) as i32), ) }); + let mut x: u32 = 10_u32; + let mut alias: *mut u32 = (&mut x as *mut u32); + let mut mutate: FnPtr u32> = lambda_unsafe!( + { + let alias: *mut u32 = alias; + }, + || -> u32 { + (*alias) = 20_u32; + return 5_u32; + } + ); + match ({ (unsafe { mutate.call() }).clone() }, &mut (x)) { + (__tmp_20, __tmp_21) => { + (*__tmp_21) = (((*__tmp_21) as u32).wrapping_add((__tmp_20 as u32))) as u32; + } + }; + (unsafe { libc::printf(c"%u\n".as_ptr() as *const libc::c_char, (x)) }); + let mut captured: u32 = 10_u32; + let mut change: FnPtr u32> = lambda_unsafe!( + { + let captured: *mut u32 = &mut captured; + }, + || -> u32 { + (*captured) = 20_u32; + return 5_u32; + } + ); + match ({ (unsafe { change.call() }).clone() }, &mut (captured)) { + (__tmp_22, __tmp_23) => { + (*__tmp_23) = (((*__tmp_23) as u32).wrapping_add((__tmp_22 as u32))) as u32; + } + }; + (unsafe { libc::printf(c"%u\n".as_ptr() as *const libc::c_char, (captured)) }); let mut flags: [bool; 1] = [false]; let mut i: i32 = 0; let mut result: bool = (match ({ 0.5_f64 }, &mut (flags[(i.postfix_inc()) as usize])) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = (((*__tmp_21) as u8 as f64) + (__tmp_20 as f64)) != 0.0; - (*__tmp_21).clone() + (__tmp_24, __tmp_25) => { + (*__tmp_25) = (((*__tmp_25) as u8 as f64) + (__tmp_24 as f64)) != 0.0; + (*__tmp_25).clone() } }); (unsafe { From 54246003e55bbb4b704e28ed8f990ab9af1869df Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Sun, 29 Nov 2026 22:01:44 +0000 Subject: [PATCH 23/25] Cover compound assignment through a comma-selected array reference Signed-off-by: Perfloop Agent --- tests/unit/assignment_single_eval.cpp | 5 ++++ .../out/refcount/assignment_single_eval.rs | 27 +++++++++++++++++++ .../unit/out/unsafe/assignment_single_eval.rs | 24 +++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index 7dafc39040..dd4146b4ce 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -52,4 +52,9 @@ int main() { int i = 0; bool result = (flags[i++] += 0.5); std::printf("%d %d %d\n", i, (int)result, (int)flags[0]); + unsigned a[2] = {10, 20}; + unsigned (&ref)[2] = a; + i = 0; + unsigned v = ((++i, ref)[0] += 5); + std::printf("%d %u %u %u\n", i, v, a[0], a[1]); } diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index c607ed0db7..0b0c9c4201 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -240,6 +240,33 @@ fn main_0() -> i32 { (result as i32), (flags[(0) as usize] as i32) ); + let a: Value> = Rc::new(RefCell::new(Box::new([10_u32, 20_u32]))); + let ref_: Ptr = a.decay(); + i = 0; + let mut v: u32 = ({ + match ( + { 5_u32 }, + &(elem!( + { + i.prefix_inc(); + (ref_).clone() + }, + 0 + )), + ) { + (__tmp_26, __tmp_27) => __tmp_27.with_mut(|__tmp_27| { + (*__tmp_27) = (((*__tmp_27) as u32).wrapping_add((__tmp_26 as u32))) as u32; + (*__tmp_27).clone() + }), + } + }); + printf!( + b"%d %u %u %u\n", + i, + v, + (*a.borrow())[(0) as usize], + (*a.borrow())[(1) as usize] + ); 0 } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index e1f9ec6850..82ab8c7ff0 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -204,6 +204,30 @@ unsafe fn main_0() -> i32 { (flags[(0) as usize] as i32), ) }); + let mut a: [u32; 2] = [10_u32, 20_u32]; + let ref_: *mut [u32; 2] = &mut a; + i = 0; + let mut v: u32 = (match ( + { 5_u32 }, + &mut ((*({ + i.prefix_inc(); + (ref_).clone() + }))[(0) as usize]), + ) { + (__tmp_26, __tmp_27) => { + (*__tmp_27) = (((*__tmp_27) as u32).wrapping_add((__tmp_26 as u32))) as u32; + (*__tmp_27).clone() + } + }); + (unsafe { + libc::printf( + c"%d %u %u %u\n".as_ptr() as *const libc::c_char, + (i), + (v), + (a[(0) as usize]), + (a[(1) as usize]), + ) + }); 0 } #[repr(C)] From e983502109dcfa70c5530cc26c8af09d02965ce2 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Mon, 30 Nov 2026 01:04:24 +0000 Subject: [PATCH 24/25] Cover compact assignment values and bound target lifetimes Signed-off-by: Perfloop Agent --- tests/unit/assignment_single_eval.cpp | 33 +++ .../out/refcount/assignment_single_eval.rs | 258 ++++++++++++++---- .../unit/out/unsafe/assignment_single_eval.rs | 221 +++++++++++++-- 3 files changed, 441 insertions(+), 71 deletions(-) diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index dd4146b4ce..1df18fefa5 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -1,6 +1,15 @@ #include unsigned rows[2][2] = {{0, 10}, {20, 30}}; +unsigned global = 10; +unsigned mutate_global() { + global = 20; + return 5; +} +struct Holder { + unsigned value; +} holder{10}; +unsigned inspect(unsigned value) { return value + holder.value; } template void test() { T a[] = {10, 20, 30, 40}; @@ -8,6 +17,11 @@ template void test() { a[i++] += 5; T compound = (a[i++] += 5); T assigned = (a[i++] = 99); + T local = 10; + T scalar = (local += 5); + T element = (a[0] += 5); + std::printf("%d %d %d %d\n", (int)local, (int)scalar, (int)element, + (int)a[0]); std::printf("%d %d %d: %d %d %d %d\n", i, (int)compound, (int)assigned, (int)a[0], (int)a[1], (int)a[2], (int)a[3]); } @@ -17,6 +31,9 @@ int main() { test(); int row = 0; unsigned nested = (rows[rows[row++][0]][0] += 1); + unsigned global_result = (global += mutate_global()); + std::printf("%u %u\n", global_result, global); + std::printf("%u\n", inspect(holder.value += mutate_global())); std::printf("%d %u %u\n", row, nested, rows[0][0]); struct Slot { unsigned &value; @@ -28,6 +45,14 @@ int main() { index = 0; member = (slots[index].value = 1); std::printf("%u %u %u\n", index, other, member); + struct Index { + unsigned value; + } first{0}, second{77}; + struct Group { + Index &ref; + } groups[] = {{first}, {second}}; + member = (groups[first.value].ref.value += 1); + std::printf("%u %u %u\n", first.value, second.value, member); int values[2] = {1, 2}; int *p = values + 1; int j = 0; @@ -48,6 +73,11 @@ int main() { }; captured += change(); std::printf("%u\n", captured); + short outer = 10; + short *ptr = &outer; + auto update = [&]() { return (outer += (*ptr = -1, 0.5)); }; + int updated = update(); + std::printf("%d %d\n", updated, (int)outer); bool flags[] = {false}; int i = 0; bool result = (flags[i++] += 0.5); @@ -57,4 +87,7 @@ int main() { i = 0; unsigned v = ((++i, ref)[0] += 5); std::printf("%d %u %u %u\n", i, v, a[0], a[1]); + unsigned *target = &v; + unsigned comma = ((++i, *target) += 1); + std::printf("%d %u %u\n", i, comma, *target); } diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 0b0c9c4201..5a1d50a865 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -12,7 +12,26 @@ thread_local!( Box::new([20_u32, 30_u32]), ]))); ); -pub fn test_1() { +thread_local!( + pub static global_1: Value = Rc::new(RefCell::new(10_u32)); +); +pub fn mutate_global_2() -> u32 { + global_1.with(|rc| *rc.borrow_mut() = 20_u32); + return 5_u32; +} +#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(4)] +pub struct Holder { + #[offset(0)] + pub value: u32, +} +thread_local!( + pub static holder_3: Value = Rc::new(RefCell::new(Holder { value: 10_u32 })); +); +pub fn inspect_4(mut value: u32) -> u32 { + return (value).wrapping_add({ holder_3.with(|rc| *rc.borrow()).value }); +} +pub fn test_5() { let mut a: [u32; 4] = [10_u32, 20_u32, 30_u32, 40_u32]; let mut i: i32 = 0; { @@ -38,6 +57,22 @@ pub fn test_1() { } } }); + let mut local: u32 = 10_u32; + let mut scalar: u32 = ({ + local = { (local).wrapping_add(5_u32) }; + local + }); + let mut element: u32 = ({ + a[(0) as usize] = { (a[(0) as usize]).wrapping_add(5_u32) }; + a[(0) as usize] + }); + printf!( + b"%d %d %d %d\n", + (local as i32), + (scalar as i32), + (element as i32), + (a[(0) as usize] as i32) + ); printf!( b"%d %d %d: %d %d %d %d\n", i, @@ -49,7 +84,7 @@ pub fn test_1() { (a[(3) as usize] as i32) ); } -pub fn test_2() { +pub fn test_6() { let mut a: [i16; 4] = [10_i16, 20_i16, 30_i16, 40_i16]; let mut i: i32 = 0; { @@ -75,6 +110,22 @@ pub fn test_2() { } } }); + let mut local: i16 = 10_i16; + let mut scalar: i16 = ({ + local = { ((local as i32) + 5) as i16 }; + local + }); + let mut element: i16 = ({ + a[(0) as usize] = { ((a[(0) as usize] as i32) + 5) as i16 }; + a[(0) as usize] + }); + printf!( + b"%d %d %d %d\n", + (local as i32), + (scalar as i32), + (element as i32), + (a[(0) as usize] as i32) + ); printf!( b"%d %d %d: %d %d %d %d\n", i, @@ -91,8 +142,8 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ test_1() }); - ({ test_2() }); + ({ test_5() }); + ({ test_6() }); let mut row: i32 = 0; let mut nested: u32 = ({ match ({ 1_u32 }, { @@ -115,6 +166,32 @@ fn main_0() -> i32 { }), } }); + let mut global_result: u32 = ({ + let __tmp_14 = ({ mutate_global_2() }); + { + let rhs_0 = + ((global_1.with(|rc| *rc.borrow()) as u32).wrapping_add((__tmp_14 as u32))) as u32; + global_1.with(|rc| *rc.borrow_mut() = rhs_0); + global_1.with(|rc| *rc.borrow()) + } + }); + printf!(b"%u %u\n", global_result, global_1.with(|rc| *rc.borrow())); + printf!( + b"%u\n", + ({ + inspect_4({ + match ( + { ({ mutate_global_2() }) }, + &mut ((*holder_3.with(Value::clone).borrow_mut()).value), + ) { + (__tmp_15, __tmp_16) => { + (*__tmp_16) = (((*__tmp_16) as u32).wrapping_add((__tmp_15 as u32))) as u32; + (*__tmp_16).clone() + } + } + }) + }) + ); printf!( b"%d %u %u\n", row, @@ -127,22 +204,22 @@ fn main_0() -> i32 { ); let index: Value = Rc::new(RefCell::new(0_u32)); let other: Value = Rc::new(RefCell::new(77_u32)); - let mut slots: [Slot_3; 2] = [ - Slot_3 { + let mut slots: [Slot_7; 2] = [ + Slot_7 { value: index.as_pointer(), }, - Slot_3 { + Slot_7 { value: other.as_pointer(), }, ]; let mut member: u32 = ({ match ({ 1_u32 }, { - let __tmp_15 = (slots[(*index.borrow()) as usize].value).clone(); - __tmp_15 + let __tmp_18 = (slots[(*index.borrow()) as usize].value).clone(); + __tmp_18 }) { - (__tmp_14, __tmp_15) => __tmp_15.with_mut(|__tmp_15| { - (*__tmp_15) = (((*__tmp_15) as u32).wrapping_add((__tmp_14 as u32))) as u32; - (*__tmp_15).clone() + (__tmp_17, __tmp_18) => __tmp_18.with_mut(|__tmp_18| { + (*__tmp_18) = (((*__tmp_18) as u32).wrapping_add((__tmp_17 as u32))) as u32; + (*__tmp_18).clone() }), } }); @@ -150,17 +227,45 @@ fn main_0() -> i32 { (*index.borrow_mut()) = 0_u32; let __rhs = ({ match ({ 1_u32 }, { - let __tmp_17 = (slots[(*index.borrow()) as usize].value).clone(); - __tmp_17 + let __tmp_20 = (slots[(*index.borrow()) as usize].value).clone(); + __tmp_20 }) { - (__tmp_16, __tmp_17) => __tmp_17.with_mut(|__tmp_17| { - (*__tmp_17) = __tmp_16; - (*__tmp_17).clone() + (__tmp_19, __tmp_20) => __tmp_20.with_mut(|__tmp_20| { + (*__tmp_20) = __tmp_19; + (*__tmp_20).clone() }), } }); member = __rhs; printf!(b"%u %u %u\n", (*index.borrow()), (*other.borrow()), member); + let first: Value = Rc::new(RefCell::new(Index_8 { value: 0_u32 })); + let second: Value = Rc::new(RefCell::new(Index_8 { value: 77_u32 })); + let mut groups: [Group_9; 2] = [ + Group_9 { + ref_: first.as_pointer(), + }, + Group_9 { + ref_: second.as_pointer(), + }, + ]; + member = ({ + match ({ 1_u32 }, { + let __tmp_22 = + (field!(groups[({ (*first.borrow()).value }) as usize].ref_, value)).clone(); + __tmp_22 + }) { + (__tmp_21, __tmp_22) => __tmp_22.with_mut(|__tmp_22| { + (*__tmp_22) = (((*__tmp_22) as u32).wrapping_add((__tmp_21 as u32))) as u32; + (*__tmp_22).clone() + }), + } + }); + printf!( + b"%u %u %u\n", + { (*first.borrow()).value }, + { (*second.borrow()).value }, + member + ); let values: Value> = Rc::new(RefCell::new(Box::new([1, 2]))); let p: Value> = Rc::new(RefCell::new(values.decay().offset((1) as isize))); let mut j: i32 = 0; @@ -169,9 +274,9 @@ fn main_0() -> i32 { { 1 }, &((p.as_pointer()).offset((j.postfix_inc()) as isize)), ) { - (__tmp_18, __tmp_19) => __tmp_19.with_mut(|__tmp_19| { - (*__tmp_19) = (*__tmp_19).offset(-(__tmp_18 as isize)); - (*__tmp_19).clone() + (__tmp_23, __tmp_24) => __tmp_24.with_mut(|__tmp_24| { + (*__tmp_24) = (*__tmp_24).offset(-(__tmp_23 as isize)); + (*__tmp_24).clone() }), } }); @@ -197,8 +302,8 @@ fn main_0() -> i32 { { ({ (*mutate.borrow()).call() }).clone() }, &mut (*x.borrow_mut()), ) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = (((*__tmp_21) as u32).wrapping_add((__tmp_20 as u32))) as u32; + (__tmp_25, __tmp_26) => { + (*__tmp_26) = (((*__tmp_26) as u32).wrapping_add((__tmp_25 as u32))) as u32; } } }; @@ -218,19 +323,47 @@ fn main_0() -> i32 { { ({ (*change.borrow()).call() }).clone() }, &mut (*captured.borrow_mut()), ) { - (__tmp_22, __tmp_23) => { - (*__tmp_23) = (((*__tmp_23) as u32).wrapping_add((__tmp_22 as u32))) as u32; + (__tmp_27, __tmp_28) => { + (*__tmp_28) = (((*__tmp_28) as u32).wrapping_add((__tmp_27 as u32))) as u32; } } }; printf!(b"%u\n", (*captured.borrow())); + let outer: Value = Rc::new(RefCell::new(10_i16)); + let ptr: Value> = Rc::new(RefCell::new((outer.as_pointer()))); + let update: Value i16>> = Rc::new(RefCell::new(lambda!( + { + let outer: Ptr = outer.as_pointer(); + let ptr: Ptr> = ptr.as_pointer(); + }, + || -> i16 { + return ({ + match ( + { + { + (ptr.read()).write((-1_i32 as i16)); + 0.5_f64 + } + }, + &(outer), + ) { + (__tmp_29, __tmp_30) => __tmp_30.with_mut(|__tmp_30| { + (*__tmp_30) = (((*__tmp_30) as f64) + (__tmp_29 as f64)) as i16; + (*__tmp_30).clone() + }), + } + }); + } + ))); + let mut updated: i32 = (({ (*update.borrow()).call() }) as i32); + printf!(b"%d %d\n", updated, ((*outer.borrow()) as i32)); let mut flags: [bool; 1] = [false]; let mut i: i32 = 0; let mut result: bool = ({ match ({ 0.5_f64 }, &mut (flags[(i.postfix_inc()) as usize])) { - (__tmp_24, __tmp_25) => { - (*__tmp_25) = (((*__tmp_25) as u8 as f64) + (__tmp_24 as f64)) != 0.0; - (*__tmp_25).clone() + (__tmp_31, __tmp_32) => { + (*__tmp_32) = (((*__tmp_32) as u8 as f64) + (__tmp_31 as f64)) != 0.0; + (*__tmp_32).clone() } } }); @@ -243,39 +376,72 @@ fn main_0() -> i32 { let a: Value> = Rc::new(RefCell::new(Box::new([10_u32, 20_u32]))); let ref_: Ptr = a.decay(); i = 0; - let mut v: u32 = ({ - match ( - { 5_u32 }, - &(elem!( - { - i.prefix_inc(); - (ref_).clone() - }, - 0 - )), - ) { - (__tmp_26, __tmp_27) => __tmp_27.with_mut(|__tmp_27| { - (*__tmp_27) = (((*__tmp_27) as u32).wrapping_add((__tmp_26 as u32))) as u32; - (*__tmp_27).clone() - }), - } - }); + let v: Value = Rc::new(RefCell::new( + ({ + match ( + { 5_u32 }, + &(elem!( + { + i.prefix_inc(); + (ref_).clone() + }, + 0 + )), + ) { + (__tmp_33, __tmp_34) => __tmp_34.with_mut(|__tmp_34| { + (*__tmp_34) = (((*__tmp_34) as u32).wrapping_add((__tmp_33 as u32))) as u32; + (*__tmp_34).clone() + }), + } + }), + )); printf!( b"%d %u %u %u\n", i, - v, + (*v.borrow()), (*a.borrow())[(0) as usize], (*a.borrow())[(1) as usize] ); + let mut target: Ptr = (v.as_pointer()); + let mut comma: u32 = ({ + match ( + { 1_u32 }, + &({ + i.prefix_inc(); + (target).clone() + }), + ) { + (__tmp_35, __tmp_36) => __tmp_36.with_mut(|__tmp_36| { + (*__tmp_36) = (((*__tmp_36) as u32).wrapping_add((__tmp_35 as u32))) as u32; + (*__tmp_36).clone() + }), + } + }); + printf!(b"%d %u %u\n", i, comma, (target.read())); 0 } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(8)] -pub struct Slot_3 { +pub struct Slot_7 { #[offset(0)] #[byte_size(8)] pub value: Ptr, } +#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(4)] +pub struct Index_8 { + #[offset(0)] + pub value: u32, +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct Group_9 { + #[offset(0)] + #[byte_size(8)] + pub ref_: Ptr, +} pub fn __cpp2rust_init_globals() { let _ = rows_0.with(|_| ()); + let _ = global_1.with(|_| ()); + let _ = holder_3.with(|_| ()); } diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 82ab8c7ff0..870311631a 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -8,7 +8,22 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub static mut rows_0: std::cell::LazyCell<[[u32; 2]; 2]> = std::cell::LazyCell::new(|| unsafe { [[0_u32, 10_u32], [20_u32, 30_u32]] }); -pub unsafe fn test_1() { +pub static mut global_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10_u32 }); +pub unsafe fn mutate_global_2() -> u32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_1)) = 20_u32; + return 5_u32; +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Holder { + pub value: u32, +} +pub static mut holder_3: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { Holder { value: 10_u32 } }); +pub unsafe fn inspect_4(mut value: u32) -> u32 { + return (value).wrapping_add((*std::cell::LazyCell::force_mut(&mut *&raw mut holder_3)).value); +} +pub unsafe fn test_5() { let mut a: [u32; 4] = [10_u32, 20_u32, 30_u32, 40_u32]; let mut i: i32 = 0; match ({ 5_u32 }, &mut (a[(i.postfix_inc()) as usize])) { @@ -28,6 +43,24 @@ pub unsafe fn test_1() { (*__tmp_5).clone() } }); + let mut local: u32 = 10_u32; + let mut scalar: u32 = ({ + local = (local).wrapping_add(5_u32); + local + }); + let mut element: u32 = ({ + a[(0) as usize] = (a[(0) as usize]).wrapping_add(5_u32); + a[(0) as usize] + }); + (unsafe { + libc::printf( + c"%d %d %d %d\n".as_ptr() as *const libc::c_char, + (local as i32), + (scalar as i32), + (element as i32), + (a[(0) as usize] as i32), + ) + }); (unsafe { libc::printf( c"%d %d %d: %d %d %d %d\n".as_ptr() as *const libc::c_char, @@ -41,7 +74,7 @@ pub unsafe fn test_1() { ) }); } -pub unsafe fn test_2() { +pub unsafe fn test_6() { let mut a: [i16; 4] = [10_i16, 20_i16, 30_i16, 40_i16]; let mut i: i32 = 0; match ({ 5 }, &mut (a[(i.postfix_inc()) as usize])) { @@ -61,6 +94,24 @@ pub unsafe fn test_2() { (*__tmp_11).clone() } }); + let mut local: i16 = 10_i16; + let mut scalar: i16 = ({ + local = ((local as i32) + 5) as i16; + local + }); + let mut element: i16 = ({ + a[(0) as usize] = ((a[(0) as usize] as i32) + 5) as i16; + a[(0) as usize] + }); + (unsafe { + libc::printf( + c"%d %d %d %d\n".as_ptr() as *const libc::c_char, + (local as i32), + (scalar as i32), + (element as i32), + (a[(0) as usize] as i32), + ) + }); (unsafe { libc::printf( c"%d %d %d: %d %d %d %d\n".as_ptr() as *const libc::c_char, @@ -81,8 +132,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { test_1() }); - (unsafe { test_2() }); + (unsafe { test_5() }); + (unsafe { test_6() }); let mut row: i32 = 0; let mut nested: u32 = (match ( { 1_u32 }, @@ -95,6 +146,41 @@ unsafe fn main_0() -> i32 { (*__tmp_13).clone() } }); + let mut global_result: u32 = (match ( + { (unsafe { mutate_global_2() }) }, + &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_1)), + ) { + (__tmp_14, __tmp_15) => { + (*__tmp_15) = (((*__tmp_15) as u32).wrapping_add((__tmp_14 as u32))) as u32; + (*__tmp_15).clone() + } + }); + (unsafe { + libc::printf( + c"%u %u\n".as_ptr() as *const libc::c_char, + (global_result), + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_1)), + ) + }); + (unsafe { + libc::printf( + c"%u\n".as_ptr() as *const libc::c_char, + (unsafe { + inspect_4( + match ( + { (unsafe { mutate_global_2() }) }, + &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut holder_3)).value), + ) { + (__tmp_16, __tmp_17) => { + (*__tmp_17) = + (((*__tmp_17) as u32).wrapping_add((__tmp_16 as u32))) as u32; + (*__tmp_17).clone() + } + }, + ) + }), + ) + }); (unsafe { libc::printf( c"%d %u %u\n".as_ptr() as *const libc::c_char, @@ -105,11 +191,11 @@ unsafe fn main_0() -> i32 { }); let mut index: u32 = 0_u32; let mut other: u32 = 77_u32; - let mut slots: [Slot_3; 2] = [Slot_3 { value: &mut index }, Slot_3 { value: &mut other }]; + let mut slots: [Slot_7; 2] = [Slot_7 { value: &mut index }, Slot_7 { value: &mut other }]; let mut member: u32 = (match ({ 1_u32 }, &mut (*slots[(index) as usize].value)) { - (__tmp_14, __tmp_15) => { - (*__tmp_15) = (((*__tmp_15) as u32).wrapping_add((__tmp_14 as u32))) as u32; - (*__tmp_15).clone() + (__tmp_18, __tmp_19) => { + (*__tmp_19) = (((*__tmp_19) as u32).wrapping_add((__tmp_18 as u32))) as u32; + (*__tmp_19).clone() } }); (unsafe { @@ -122,9 +208,9 @@ unsafe fn main_0() -> i32 { }); index = 0_u32; member = (match ({ 1_u32 }, &mut (*slots[(index) as usize].value)) { - (__tmp_16, __tmp_17) => { - (*__tmp_17) = __tmp_16; - (*__tmp_17).clone() + (__tmp_20, __tmp_21) => { + (*__tmp_21) = __tmp_20; + (*__tmp_21).clone() } }); (unsafe { @@ -135,6 +221,26 @@ unsafe fn main_0() -> i32 { (member), ) }); + let mut first: Index_8 = Index_8 { value: 0_u32 }; + let mut second: Index_8 = Index_8 { value: 77_u32 }; + let mut groups: [Group_9; 2] = [Group_9 { ref_: &mut first }, Group_9 { ref_: &mut second }]; + member = (match ( + { 1_u32 }, + &mut ((*groups[(first.value) as usize].ref_).value), + ) { + (__tmp_22, __tmp_23) => { + (*__tmp_23) = (((*__tmp_23) as u32).wrapping_add((__tmp_22 as u32))) as u32; + (*__tmp_23).clone() + } + }); + (unsafe { + libc::printf( + c"%u %u %u\n".as_ptr() as *const libc::c_char, + (first.value), + (second.value), + (member), + ) + }); let mut values: [i32; 2] = [1, 2]; let mut p: *mut i32 = values.as_mut_ptr().offset((1) as isize); let mut j: i32 = 0; @@ -142,9 +248,9 @@ unsafe fn main_0() -> i32 { { 1 }, &mut (*((&mut p as *mut *mut i32).offset((j.postfix_inc()) as isize))), ) { - (__tmp_18, __tmp_19) => { - (*__tmp_19) = (*__tmp_19).offset(-(__tmp_18 as isize)); - (*__tmp_19).clone() + (__tmp_24, __tmp_25) => { + (*__tmp_25) = (*__tmp_25).offset(-(__tmp_24 as isize)); + (*__tmp_25).clone() } }); (unsafe { @@ -167,8 +273,8 @@ unsafe fn main_0() -> i32 { } ); match ({ (unsafe { mutate.call() }).clone() }, &mut (x)) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = (((*__tmp_21) as u32).wrapping_add((__tmp_20 as u32))) as u32; + (__tmp_26, __tmp_27) => { + (*__tmp_27) = (((*__tmp_27) as u32).wrapping_add((__tmp_26 as u32))) as u32; } }; (unsafe { libc::printf(c"%u\n".as_ptr() as *const libc::c_char, (x)) }); @@ -183,17 +289,49 @@ unsafe fn main_0() -> i32 { } ); match ({ (unsafe { change.call() }).clone() }, &mut (captured)) { - (__tmp_22, __tmp_23) => { - (*__tmp_23) = (((*__tmp_23) as u32).wrapping_add((__tmp_22 as u32))) as u32; + (__tmp_28, __tmp_29) => { + (*__tmp_29) = (((*__tmp_29) as u32).wrapping_add((__tmp_28 as u32))) as u32; } }; (unsafe { libc::printf(c"%u\n".as_ptr() as *const libc::c_char, (captured)) }); + let mut outer: i16 = 10_i16; + let mut ptr: *mut i16 = (&mut outer as *mut i16); + let mut update: FnPtr i16> = lambda_unsafe!( + { + let outer: *mut i16 = &mut outer; + let ptr: *mut *mut i16 = &mut ptr; + }, + || -> i16 { + return (match ( + { + { + (*(*ptr)) = (-1_i32 as i16); + 0.5_f64 + } + }, + &mut (*outer), + ) { + (__tmp_30, __tmp_31) => { + (*__tmp_31) = (((*__tmp_31) as f64) + (__tmp_30 as f64)) as i16; + (*__tmp_31).clone() + } + }); + } + ); + let mut updated: i32 = ((unsafe { update.call() }) as i32); + (unsafe { + libc::printf( + c"%d %d\n".as_ptr() as *const libc::c_char, + (updated), + (outer as i32), + ) + }); let mut flags: [bool; 1] = [false]; let mut i: i32 = 0; let mut result: bool = (match ({ 0.5_f64 }, &mut (flags[(i.postfix_inc()) as usize])) { - (__tmp_24, __tmp_25) => { - (*__tmp_25) = (((*__tmp_25) as u8 as f64) + (__tmp_24 as f64)) != 0.0; - (*__tmp_25).clone() + (__tmp_32, __tmp_33) => { + (*__tmp_33) = (((*__tmp_33) as u8 as f64) + (__tmp_32 as f64)) != 0.0; + (*__tmp_33).clone() } }); (unsafe { @@ -214,9 +352,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_26, __tmp_27) => { - (*__tmp_27) = (((*__tmp_27) as u32).wrapping_add((__tmp_26 as u32))) as u32; - (*__tmp_27).clone() + (__tmp_34, __tmp_35) => { + (*__tmp_35) = (((*__tmp_35) as u32).wrapping_add((__tmp_34 as u32))) as u32; + (*__tmp_35).clone() } }); (unsafe { @@ -228,13 +366,46 @@ unsafe fn main_0() -> i32 { (a[(1) as usize]), ) }); + let mut target: *mut u32 = (&mut v as *mut u32); + let mut comma: u32 = (match ( + { 1_u32 }, + &mut (*({ + i.prefix_inc(); + (target).clone() + })), + ) { + (__tmp_36, __tmp_37) => { + (*__tmp_37) = (((*__tmp_37) as u32).wrapping_add((__tmp_36 as u32))) as u32; + (*__tmp_37).clone() + } + }); + (unsafe { + libc::printf( + c"%d %u %u\n".as_ptr() as *const libc::c_char, + (i), + (comma), + (*target), + ) + }); 0 } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Slot_3 { +pub struct Slot_7 { pub value: *mut u32, } +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Index_8 { + pub value: u32, +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Group_9 { + pub ref_: *mut Index_8, +} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const rows_0); + std::cell::LazyCell::force(&*&raw const global_1); + std::cell::LazyCell::force(&*&raw const holder_3); } From d5d20f513c047519388e494385a775a2a777e175 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Mon, 30 Nov 2026 04:04:14 +0000 Subject: [PATCH 25/25] Keep temporary assignment targets alive through the full expression Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 3 + .../converter/models/converter_refcount.cpp | 2 + tests/unit/assignment_single_eval.cpp | 19 ++ .../out/refcount/assignment_single_eval.rs | 238 +++++++++++++----- .../unit/out/unsafe/assignment_single_eval.rs | 220 ++++++++++++---- 5 files changed, 372 insertions(+), 110 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 137e69f3f0..c2b30a763b 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -3038,6 +3038,7 @@ void Converter::ConvertAssignmentRef(clang::BinaryOperator *expr) { auto *lhs = expr->getLHS(); auto *rhs = expr->getRHS(); auto value = ConvertFreshRValue(rhs); + ScopedValue retain(retain_bound_temporaries_, true); std::string ptr; { PushExprKind push(*this, ExprKind::RValue); @@ -5415,6 +5416,8 @@ void Converter::ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, auto left = NewTempName(); auto rhs_value = ConvertFreshRValue( rhs, compound ? std::nullopt : std::optional(lhs->getType())); + // A returned reference or pointer can still depend on a temporary owner. + ScopedValue retain(retain_bound_temporaries_, true); auto lhs_value = ConvertLValue(lhs); auto read = std::format("(*{})", left); auto value = diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 31bc594ffe..a719f88698 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -2499,6 +2499,8 @@ void ConverterRefCount::ConvertAssignment( auto left = NewTempName(); auto rhs_value = ConvertFreshRValue( rhs, compound ? std::nullopt : std::optional(lhs->getType())); + // A returned reference or pointer can still depend on a temporary owner. + ScopedValue retain(retain_bound_temporaries_, true); std::string lhs_value; auto *base = lhs->IgnoreParenImpCasts(); while (auto *member = clang::dyn_cast(base)) { diff --git a/tests/unit/assignment_single_eval.cpp b/tests/unit/assignment_single_eval.cpp index 1df18fefa5..8c89e5e15f 100644 --- a/tests/unit/assignment_single_eval.cpp +++ b/tests/unit/assignment_single_eval.cpp @@ -1,4 +1,5 @@ #include +#include unsigned rows[2][2] = {{0, 10}, {20, 30}}; unsigned global = 10; @@ -11,6 +12,20 @@ struct Holder { } holder{10}; unsigned inspect(unsigned value) { return value + holder.value; } +unsigned selections; +struct Temp { + std::unique_ptr value = std::make_unique(10); + unsigned &get() { + ++selections; + return *value; + } + unsigned *data() { + ++selections; + return value.get(); + } +}; +int read(unsigned &value) { return value; } + template void test() { T a[] = {10, 20, 30, 40}; int i = 0; @@ -29,6 +44,10 @@ template void test() { int main() { test(); test(); + Temp{}.get() += 5; + unsigned temporary = (Temp{}.data()[0] += 5); + int read_result = read(Temp{}.get() = 99); + std::printf("%d %u %u\n", read_result, temporary, selections); int row = 0; unsigned nested = (rows[rows[row++][0]][0] += 1); unsigned global_result = (global += mutate_global()); diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 5a1d50a865..1fc093407d 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -31,7 +31,36 @@ thread_local!( pub fn inspect_4(mut value: u32) -> u32 { return (value).wrapping_add({ holder_3.with(|rc| *rc.borrow()).value }); } -pub fn test_5() { +thread_local!( + pub static selections_5: Value = Rc::new(RefCell::new(0_u32)); +); +#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, MoveAssign)] +#[byte_size(8)] +pub struct Temp { + #[offset(0)] + #[byte_size(8)] + pub value: Option>, +} +impl Temp { + pub fn move_from(_a0: Ptr) -> Self { + Self { + value: field!(_a0, value).with_mut(|__v: &mut Option>| __v.take()), + } + } +} +impl Default for Temp { + fn default() -> Self { + { + Temp { + value: Some(Rc::new(RefCell::new((10 as u32)))), + } + } + } +} +pub fn read_6(value: Ptr) -> i32 { + return ((value.read()) as i32); +} +pub fn test_7() { let mut a: [u32; 4] = [10_u32, 20_u32, 30_u32, 40_u32]; let mut i: i32 = 0; { @@ -84,7 +113,7 @@ pub fn test_5() { (a[(3) as usize] as i32) ); } -pub fn test_6() { +pub fn test_8() { let mut a: [i16; 4] = [10_i16, 20_i16, 30_i16, 40_i16]; let mut i: i32 = 0; { @@ -142,12 +171,79 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ test_5() }); - ({ test_6() }); + ({ test_7() }); + ({ test_8() }); + { + let __tmp_14: Value; + { + match ( + { 5_u32 }, + &({ + TempImpl::get(&{ + __tmp_14 = Rc::new(RefCell::new(::default())); + __tmp_14.as_pointer() + }) + }), + ) { + (__tmp_12, __tmp_13) => __tmp_13.with_mut(|__tmp_13| { + (*__tmp_13) = (((*__tmp_13) as u32).wrapping_add((__tmp_12 as u32))) as u32; + }), + } + } + }; + let mut temporary: u32 = { + let __tmp_17: Value; + ({ + match ( + { 5_u32 }, + &(elem!( + ({ + TempImpl::data(&{ + __tmp_17 = Rc::new(RefCell::new(::default())); + __tmp_17.as_pointer() + }) + }), + 0 + )), + ) { + (__tmp_15, __tmp_16) => __tmp_16.with_mut(|__tmp_16| { + (*__tmp_16) = (((*__tmp_16) as u32).wrapping_add((__tmp_15 as u32))) as u32; + (*__tmp_16).clone() + }), + } + }) + }; + let mut read_result: i32 = { + let __tmp_18: Value; + ({ + read_6( + match ( + { 99_u32 }, + ({ + TempImpl::get(&{ + __tmp_18 = Rc::new(RefCell::new(::default())); + __tmp_18.as_pointer() + }) + }), + ) { + (__tmp_20, __tmp_19) => { + __tmp_19.write(__tmp_20); + __tmp_19 + } + }, + ) + }) + }; + printf!( + b"%d %u %u\n", + read_result, + temporary, + selections_5.with(|rc| *rc.borrow()) + ); let mut row: i32 = 0; let mut nested: u32 = ({ match ({ 1_u32 }, { - let __tmp_13 = rows_0 + let __tmp_22 = rows_0 .with(|v| v.decay()) .offset( ({ @@ -158,19 +254,19 @@ fn main_0() -> i32 { ) .decay() .offset(0); - __tmp_13 + __tmp_22 }) { - (__tmp_12, __tmp_13) => __tmp_13.with_mut(|__tmp_13| { - (*__tmp_13) = (((*__tmp_13) as u32).wrapping_add((__tmp_12 as u32))) as u32; - (*__tmp_13).clone() + (__tmp_21, __tmp_22) => __tmp_22.with_mut(|__tmp_22| { + (*__tmp_22) = (((*__tmp_22) as u32).wrapping_add((__tmp_21 as u32))) as u32; + (*__tmp_22).clone() }), } }); let mut global_result: u32 = ({ - let __tmp_14 = ({ mutate_global_2() }); + let __tmp_23 = ({ mutate_global_2() }); { let rhs_0 = - ((global_1.with(|rc| *rc.borrow()) as u32).wrapping_add((__tmp_14 as u32))) as u32; + ((global_1.with(|rc| *rc.borrow()) as u32).wrapping_add((__tmp_23 as u32))) as u32; global_1.with(|rc| *rc.borrow_mut() = rhs_0); global_1.with(|rc| *rc.borrow()) } @@ -184,9 +280,9 @@ fn main_0() -> i32 { { ({ mutate_global_2() }) }, &mut ((*holder_3.with(Value::clone).borrow_mut()).value), ) { - (__tmp_15, __tmp_16) => { - (*__tmp_16) = (((*__tmp_16) as u32).wrapping_add((__tmp_15 as u32))) as u32; - (*__tmp_16).clone() + (__tmp_24, __tmp_25) => { + (*__tmp_25) = (((*__tmp_25) as u32).wrapping_add((__tmp_24 as u32))) as u32; + (*__tmp_25).clone() } } }) @@ -204,22 +300,22 @@ fn main_0() -> i32 { ); let index: Value = Rc::new(RefCell::new(0_u32)); let other: Value = Rc::new(RefCell::new(77_u32)); - let mut slots: [Slot_7; 2] = [ - Slot_7 { + let mut slots: [Slot_9; 2] = [ + Slot_9 { value: index.as_pointer(), }, - Slot_7 { + Slot_9 { value: other.as_pointer(), }, ]; let mut member: u32 = ({ match ({ 1_u32 }, { - let __tmp_18 = (slots[(*index.borrow()) as usize].value).clone(); - __tmp_18 + let __tmp_27 = (slots[(*index.borrow()) as usize].value).clone(); + __tmp_27 }) { - (__tmp_17, __tmp_18) => __tmp_18.with_mut(|__tmp_18| { - (*__tmp_18) = (((*__tmp_18) as u32).wrapping_add((__tmp_17 as u32))) as u32; - (*__tmp_18).clone() + (__tmp_26, __tmp_27) => __tmp_27.with_mut(|__tmp_27| { + (*__tmp_27) = (((*__tmp_27) as u32).wrapping_add((__tmp_26 as u32))) as u32; + (*__tmp_27).clone() }), } }); @@ -227,36 +323,36 @@ fn main_0() -> i32 { (*index.borrow_mut()) = 0_u32; let __rhs = ({ match ({ 1_u32 }, { - let __tmp_20 = (slots[(*index.borrow()) as usize].value).clone(); - __tmp_20 + let __tmp_29 = (slots[(*index.borrow()) as usize].value).clone(); + __tmp_29 }) { - (__tmp_19, __tmp_20) => __tmp_20.with_mut(|__tmp_20| { - (*__tmp_20) = __tmp_19; - (*__tmp_20).clone() + (__tmp_28, __tmp_29) => __tmp_29.with_mut(|__tmp_29| { + (*__tmp_29) = __tmp_28; + (*__tmp_29).clone() }), } }); member = __rhs; printf!(b"%u %u %u\n", (*index.borrow()), (*other.borrow()), member); - let first: Value = Rc::new(RefCell::new(Index_8 { value: 0_u32 })); - let second: Value = Rc::new(RefCell::new(Index_8 { value: 77_u32 })); - let mut groups: [Group_9; 2] = [ - Group_9 { + let first: Value = Rc::new(RefCell::new(Index_10 { value: 0_u32 })); + let second: Value = Rc::new(RefCell::new(Index_10 { value: 77_u32 })); + let mut groups: [Group_11; 2] = [ + Group_11 { ref_: first.as_pointer(), }, - Group_9 { + Group_11 { ref_: second.as_pointer(), }, ]; member = ({ match ({ 1_u32 }, { - let __tmp_22 = + let __tmp_31 = (field!(groups[({ (*first.borrow()).value }) as usize].ref_, value)).clone(); - __tmp_22 + __tmp_31 }) { - (__tmp_21, __tmp_22) => __tmp_22.with_mut(|__tmp_22| { - (*__tmp_22) = (((*__tmp_22) as u32).wrapping_add((__tmp_21 as u32))) as u32; - (*__tmp_22).clone() + (__tmp_30, __tmp_31) => __tmp_31.with_mut(|__tmp_31| { + (*__tmp_31) = (((*__tmp_31) as u32).wrapping_add((__tmp_30 as u32))) as u32; + (*__tmp_31).clone() }), } }); @@ -274,9 +370,9 @@ fn main_0() -> i32 { { 1 }, &((p.as_pointer()).offset((j.postfix_inc()) as isize)), ) { - (__tmp_23, __tmp_24) => __tmp_24.with_mut(|__tmp_24| { - (*__tmp_24) = (*__tmp_24).offset(-(__tmp_23 as isize)); - (*__tmp_24).clone() + (__tmp_32, __tmp_33) => __tmp_33.with_mut(|__tmp_33| { + (*__tmp_33) = (*__tmp_33).offset(-(__tmp_32 as isize)); + (*__tmp_33).clone() }), } }); @@ -302,8 +398,8 @@ fn main_0() -> i32 { { ({ (*mutate.borrow()).call() }).clone() }, &mut (*x.borrow_mut()), ) { - (__tmp_25, __tmp_26) => { - (*__tmp_26) = (((*__tmp_26) as u32).wrapping_add((__tmp_25 as u32))) as u32; + (__tmp_34, __tmp_35) => { + (*__tmp_35) = (((*__tmp_35) as u32).wrapping_add((__tmp_34 as u32))) as u32; } } }; @@ -323,8 +419,8 @@ fn main_0() -> i32 { { ({ (*change.borrow()).call() }).clone() }, &mut (*captured.borrow_mut()), ) { - (__tmp_27, __tmp_28) => { - (*__tmp_28) = (((*__tmp_28) as u32).wrapping_add((__tmp_27 as u32))) as u32; + (__tmp_36, __tmp_37) => { + (*__tmp_37) = (((*__tmp_37) as u32).wrapping_add((__tmp_36 as u32))) as u32; } } }; @@ -347,9 +443,9 @@ fn main_0() -> i32 { }, &(outer), ) { - (__tmp_29, __tmp_30) => __tmp_30.with_mut(|__tmp_30| { - (*__tmp_30) = (((*__tmp_30) as f64) + (__tmp_29 as f64)) as i16; - (*__tmp_30).clone() + (__tmp_38, __tmp_39) => __tmp_39.with_mut(|__tmp_39| { + (*__tmp_39) = (((*__tmp_39) as f64) + (__tmp_38 as f64)) as i16; + (*__tmp_39).clone() }), } }); @@ -361,9 +457,9 @@ fn main_0() -> i32 { let mut i: i32 = 0; let mut result: bool = ({ match ({ 0.5_f64 }, &mut (flags[(i.postfix_inc()) as usize])) { - (__tmp_31, __tmp_32) => { - (*__tmp_32) = (((*__tmp_32) as u8 as f64) + (__tmp_31 as f64)) != 0.0; - (*__tmp_32).clone() + (__tmp_40, __tmp_41) => { + (*__tmp_41) = (((*__tmp_41) as u8 as f64) + (__tmp_40 as f64)) != 0.0; + (*__tmp_41).clone() } } }); @@ -388,9 +484,9 @@ fn main_0() -> i32 { 0 )), ) { - (__tmp_33, __tmp_34) => __tmp_34.with_mut(|__tmp_34| { - (*__tmp_34) = (((*__tmp_34) as u32).wrapping_add((__tmp_33 as u32))) as u32; - (*__tmp_34).clone() + (__tmp_42, __tmp_43) => __tmp_43.with_mut(|__tmp_43| { + (*__tmp_43) = (((*__tmp_43) as u32).wrapping_add((__tmp_42 as u32))) as u32; + (*__tmp_43).clone() }), } }), @@ -411,9 +507,9 @@ fn main_0() -> i32 { (target).clone() }), ) { - (__tmp_35, __tmp_36) => __tmp_36.with_mut(|__tmp_36| { - (*__tmp_36) = (((*__tmp_36) as u32).wrapping_add((__tmp_35 as u32))) as u32; - (*__tmp_36).clone() + (__tmp_44, __tmp_45) => __tmp_45.with_mut(|__tmp_45| { + (*__tmp_45) = (((*__tmp_45) as u32).wrapping_add((__tmp_44 as u32))) as u32; + (*__tmp_45).clone() }), } }); @@ -422,26 +518,48 @@ fn main_0() -> i32 { } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(8)] -pub struct Slot_7 { +pub struct Slot_9 { #[offset(0)] #[byte_size(8)] pub value: Ptr, } #[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(4)] -pub struct Index_8 { +pub struct Index_10 { #[offset(0)] pub value: u32, } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(8)] -pub struct Group_9 { +pub struct Group_11 { #[offset(0)] #[byte_size(8)] - pub ref_: Ptr, + pub ref_: Ptr, +} +pub trait TempImpl { + fn get(&self) -> Ptr; + fn data(&self) -> Ptr; + fn move_assign(&self, _a0: Ptr) -> Ptr; +} +impl TempImpl for Ptr { + fn get(&self) -> Ptr { + (*selections_5.with(Value::clone).borrow_mut()).prefix_inc(); + return (*self).with(|__s| __s.value.clone()).as_pointer(); + } + fn data(&self) -> Ptr { + (*selections_5.with(Value::clone).borrow_mut()).prefix_inc(); + return (*self).with(|__s| __s.value.clone()).as_pointer(); + } + fn move_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), value).with_mut(|__b0| { + (*__b0) = field!(_a0, value).with_mut(|__v: &mut Option>| __v.take()); + }); + return (*self).clone(); + } } pub fn __cpp2rust_init_globals() { let _ = rows_0.with(|_| ()); let _ = global_1.with(|_| ()); let _ = holder_3.with(|_| ()); + let _ = selections_5.with(|_| ()); } diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 870311631a..7abbff52c6 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -23,7 +23,54 @@ pub static mut holder_3: std::cell::LazyCell = pub unsafe fn inspect_4(mut value: u32) -> u32 { return (value).wrapping_add((*std::cell::LazyCell::force_mut(&mut *&raw mut holder_3)).value); } -pub unsafe fn test_5() { +pub static mut selections_5: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_u32 }); +#[repr(C)] +#[derive(FnPtrArg, MoveCtorUnsafe, MoveAssignUnsafe)] +pub struct Temp { + pub value: Option>, +} +impl Temp { + pub unsafe fn get(&mut self) -> *mut u32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut selections_5)).prefix_inc(); + return &mut (*self + .value + .as_deref() + .map_or(::std::ptr::null_mut(), |v| v as *const u32 as *mut u32)); + } + pub unsafe fn data(&mut self) -> *mut u32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut selections_5)).prefix_inc(); + return self + .value + .as_deref_mut() + .map_or(::std::ptr::null_mut(), |v| v as *mut u32); + } + pub unsafe fn move_from(_a0: *mut Temp) -> Self { + let mut this = Self { + value: (*_a0).value.take(), + }; + this + } + pub unsafe fn move_assign(&mut self, _a0: *mut Temp) -> *mut Temp { + { + self.value = (*_a0).value.take(); + }; + return &mut (*(self as *mut Temp)); + } +} +impl Default for Temp { + fn default() -> Self { + unsafe { + Temp { + value: Some(Box::new((10 as u32))), + } + } + } +} +pub unsafe fn read_6(value: *mut u32) -> i32 { + return ((*value) as i32); +} +pub unsafe fn test_7() { let mut a: [u32; 4] = [10_u32, 20_u32, 30_u32, 40_u32]; let mut i: i32 = 0; match ({ 5_u32 }, &mut (a[(i.postfix_inc()) as usize])) { @@ -74,7 +121,7 @@ pub unsafe fn test_5() { ) }); } -pub unsafe fn test_6() { +pub unsafe fn test_8() { let mut a: [i16; 4] = [10_i16, 20_i16, 30_i16, 40_i16]; let mut i: i32 = 0; match ({ 5 }, &mut (a[(i.postfix_inc()) as usize])) { @@ -132,8 +179,77 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { test_5() }); - (unsafe { test_6() }); + (unsafe { test_7() }); + (unsafe { test_8() }); + { + let mut __tmp_14: Temp; + match ( + { 5_u32 }, + &mut (*(unsafe { + Temp::get( + &mut (*{ + __tmp_14 = ::default(); + &mut __tmp_14 + }), + ) + })), + ) { + (__tmp_12, __tmp_13) => { + (*__tmp_13) = (((*__tmp_13) as u32).wrapping_add((__tmp_12 as u32))) as u32; + } + } + }; + let mut temporary: u32 = { + let mut __tmp_17: Temp; + (match ( + { 5_u32 }, + &mut (*(unsafe { + Temp::data( + &mut (*{ + __tmp_17 = ::default(); + &mut __tmp_17 + }), + ) + }) + .offset((0) as isize)), + ) { + (__tmp_15, __tmp_16) => { + (*__tmp_16) = (((*__tmp_16) as u32).wrapping_add((__tmp_15 as u32))) as u32; + (*__tmp_16).clone() + } + }) + }; + let mut read_result: i32 = { + let mut __tmp_18: Temp; + (unsafe { + read_6( + match ( + { 99_u32 }, + ((unsafe { + Temp::get( + &mut (*{ + __tmp_18 = ::default(); + &mut __tmp_18 + }), + ) + }) as *mut u32), + ) { + (__tmp_20, __tmp_19) => { + __tmp_19.write(__tmp_20); + __tmp_19 + } + }, + ) + }) + }; + (unsafe { + libc::printf( + c"%d %u %u\n".as_ptr() as *const libc::c_char, + (read_result), + (temporary), + (*std::cell::LazyCell::force_mut(&mut *&raw mut selections_5)), + ) + }); let mut row: i32 = 0; let mut nested: u32 = (match ( { 1_u32 }, @@ -141,18 +257,18 @@ unsafe fn main_0() -> i32 { [((*std::cell::LazyCell::force_mut(&mut *&raw mut rows_0)) [(row.postfix_inc()) as usize][(0) as usize]) as usize][(0) as usize]), ) { - (__tmp_12, __tmp_13) => { - (*__tmp_13) = (((*__tmp_13) as u32).wrapping_add((__tmp_12 as u32))) as u32; - (*__tmp_13).clone() + (__tmp_21, __tmp_22) => { + (*__tmp_22) = (((*__tmp_22) as u32).wrapping_add((__tmp_21 as u32))) as u32; + (*__tmp_22).clone() } }); let mut global_result: u32 = (match ( { (unsafe { mutate_global_2() }) }, &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_1)), ) { - (__tmp_14, __tmp_15) => { - (*__tmp_15) = (((*__tmp_15) as u32).wrapping_add((__tmp_14 as u32))) as u32; - (*__tmp_15).clone() + (__tmp_23, __tmp_24) => { + (*__tmp_24) = (((*__tmp_24) as u32).wrapping_add((__tmp_23 as u32))) as u32; + (*__tmp_24).clone() } }); (unsafe { @@ -171,10 +287,10 @@ unsafe fn main_0() -> i32 { { (unsafe { mutate_global_2() }) }, &mut ((*std::cell::LazyCell::force_mut(&mut *&raw mut holder_3)).value), ) { - (__tmp_16, __tmp_17) => { - (*__tmp_17) = - (((*__tmp_17) as u32).wrapping_add((__tmp_16 as u32))) as u32; - (*__tmp_17).clone() + (__tmp_25, __tmp_26) => { + (*__tmp_26) = + (((*__tmp_26) as u32).wrapping_add((__tmp_25 as u32))) as u32; + (*__tmp_26).clone() } }, ) @@ -191,11 +307,11 @@ unsafe fn main_0() -> i32 { }); let mut index: u32 = 0_u32; let mut other: u32 = 77_u32; - let mut slots: [Slot_7; 2] = [Slot_7 { value: &mut index }, Slot_7 { value: &mut other }]; + let mut slots: [Slot_9; 2] = [Slot_9 { value: &mut index }, Slot_9 { value: &mut other }]; let mut member: u32 = (match ({ 1_u32 }, &mut (*slots[(index) as usize].value)) { - (__tmp_18, __tmp_19) => { - (*__tmp_19) = (((*__tmp_19) as u32).wrapping_add((__tmp_18 as u32))) as u32; - (*__tmp_19).clone() + (__tmp_27, __tmp_28) => { + (*__tmp_28) = (((*__tmp_28) as u32).wrapping_add((__tmp_27 as u32))) as u32; + (*__tmp_28).clone() } }); (unsafe { @@ -208,9 +324,9 @@ unsafe fn main_0() -> i32 { }); index = 0_u32; member = (match ({ 1_u32 }, &mut (*slots[(index) as usize].value)) { - (__tmp_20, __tmp_21) => { - (*__tmp_21) = __tmp_20; - (*__tmp_21).clone() + (__tmp_29, __tmp_30) => { + (*__tmp_30) = __tmp_29; + (*__tmp_30).clone() } }); (unsafe { @@ -221,16 +337,19 @@ unsafe fn main_0() -> i32 { (member), ) }); - let mut first: Index_8 = Index_8 { value: 0_u32 }; - let mut second: Index_8 = Index_8 { value: 77_u32 }; - let mut groups: [Group_9; 2] = [Group_9 { ref_: &mut first }, Group_9 { ref_: &mut second }]; + let mut first: Index_10 = Index_10 { value: 0_u32 }; + let mut second: Index_10 = Index_10 { value: 77_u32 }; + let mut groups: [Group_11; 2] = [ + Group_11 { ref_: &mut first }, + Group_11 { ref_: &mut second }, + ]; member = (match ( { 1_u32 }, &mut ((*groups[(first.value) as usize].ref_).value), ) { - (__tmp_22, __tmp_23) => { - (*__tmp_23) = (((*__tmp_23) as u32).wrapping_add((__tmp_22 as u32))) as u32; - (*__tmp_23).clone() + (__tmp_31, __tmp_32) => { + (*__tmp_32) = (((*__tmp_32) as u32).wrapping_add((__tmp_31 as u32))) as u32; + (*__tmp_32).clone() } }); (unsafe { @@ -248,9 +367,9 @@ unsafe fn main_0() -> i32 { { 1 }, &mut (*((&mut p as *mut *mut i32).offset((j.postfix_inc()) as isize))), ) { - (__tmp_24, __tmp_25) => { - (*__tmp_25) = (*__tmp_25).offset(-(__tmp_24 as isize)); - (*__tmp_25).clone() + (__tmp_33, __tmp_34) => { + (*__tmp_34) = (*__tmp_34).offset(-(__tmp_33 as isize)); + (*__tmp_34).clone() } }); (unsafe { @@ -273,8 +392,8 @@ unsafe fn main_0() -> i32 { } ); match ({ (unsafe { mutate.call() }).clone() }, &mut (x)) { - (__tmp_26, __tmp_27) => { - (*__tmp_27) = (((*__tmp_27) as u32).wrapping_add((__tmp_26 as u32))) as u32; + (__tmp_35, __tmp_36) => { + (*__tmp_36) = (((*__tmp_36) as u32).wrapping_add((__tmp_35 as u32))) as u32; } }; (unsafe { libc::printf(c"%u\n".as_ptr() as *const libc::c_char, (x)) }); @@ -289,8 +408,8 @@ unsafe fn main_0() -> i32 { } ); match ({ (unsafe { change.call() }).clone() }, &mut (captured)) { - (__tmp_28, __tmp_29) => { - (*__tmp_29) = (((*__tmp_29) as u32).wrapping_add((__tmp_28 as u32))) as u32; + (__tmp_37, __tmp_38) => { + (*__tmp_38) = (((*__tmp_38) as u32).wrapping_add((__tmp_37 as u32))) as u32; } }; (unsafe { libc::printf(c"%u\n".as_ptr() as *const libc::c_char, (captured)) }); @@ -311,9 +430,9 @@ unsafe fn main_0() -> i32 { }, &mut (*outer), ) { - (__tmp_30, __tmp_31) => { - (*__tmp_31) = (((*__tmp_31) as f64) + (__tmp_30 as f64)) as i16; - (*__tmp_31).clone() + (__tmp_39, __tmp_40) => { + (*__tmp_40) = (((*__tmp_40) as f64) + (__tmp_39 as f64)) as i16; + (*__tmp_40).clone() } }); } @@ -329,9 +448,9 @@ unsafe fn main_0() -> i32 { let mut flags: [bool; 1] = [false]; let mut i: i32 = 0; let mut result: bool = (match ({ 0.5_f64 }, &mut (flags[(i.postfix_inc()) as usize])) { - (__tmp_32, __tmp_33) => { - (*__tmp_33) = (((*__tmp_33) as u8 as f64) + (__tmp_32 as f64)) != 0.0; - (*__tmp_33).clone() + (__tmp_41, __tmp_42) => { + (*__tmp_42) = (((*__tmp_42) as u8 as f64) + (__tmp_41 as f64)) != 0.0; + (*__tmp_42).clone() } }); (unsafe { @@ -352,9 +471,9 @@ unsafe fn main_0() -> i32 { (ref_).clone() }))[(0) as usize]), ) { - (__tmp_34, __tmp_35) => { - (*__tmp_35) = (((*__tmp_35) as u32).wrapping_add((__tmp_34 as u32))) as u32; - (*__tmp_35).clone() + (__tmp_43, __tmp_44) => { + (*__tmp_44) = (((*__tmp_44) as u32).wrapping_add((__tmp_43 as u32))) as u32; + (*__tmp_44).clone() } }); (unsafe { @@ -374,9 +493,9 @@ unsafe fn main_0() -> i32 { (target).clone() })), ) { - (__tmp_36, __tmp_37) => { - (*__tmp_37) = (((*__tmp_37) as u32).wrapping_add((__tmp_36 as u32))) as u32; - (*__tmp_37).clone() + (__tmp_45, __tmp_46) => { + (*__tmp_46) = (((*__tmp_46) as u32).wrapping_add((__tmp_45 as u32))) as u32; + (*__tmp_46).clone() } }); (unsafe { @@ -391,21 +510,22 @@ unsafe fn main_0() -> i32 { } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Slot_7 { +pub struct Slot_9 { pub value: *mut u32, } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Index_8 { +pub struct Index_10 { pub value: u32, } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct Group_9 { - pub ref_: *mut Index_8, +pub struct Group_11 { + pub ref_: *mut Index_10, } pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const rows_0); std::cell::LazyCell::force(&*&raw const global_1); std::cell::LazyCell::force(&*&raw const holder_3); + std::cell::LazyCell::force(&*&raw const selections_5); }