diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 502ab0a..ea07e74 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -1742,24 +1742,12 @@ void Converter::ConvertIntegralToBooleanCast(clang::ImplicitCastExpr *expr) { auto *stripped = sub_expr->IgnoreParenImpCasts(); if (auto binop = clang::dyn_cast(stripped)) { - // Comparison already produces bool, no wrap needed. - if (binop->isComparisonOp()) { + // Comparisons and logical ops already produces bool, no wrap needed. + if ((binop->isComparisonOp() || binop->isLogicalOp()) && + binop->getType()->isBooleanType()) { Convert(sub_expr); return; } - // Distribute bool conversion to each argument of the logical op. - if (binop->isLogicalOp()) { - { - PushParen paren(*this); - ConvertCondition(binop->getLHS()); - } - StrCat(binop->getOpcodeStr()); - { - PushParen paren(*this); - ConvertCondition(binop->getRHS()); - } - return; - } } PushParen paren(*this); @@ -1945,6 +1933,21 @@ bool Converter::VisitExplicitCastExpr(clang::ExplicitCastExpr *expr) { } bool Converter::VisitBinaryOperator(clang::BinaryOperator *expr) { + bool needs_cast = (expr->isComparisonOp() || expr->isLogicalOp()) && + expr->getType()->isIntegerType() && + !expr->getType()->isBooleanType(); + PushParen outer(*this, needs_cast); + { + PushParen inner(*this, needs_cast); + ConvertBinaryOperator(expr); + } + if (needs_cast) { + ConvertCast(expr->getType()); + } + return false; +} + +void Converter::ConvertBinaryOperator(clang::BinaryOperator *expr) { auto type = expr->getType(); auto *lhs = expr->getLHS(); auto *rhs = expr->getRHS(); @@ -2048,10 +2051,19 @@ bool Converter::VisitBinaryOperator(clang::BinaryOperator *expr) { } ConvertCast(expr->getType()); computed_expr_type_ = ComputedExprType::FreshValue; + } else if (expr->isLogicalOp()) { + { + PushParen paren(*this); + ConvertCondition(expr->getLHS()); + } + StrCat(expr->getOpcodeStr()); + { + PushParen paren(*this); + ConvertCondition(expr->getRHS()); + } } else { ConvertGenericBinaryOperator(expr); } - return false; } void Converter::ConvertGenericBinaryOperator(clang::BinaryOperator *expr) { @@ -2063,8 +2075,10 @@ void Converter::ConvertGenericBinaryOperator(clang::BinaryOperator *expr) { StrCat(expr->getOpcodeStr()); - PushParen rhs_paren(*this); - Convert(expr->getRHS()); + { + PushParen rhs_paren(*this); + Convert(expr->getRHS()); + } } bool Converter::IsReferenceType(const clang::Expr *expr) const { diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index c44e2e6..0719c0b 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -252,6 +252,8 @@ class Converter : public clang::RecursiveASTVisitor { virtual bool VisitBinaryOperator(clang::BinaryOperator *expr); + virtual void ConvertBinaryOperator(clang::BinaryOperator *expr); + virtual bool ConvertIncAndDec(clang::UnaryOperator *expr); virtual bool VisitUnaryOperator(clang::UnaryOperator *expr); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 9b3c310..44eb4cc 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -1191,7 +1191,7 @@ void ConverterRefCount::EmitStmtExprTail(clang::Expr *tail) { StrCat("__result"); } -bool ConverterRefCount::VisitBinaryOperator(clang::BinaryOperator *expr) { +void ConverterRefCount::ConvertBinaryOperator(clang::BinaryOperator *expr) { auto *lhs = expr->getLHS(); auto *rhs = expr->getRHS(); auto lhs_type = lhs->getType(); @@ -1229,7 +1229,7 @@ bool ConverterRefCount::VisitBinaryOperator(clang::BinaryOperator *expr) { } StrCat(token::kSemiColon); EmitSetOrAssign(lhs, "rhs_0"); - return false; + return; } if (IsUnsignedArithOp(expr)) { @@ -1249,7 +1249,7 @@ bool ConverterRefCount::VisitBinaryOperator(clang::BinaryOperator *expr) { StrCat(token::kSemiColon); EmitSetOrAssign(lhs, "rhs_0"); } - return false; + return; } // pointer subtraction. The Sub trait gets elements by Value, so we need @@ -1263,15 +1263,15 @@ bool ConverterRefCount::VisitBinaryOperator(clang::BinaryOperator *expr) { } ConvertCast(expr->getType()); computed_expr_type_ = ComputedExprType::FreshValue; - return false; + return; } if (expr->isAssignmentOp()) { ConvertAssignment(lhs, rhs, opcode_as_string); - return false; + return; } - return Converter::VisitBinaryOperator(expr); + Converter::ConvertBinaryOperator(expr); } bool ConverterRefCount::VisitInitListExpr(clang::InitListExpr *expr) { @@ -1840,7 +1840,7 @@ void ConverterRefCount::ConvertGenericBinaryOperator( return; } - PushParen paren(*this); + PushParen outer(*this); Convert(lhs); StrCat(opcode); Convert(rhs); diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 4389470..c1fd32a 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -82,7 +82,7 @@ class ConverterRefCount final : public Converter { bool VisitExplicitCastExpr(clang::ExplicitCastExpr *expr) override; - bool VisitBinaryOperator(clang::BinaryOperator *expr) override; + void ConvertBinaryOperator(clang::BinaryOperator *expr) override; bool VisitStmtExpr(clang::StmtExpr *expr) override; diff --git a/tests/benchmarks/out/refcount/bst.rs b/tests/benchmarks/out/refcount/bst.rs index bdcd047..060816c 100644 --- a/tests/benchmarks/out/refcount/bst.rs +++ b/tests/benchmarks/out/refcount/bst.rs @@ -26,25 +26,21 @@ impl ByteRepr for node_t {} pub fn find_0(node: Ptr, value: i32) -> Ptr { let node: Value> = Rc::new(RefCell::new(node)); let value: Value = Rc::new(RefCell::new(value)); - if { - let _lhs = { - let _lhs = (*value.borrow()); - _lhs < (*(*(*node.borrow()).upgrade().deref()).value.borrow()) - }; - _lhs && (!((*(*(*node.borrow()).upgrade().deref()).left.borrow()).is_null())).clone() - } { + if ({ + let _lhs = (*value.borrow()); + _lhs < (*(*(*node.borrow()).upgrade().deref()).value.borrow()) + }) && (!((*(*(*node.borrow()).upgrade().deref()).left.borrow()).is_null())) + { return ({ let _node: Ptr = (*(*(*node.borrow()).upgrade().deref()).left.borrow()).clone(); let _value: i32 = (*value.borrow()); find_0(_node, _value) }); - } else if { - let _lhs = { - let _lhs = (*value.borrow()); - _lhs > (*(*(*node.borrow()).upgrade().deref()).value.borrow()) - }; - _lhs && (!((*(*(*node.borrow()).upgrade().deref()).right.borrow()).is_null())).clone() - } { + } else if ({ + let _lhs = (*value.borrow()); + _lhs > (*(*(*node.borrow()).upgrade().deref()).value.borrow()) + }) && (!((*(*(*node.borrow()).upgrade().deref()).right.borrow()).is_null())) + { return ({ let _node: Ptr = (*(*(*node.borrow()).upgrade().deref()).right.borrow()).clone(); diff --git a/tests/benchmarks/out/refcount/fibonacci.rs b/tests/benchmarks/out/refcount/fibonacci.rs index 1fd97c8..4cbde37 100644 --- a/tests/benchmarks/out/refcount/fibonacci.rs +++ b/tests/benchmarks/out/refcount/fibonacci.rs @@ -8,7 +8,7 @@ use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn fib_0(n: u64) -> u64 { let n: Value = Rc::new(RefCell::new(n)); - return if (((*n.borrow()) == 0_u64) || ((*n.borrow()) == 1_u64)) { + return if ((*n.borrow()) == 0_u64) || ((*n.borrow()) == 1_u64) { (*n.borrow()) } else { ({ diff --git a/tests/benchmarks/out/refcount/ptr_fibonacci.rs b/tests/benchmarks/out/refcount/ptr_fibonacci.rs index e42fbb5..b6a3679 100644 --- a/tests/benchmarks/out/refcount/ptr_fibonacci.rs +++ b/tests/benchmarks/out/refcount/ptr_fibonacci.rs @@ -8,7 +8,7 @@ use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn fib_0(n: Ptr) { let n: Value> = Rc::new(RefCell::new(n)); - if ((((*n.borrow()).read()) == 0_u64) || (((*n.borrow()).read()) == 1_u64)) { + if (((*n.borrow()).read()) == 0_u64) || (((*n.borrow()).read()) == 1_u64) { return; } let n_1: Value = Rc::new(RefCell::new(((*n.borrow()).read()).wrapping_sub(1_u64))); diff --git a/tests/benchmarks/out/refcount/ref_fibonacci.rs b/tests/benchmarks/out/refcount/ref_fibonacci.rs index 9b261f4..4abedbf 100644 --- a/tests/benchmarks/out/refcount/ref_fibonacci.rs +++ b/tests/benchmarks/out/refcount/ref_fibonacci.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn fib_0(n: Ptr) { - if (((n.read()) == 0_u64) || ((n.read()) == 1_u64)) { + if ((n.read()) == 0_u64) || ((n.read()) == 1_u64) { return; } let n_1: Value = Rc::new(RefCell::new((n.read()).wrapping_sub(1_u64))); diff --git a/tests/benchmarks/out/unsafe/bst.rs b/tests/benchmarks/out/unsafe/bst.rs index 769f040..459c776 100644 --- a/tests/benchmarks/out/unsafe/bst.rs +++ b/tests/benchmarks/out/unsafe/bst.rs @@ -14,13 +14,13 @@ pub struct node_t { pub value: i32, } pub unsafe fn find_0(mut node: *mut node_t, mut value: i32) -> *mut node_t { - if (((value) < ((*node).value)) && (!(((*node).left).is_null()))) { + if ((value) < ((*node).value)) && (!(((*node).left).is_null())) { return (unsafe { let _node: *mut node_t = (*node).left; let _value: i32 = value; find_0(_node, _value) }); - } else if (((value) > ((*node).value)) && (!(((*node).right).is_null()))) { + } else if ((value) > ((*node).value)) && (!(((*node).right).is_null())) { return (unsafe { let _node: *mut node_t = (*node).right; let _value: i32 = value; diff --git a/tests/benchmarks/out/unsafe/fibonacci.rs b/tests/benchmarks/out/unsafe/fibonacci.rs index 361b221..d67f49e 100644 --- a/tests/benchmarks/out/unsafe/fibonacci.rs +++ b/tests/benchmarks/out/unsafe/fibonacci.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn fib_0(mut n: u64) -> u64 { - return if (((n) == (0_u64)) || ((n) == (1_u64))) { + return if ((n) == (0_u64)) || ((n) == (1_u64)) { n } else { (unsafe { diff --git a/tests/benchmarks/out/unsafe/ptr_fibonacci.rs b/tests/benchmarks/out/unsafe/ptr_fibonacci.rs index b75c0b4..bb396ec 100644 --- a/tests/benchmarks/out/unsafe/ptr_fibonacci.rs +++ b/tests/benchmarks/out/unsafe/ptr_fibonacci.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn fib_0(mut n: *mut u64) { - if (((*n) == (0_u64)) || ((*n) == (1_u64))) { + if ((*n) == (0_u64)) || ((*n) == (1_u64)) { return; } let mut n_1: u64 = (*n).wrapping_sub(1_u64); diff --git a/tests/benchmarks/out/unsafe/ref_fibonacci.rs b/tests/benchmarks/out/unsafe/ref_fibonacci.rs index 993ec74..7ead581 100644 --- a/tests/benchmarks/out/unsafe/ref_fibonacci.rs +++ b/tests/benchmarks/out/unsafe/ref_fibonacci.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn fib_0(n: *mut u64) { - if (((*n) == (0_u64)) || ((*n) == (1_u64))) { + if ((*n) == (0_u64)) || ((*n) == (1_u64)) { return; } let mut n_1: u64 = (*n).wrapping_sub(1_u64); diff --git a/tests/ub/out/refcount/ub6.rs b/tests/ub/out/refcount/ub6.rs index 12afc5f..f971903 100644 --- a/tests/ub/out/refcount/ub6.rs +++ b/tests/ub/out/refcount/ub6.rs @@ -48,13 +48,11 @@ pub fn any_2(arr: Ptr]>>>>, n1: Ptr) -> bool { let _lhs = (*i.borrow()); _lhs < (n1.read()) } { - let __rhs = { - let _lhs = (*out.borrow()); - _lhs || (((*arr.upgrade().deref()).as_ref().unwrap().borrow() + let __rhs = (*out.borrow()) + || (((*arr.upgrade().deref()).as_ref().unwrap().borrow() [((*i.borrow()) as u64) as usize] .read()) - == 0) - }; + == 0); (*out.borrow_mut()) = __rhs; (*i.borrow_mut()).prefix_inc(); } diff --git a/tests/ub/out/unsafe/ub6.rs b/tests/ub/out/unsafe/ub6.rs index 1d276b7..444247f 100644 --- a/tests/ub/out/unsafe/ub6.rs +++ b/tests/ub/out/unsafe/ub6.rs @@ -29,7 +29,7 @@ pub unsafe fn any_2(arr: *mut Option>, n1: *mut i32) -> bool { let mut out: bool = false; let mut i: i32 = 0; 'loop_: while ((i) < (*n1)) { - out = ((out) || ((*(*arr).as_mut().unwrap()[(i as u64) as usize]) == (0))); + out = (out) || ((*(*arr).as_mut().unwrap()[(i as u64) as usize]) == (0)); i.prefix_inc(); } return out; diff --git a/tests/unit/bool_condition_logical.cpp b/tests/unit/bool_condition_logical.cpp index eff2ae5..793f1d7 100644 --- a/tests/unit/bool_condition_logical.cpp +++ b/tests/unit/bool_condition_logical.cpp @@ -9,6 +9,9 @@ int observe(int v) { return v; } +int returns_one() { return 1; } +int returns_zero() { return 0; } + int main() { int n = 3; int zero = 0; @@ -77,5 +80,50 @@ int main() { assert(true); } + unsigned long long ull = 7ull; + if ((p != nullptr) && ull) { + assert(true); + } + if ((x > y) && ull) { + assert(true); + } + + long long mask = (1ll << 4) | (1ll << 5); + long long bits = 1ll << 4; + if ((n != 0) && (bits & mask)) { + assert(true); + } + if ((n != 0) || (bits & 0x100ll)) { + assert(true); + } + + const char *cp = "hi"; + const char *cnp = nullptr; + if ((x > y) && cp) { + assert(true); + } + if ((x < y) || cnp) { + assert(false); + } + if ((x > y) && (n && cp)) { + assert(true); + } + + if ((x > y) && returns_one()) { + assert(true); + } + if ((x > y) && !returns_zero()) { + assert(true); + } + if ((x < y) || returns_one()) { + assert(true); + } + if ((x < y) || !returns_one()) { + assert(false); + } + if ((p != nullptr) && returns_one() && (n != 0)) { + assert(true); + } + return 0; } diff --git a/tests/unit/bool_condition_logical_c.c b/tests/unit/bool_condition_logical_c.c index c7870f3..60606f3 100644 --- a/tests/unit/bool_condition_logical_c.c +++ b/tests/unit/bool_condition_logical_c.c @@ -10,6 +10,9 @@ int observe(int v) { return v; } +int returns_one(void) { return 1; } +int returns_zero(void) { return 0; } + int main() { int n = 3; int zero = 0; @@ -78,5 +81,50 @@ int main() { assert(true); } + unsigned long long ull = 7ull; + if ((p != NULL) && ull) { + assert(true); + } + if ((x > y) && ull) { + assert(true); + } + + long long mask = (1ll << 4) | (1ll << 5); + long long bits = 1ll << 4; + if ((n != 0) && (bits & mask)) { + assert(true); + } + if ((n != 0) || (bits & 0x100ll)) { + assert(true); + } + + const char *cp = "hi"; + const char *cnp = NULL; + if ((x > y) && cp) { + assert(true); + } + if ((x < y) || cnp) { + assert(false); + } + if ((x > y) && (n && cp)) { + assert(true); + } + + if ((x > y) && returns_one()) { + assert(true); + } + if ((x > y) && !returns_zero()) { + assert(true); + } + if ((x < y) || returns_one()) { + assert(true); + } + if ((x < y) || !returns_one()) { + assert(false); + } + if ((p != NULL) && returns_one() && (n != 0)) { + assert(true); + } + return 0; } diff --git a/tests/unit/expr_as_bool_c.c b/tests/unit/expr_as_bool_c.c index 3a7cc10..9232708 100644 --- a/tests/unit/expr_as_bool_c.c +++ b/tests/unit/expr_as_bool_c.c @@ -1,5 +1,12 @@ #include #include +#include + +int cmp_eq(int rc) { return rc == -1; } +int cmp_or_ptr(const char *p, const char *q) { return p || q; } +int both_null(const char *s1, const char *s2) { + return (s1 == NULL) && (s2 == NULL); +} int main() { int a = 0; @@ -25,5 +32,28 @@ int main() { c = a; c = a == b; c = a < b; + + int x = 5, y = 5; + int eq = x == y; + int lt = x < y; + int neq = x != y; + assert(eq == 1); + assert(lt == 0); + assert(neq == 0); + + const char *p1 = "hi"; + const char *p2 = NULL; + int either = p1 || p2; + int both = p1 && p2; + assert(either == 1); + assert(both == 0); + + assert(cmp_eq(-1) == 1); + assert(cmp_eq(0) == 0); + assert(cmp_or_ptr(p1, p2) == 1); + assert(cmp_or_ptr(NULL, NULL) == 0); + assert(both_null(NULL, NULL) == 1); + assert(both_null(p1, NULL) == 0); + return 0; } diff --git a/tests/unit/expr_as_bool_cpp.cpp b/tests/unit/expr_as_bool_cpp.cpp index 3a7cc10..21a9141 100644 --- a/tests/unit/expr_as_bool_cpp.cpp +++ b/tests/unit/expr_as_bool_cpp.cpp @@ -1,5 +1,12 @@ #include #include +#include + +int cmp_eq(int rc) { return rc == -1; } +int cmp_or_ptr(const char *p, const char *q) { return p || q; } +int both_null(const char *s1, const char *s2) { + return (s1 == nullptr) && (s2 == nullptr); +} int main() { int a = 0; @@ -25,5 +32,28 @@ int main() { c = a; c = a == b; c = a < b; + + int x = 5, y = 5; + int eq = x == y; + int lt = x < y; + int neq = x != y; + assert(eq == 1); + assert(lt == 0); + assert(neq == 0); + + const char *p1 = "hi"; + const char *p2 = nullptr; + int either = p1 || p2; + int both = p1 && p2; + assert(either == 1); + assert(both == 0); + + assert(cmp_eq(-1) == 1); + assert(cmp_eq(0) == 0); + assert(cmp_or_ptr(p1, p2) == 1); + assert(cmp_or_ptr(nullptr, nullptr) == 0); + assert(both_null(nullptr, nullptr) == 1); + assert(both_null(p1, nullptr) == 0); + return 0; } diff --git a/tests/unit/out/refcount/anonymous-struct_c.rs b/tests/unit/out/refcount/anonymous-struct_c.rs index ab870b0..fe9e84e 100644 --- a/tests/unit/out/refcount/anonymous-struct_c.rs +++ b/tests/unit/out/refcount/anonymous-struct_c.rs @@ -85,26 +85,28 @@ fn main_0() -> i32 { (*(*(*(*o.borrow()).anon_3.borrow()).anon_1.borrow()) .k .borrow_mut()) = 11; - assert!(((*(*(*o.borrow()).named.borrow()).a.borrow()) == 1)); - assert!(((*(*(*o.borrow()).named.borrow()).b.borrow()) == 2)); - assert!(((*(*(*o.borrow()).anon0.borrow()).c.borrow()) == 3)); - assert!(((*(*(*o.borrow()).anon0.borrow()).d.borrow()) == 4)); - assert!(((*(*(*o.borrow()).anon1.borrow()).g.borrow()) == 5)); - assert!(((*(*(*o.borrow()).anon1.borrow()).h.borrow()) == 6)); - assert!(((*(*(*o.borrow()).anon_2.borrow()).e.borrow()) == 7)); - assert!(((*(*(*o.borrow()).anon_2.borrow()).f.borrow()) == 8)); - assert!(((*(*(*o.borrow()).anon_3.borrow()).i.borrow()) == 9)); + assert!(((((*(*(*o.borrow()).named.borrow()).a.borrow()) == 1) as i32) != 0)); + assert!(((((*(*(*o.borrow()).named.borrow()).b.borrow()) == 2) as i32) != 0)); + assert!(((((*(*(*o.borrow()).anon0.borrow()).c.borrow()) == 3) as i32) != 0)); + assert!(((((*(*(*o.borrow()).anon0.borrow()).d.borrow()) == 4) as i32) != 0)); + assert!(((((*(*(*o.borrow()).anon1.borrow()).g.borrow()) == 5) as i32) != 0)); + assert!(((((*(*(*o.borrow()).anon1.borrow()).h.borrow()) == 6) as i32) != 0)); + assert!(((((*(*(*o.borrow()).anon_2.borrow()).e.borrow()) == 7) as i32) != 0)); + assert!(((((*(*(*o.borrow()).anon_2.borrow()).f.borrow()) == 8) as i32) != 0)); + assert!(((((*(*(*o.borrow()).anon_3.borrow()).i.borrow()) == 9) as i32) != 0)); assert!( - ((*(*(*(*o.borrow()).anon_3.borrow()).inner_named.borrow()) + ((((*(*(*(*o.borrow()).anon_3.borrow()).inner_named.borrow()) .j .borrow()) - == 10) + == 10) as i32) + != 0) ); assert!( - ((*(*(*(*o.borrow()).anon_3.borrow()).anon_1.borrow()) + ((((*(*(*(*o.borrow()).anon_3.borrow()).anon_1.borrow()) .k .borrow()) - == 11) + == 11) as i32) + != 0) ); #[derive(Default)] pub struct anon_0 { diff --git a/tests/unit/out/refcount/anonymous_enum_c.rs b/tests/unit/out/refcount/anonymous_enum_c.rs index 4127878..8fa7162 100644 --- a/tests/unit/out/refcount/anonymous_enum_c.rs +++ b/tests/unit/out/refcount/anonymous_enum_c.rs @@ -96,17 +96,25 @@ fn main_0() -> i32 { } } }; - assert!(((anon_enum_3::FIRST_A as i32) != (anon_enum_3::FIRST_B as i32))); - assert!(((anon_enum_11::SECOND_A as i32) != (anon_enum_11::SECOND_B as i32))); - assert!(((anon_enum_31::THIRD_A as i32) != (anon_enum_31::THIRD_B as i32))); + assert!(((((anon_enum_3::FIRST_A as i32) != (anon_enum_3::FIRST_B as i32)) as i32) != 0)); + assert!(((((anon_enum_11::SECOND_A as i32) != (anon_enum_11::SECOND_B as i32)) as i32) != 0)); + assert!(((((anon_enum_31::THIRD_A as i32) != (anon_enum_31::THIRD_B as i32)) as i32) != 0)); let td: Value = Rc::new(RefCell::new(TdEnum::from((TdEnum::TD_A as i32)))); - assert!((((*td.borrow()) as u32) == ((TdEnum::TD_A as i32) as u32))); + assert!((((((*td.borrow()) as u32) == ((TdEnum::TD_A as i32) as u32)) as i32) != 0)); (*td.borrow_mut()) = TdEnum::from((TdEnum::TD_B as i32)); - assert!((((*td.borrow()) as u32) == ((TdEnum::TD_B as i32) as u32))); + assert!((((((*td.borrow()) as u32) == ((TdEnum::TD_B as i32) as u32)) as i32) != 0)); let w: Value = >::default(); (*(*w.borrow()).field.borrow_mut()) = anon_enum_24::from((anon_enum_24::FIELD_A as i32)); - assert!((((*(*w.borrow()).field.borrow()) as u32) == ((anon_enum_24::FIELD_A as i32) as u32))); + assert!( + (((((*(*w.borrow()).field.borrow()) as u32) == ((anon_enum_24::FIELD_A as i32) as u32)) + as i32) + != 0) + ); (*(*w.borrow()).field.borrow_mut()) = anon_enum_24::from((anon_enum_24::FIELD_B as i32)); - assert!((((*(*w.borrow()).field.borrow()) as u32) == ((anon_enum_24::FIELD_B as i32) as u32))); + assert!( + (((((*(*w.borrow()).field.borrow()) as u32) == ((anon_enum_24::FIELD_B as i32) as u32)) + as i32) + != 0) + ); return 0; } diff --git a/tests/unit/out/refcount/bool_condition_enum_c.rs b/tests/unit/out/refcount/bool_condition_enum_c.rs index 150f261..1bf7cac 100644 --- a/tests/unit/out/refcount/bool_condition_enum_c.rs +++ b/tests/unit/out/refcount/bool_condition_enum_c.rs @@ -42,7 +42,7 @@ fn main_0() -> i32 { assert!((0 != 0)); } let t9: Value = Rc::new(RefCell::new((!((*code.borrow()) != Code::from(0)) as i32))); - assert!(((*t9.borrow()) == 1)); + assert!(((((*t9.borrow()) == 1) as i32) != 0)); let b4: Value = Rc::new(RefCell::new(((*code.borrow()) != Code::from(0)).clone())); assert!(((!(*b4.borrow()) as i32) != 0)); return 0; diff --git a/tests/unit/out/refcount/bool_condition_int_c.rs b/tests/unit/out/refcount/bool_condition_int_c.rs index 7d68528..7578ebc 100644 --- a/tests/unit/out/refcount/bool_condition_int_c.rs +++ b/tests/unit/out/refcount/bool_condition_int_c.rs @@ -46,25 +46,25 @@ fn main_0() -> i32 { (*counter.borrow_mut()).prefix_dec(); (*loop_count.borrow_mut()).prefix_inc(); } - assert!(((*loop_count.borrow()) == 3)); + assert!(((((*loop_count.borrow()) == 3) as i32) != 0)); let i: Value = Rc::new(RefCell::new(5)); 'loop_: while ((*i.borrow()) != 0) { (*loop_count.borrow_mut()).prefix_inc(); (*i.borrow_mut()).prefix_dec(); } - assert!(((*loop_count.borrow()) == 8)); + assert!(((((*loop_count.borrow()) == 8) as i32) != 0)); let t: Value = Rc::new(RefCell::new(if ((*n.borrow()) != 0) { 100 } else { 200 })); - assert!(((*t.borrow()) == 100)); + assert!(((((*t.borrow()) == 100) as i32) != 0)); let t2: Value = Rc::new(RefCell::new(if ((*zero.borrow()) != 0) { 100 } else { 200 })); - assert!(((*t2.borrow()) == 200)); + assert!(((((*t2.borrow()) == 200) as i32) != 0)); let t7: Value = Rc::new(RefCell::new((!((*n.borrow()) != 0) as i32))); - assert!(((*t7.borrow()) == 0)); + assert!(((((*t7.borrow()) == 0) as i32) != 0)); let t8: Value = Rc::new(RefCell::new((!((*zero.borrow()) != 0) as i32))); - assert!(((*t8.borrow()) == 1)); + assert!(((((*t8.borrow()) == 1) as i32) != 0)); let b1: Value = Rc::new(RefCell::new(((*n.borrow()) != 0))); assert!((*b1.borrow())); return 0; diff --git a/tests/unit/out/refcount/bool_condition_logical.rs b/tests/unit/out/refcount/bool_condition_logical.rs index a25a429..1600c04 100644 --- a/tests/unit/out/refcount/bool_condition_logical.rs +++ b/tests/unit/out/refcount/bool_condition_logical.rs @@ -31,6 +31,12 @@ pub fn observe_0(v: i32) -> i32 { (*side_effect.with(Value::clone).borrow_mut()).prefix_inc(); return (*v.borrow()); } +pub fn returns_one_1() -> i32 { + return 1; +} +pub fn returns_zero_2() -> i32 { + return 0; +} pub fn main() { std::process::exit(main_0()); } @@ -42,54 +48,38 @@ fn main_0() -> i32 { let np: Value> = Rc::new(RefCell::new(Default::default())); let u: Value = Rc::new(RefCell::new(4_u32)); let code: Value = Rc::new(RefCell::new(Code::CODE_OK)); - if { - let _lhs = ((*n.borrow()) != 0); - _lhs && (!(*p.borrow()).is_null()).clone() - } { + if ((*n.borrow()) != 0) && (!(*p.borrow()).is_null()) { assert!(true); } - if { - let _lhs = ((*n.borrow()) != 0); - _lhs && (!(*np.borrow()).is_null()).clone() - } { + if ((*n.borrow()) != 0) && (!(*np.borrow()).is_null()) { assert!(false); } - if { - let _lhs = ((*zero.borrow()) != 0); - _lhs || (!(*p.borrow()).is_null()).clone() - } { + if ((*zero.borrow()) != 0) || (!(*p.borrow()).is_null()) { assert!(true); } - if { - let _lhs = ((*zero.borrow()) != 0); - _lhs || (!(*np.borrow()).is_null()).clone() - } { + if ((*zero.borrow()) != 0) || (!(*np.borrow()).is_null()) { assert!(false); } - if { - let _lhs = { - let _lhs = (((*n.borrow()) != 0) && ((*u.borrow()) != 0)); - _lhs && (!(*p.borrow()).is_null()).clone() - }; - _lhs && (((*code.borrow()) as i32) == (Code::CODE_OK as i32)).clone() - } { + if ((((*n.borrow()) != 0) && ((*u.borrow()) != 0)) && (!(*p.borrow()).is_null())) + && (((*code.borrow()) as i32) == (Code::CODE_OK as i32)) + { assert!(true); } (*side_effect.with(Value::clone).borrow_mut()) = 0; - if (((*zero.borrow()) != 0) + if ((*zero.borrow()) != 0) && (({ let _v: i32 = 1; observe_0(_v) - }) != 0)) + }) != 0) { assert!(false); } assert!(((*side_effect.with(Value::clone).borrow()) == 0)); - if (((*n.borrow()) != 0) + if ((*n.borrow()) != 0) || (({ let _v: i32 = 1; observe_0(_v) - }) != 0)) + }) != 0) { assert!(true); } @@ -97,31 +87,69 @@ fn main_0() -> i32 { let x: Value = Rc::new(RefCell::new(5)); let y: Value = Rc::new(RefCell::new(3)); let flags: Value = Rc::new(RefCell::new(2_u32)); - if (((*x.borrow()) > (*y.borrow())) || (((*flags.borrow()) & 1_u32) != 0)) { + if ((*x.borrow()) > (*y.borrow())) || (((*flags.borrow()) & 1_u32) != 0) { assert!(true); } - if (((*x.borrow()) < (*y.borrow())) || (((*flags.borrow()) & 1_u32) != 0)) { + if ((*x.borrow()) < (*y.borrow())) || (((*flags.borrow()) & 1_u32) != 0) { assert!(false); } let a: Value = Rc::new(RefCell::new(1_u32)); let b: Value = Rc::new(RefCell::new(2_u32)); let c: Value = Rc::new(RefCell::new(3_u32)); - if (((*a.borrow()) != (*c.borrow())) && ((*b.borrow()) != (*c.borrow()))) { + if ((*a.borrow()) != (*c.borrow())) && ((*b.borrow()) != (*c.borrow())) { assert!(true); } let s: Value = Rc::new(RefCell::new(-1_i32)); - if { - let _lhs = (!((*p.borrow()).is_null())).clone(); - _lhs && ((*s.borrow()) < 0) - } { + if (!((*p.borrow()).is_null())) && ((*s.borrow()) < 0) { assert!(true); } let k: Value = Rc::new(RefCell::new(2_u32)); let done: Value = Rc::new(RefCell::new(false)); - if (((*k.borrow()) > 1_u32) || !(*done.borrow())) { + if ((*k.borrow()) > 1_u32) || (!(*done.borrow())) { + assert!(true); + } + if ((*x.borrow()) > (*y.borrow())) || (((*flags.borrow()) & 4_u32) != 0) { + assert!(true); + } + let ull: Value = Rc::new(RefCell::new(7_u64)); + if (!((*p.borrow()).is_null())) && ((*ull.borrow()) != 0) { + assert!(true); + } + if ((*x.borrow()) > (*y.borrow())) && ((*ull.borrow()) != 0) { + assert!(true); + } + let mask: Value = Rc::new(RefCell::new(((1_i64 << 4) | (1_i64 << 5)))); + let bits: Value = Rc::new(RefCell::new((1_i64 << 4))); + if ((*n.borrow()) != 0) && (((*bits.borrow()) & (*mask.borrow())) != 0) { + assert!(true); + } + if ((*n.borrow()) != 0) || (((*bits.borrow()) & 256_i64) != 0) { assert!(true); } - if (((*x.borrow()) > (*y.borrow())) || (((*flags.borrow()) & 4_u32) != 0)) { + let cp: Value> = Rc::new(RefCell::new(Ptr::from_string_literal("hi"))); + let cnp: Value> = Rc::new(RefCell::new(Default::default())); + if ((*x.borrow()) > (*y.borrow())) && (!(*cp.borrow()).is_null()) { + assert!(true); + } + if ((*x.borrow()) < (*y.borrow())) || (!(*cnp.borrow()).is_null()) { + assert!(false); + } + if ((*x.borrow()) > (*y.borrow())) && (((*n.borrow()) != 0) && (!(*cp.borrow()).is_null())) { + assert!(true); + } + if ((*x.borrow()) > (*y.borrow())) && (({ returns_one_1() }) != 0) { + assert!(true); + } + if ((*x.borrow()) > (*y.borrow())) && (!(({ returns_zero_2() }) != 0)) { + assert!(true); + } + if ((*x.borrow()) < (*y.borrow())) || (({ returns_one_1() }) != 0) { + assert!(true); + } + if ((*x.borrow()) < (*y.borrow())) || (!(({ returns_one_1() }) != 0)) { + assert!(false); + } + if ((!((*p.borrow()).is_null())) && (({ returns_one_1() }) != 0)) && ((*n.borrow()) != 0) { assert!(true); } return 0; diff --git a/tests/unit/out/refcount/bool_condition_logical_c.rs b/tests/unit/out/refcount/bool_condition_logical_c.rs index fcf9535..bc04a88 100644 --- a/tests/unit/out/refcount/bool_condition_logical_c.rs +++ b/tests/unit/out/refcount/bool_condition_logical_c.rs @@ -31,6 +31,12 @@ pub fn observe_0(v: i32) -> i32 { (*side_effect.with(Value::clone).borrow_mut()).prefix_inc(); return (*v.borrow()); } +pub fn returns_one_1() -> i32 { + return 1; +} +pub fn returns_zero_2() -> i32 { + return 0; +} pub fn main() { std::process::exit(main_0()); } @@ -42,67 +48,158 @@ fn main_0() -> i32 { let np: Value> = Rc::new(RefCell::new(Default::default())); let u: Value = Rc::new(RefCell::new(4_u32)); let code: Value = Rc::new(RefCell::new(Code::from((Code::CODE_OK as i32)))); - if ((*n.borrow()) != 0) && (!(*p.borrow()).is_null()) { + if (((((*n.borrow()) != 0) && (!(*p.borrow()).is_null())) as i32) != 0) { assert!((1 != 0)); } - if ((*n.borrow()) != 0) && (!(*np.borrow()).is_null()) { + if (((((*n.borrow()) != 0) && (!(*np.borrow()).is_null())) as i32) != 0) { assert!((0 != 0)); } - if ((*zero.borrow()) != 0) || (!(*p.borrow()).is_null()) { + if (((((*zero.borrow()) != 0) || (!(*p.borrow()).is_null())) as i32) != 0) { assert!((1 != 0)); } - if ((*zero.borrow()) != 0) || (!(*np.borrow()).is_null()) { + if (((((*zero.borrow()) != 0) || (!(*np.borrow()).is_null())) as i32) != 0) { assert!((0 != 0)); } - if ((((*n.borrow()) != 0) && ((*u.borrow()) != 0)) && (!(*p.borrow()).is_null())) - && (((*code.borrow()) as u32) == ((Code::CODE_OK as i32) as u32)) + if (((((((((((*n.borrow()) != 0) && ((*u.borrow()) != 0)) as i32) != 0) + && (!(*p.borrow()).is_null())) as i32) + != 0) + && (((((*code.borrow()) as u32) == ((Code::CODE_OK as i32) as u32)) as i32) != 0)) + as i32) + != 0) { assert!((1 != 0)); } (*side_effect.with(Value::clone).borrow_mut()) = 0; - if ((*zero.borrow()) != 0) + if (((((*zero.borrow()) != 0) && (({ let _v: i32 = 1; observe_0(_v) - }) != 0) + }) != 0)) as i32) + != 0) { assert!((0 != 0)); } - assert!(((*side_effect.with(Value::clone).borrow()) == 0)); - if ((*n.borrow()) != 0) + assert!(((((*side_effect.with(Value::clone).borrow()) == 0) as i32) != 0)); + if (((((*n.borrow()) != 0) || (({ let _v: i32 = 1; observe_0(_v) - }) != 0) + }) != 0)) as i32) + != 0) { assert!((1 != 0)); } - assert!(((*side_effect.with(Value::clone).borrow()) == 0)); + assert!(((((*side_effect.with(Value::clone).borrow()) == 0) as i32) != 0)); let x: Value = Rc::new(RefCell::new(5)); let y: Value = Rc::new(RefCell::new(3)); let flags: Value = Rc::new(RefCell::new(2_u32)); - if ((*x.borrow()) > (*y.borrow())) || (((*flags.borrow()) & 1_u32) != 0) { + if (((((((*x.borrow()) > (*y.borrow())) as i32) != 0) || (((*flags.borrow()) & 1_u32) != 0)) + as i32) + != 0) + { assert!((1 != 0)); } - if ((*x.borrow()) < (*y.borrow())) || (((*flags.borrow()) & 1_u32) != 0) { + if (((((((*x.borrow()) < (*y.borrow())) as i32) != 0) || (((*flags.borrow()) & 1_u32) != 0)) + as i32) + != 0) + { assert!((0 != 0)); } let a: Value = Rc::new(RefCell::new(1_u32)); let b: Value = Rc::new(RefCell::new(2_u32)); let c: Value = Rc::new(RefCell::new(3_u32)); - if ((*a.borrow()) != (*c.borrow())) && ((*b.borrow()) != (*c.borrow())) { + if (((((((*a.borrow()) != (*c.borrow())) as i32) != 0) + && ((((*b.borrow()) != (*c.borrow())) as i32) != 0)) as i32) + != 0) + { assert!((1 != 0)); } let s: Value = Rc::new(RefCell::new(-1_i32)); - if ((*p.borrow()) != (Default::default())) && ((*s.borrow()) < 0) { + if (((((((*p.borrow()) != (Default::default())) as i32) != 0) + && ((((*s.borrow()) < 0) as i32) != 0)) as i32) + != 0) + { assert!((1 != 0)); } let k: Value = Rc::new(RefCell::new(2_u32)); let done: Value = Rc::new(RefCell::new((0 != 0))); - if ((*k.borrow()) > 1_u32) || (!(*done.borrow())) { + if (((((((*k.borrow()) > 1_u32) as i32) != 0) || (!(*done.borrow()))) as i32) != 0) { + assert!((1 != 0)); + } + if (((((((*x.borrow()) > (*y.borrow())) as i32) != 0) || (((*flags.borrow()) & 4_u32) != 0)) + as i32) + != 0) + { + assert!((1 != 0)); + } + let ull: Value = Rc::new(RefCell::new(7_u64)); + if (((((((*p.borrow()) != (Default::default())) as i32) != 0) && ((*ull.borrow()) != 0)) + as i32) + != 0) + { + assert!((1 != 0)); + } + if (((((((*x.borrow()) > (*y.borrow())) as i32) != 0) && ((*ull.borrow()) != 0)) as i32) != 0) { assert!((1 != 0)); } - if ((*x.borrow()) > (*y.borrow())) || (((*flags.borrow()) & 4_u32) != 0) { + let mask: Value = Rc::new(RefCell::new(((1_i64 << 4) | (1_i64 << 5)))); + let bits: Value = Rc::new(RefCell::new((1_i64 << 4))); + if (((((((*n.borrow()) != 0) as i32) != 0) && (((*bits.borrow()) & (*mask.borrow())) != 0)) + as i32) + != 0) + { + assert!((1 != 0)); + } + if (((((((*n.borrow()) != 0) as i32) != 0) || (((*bits.borrow()) & 256_i64) != 0)) as i32) != 0) + { + assert!((1 != 0)); + } + let cp: Value> = Rc::new(RefCell::new(Ptr::from_string_literal("hi"))); + let cnp: Value> = Rc::new(RefCell::new(Default::default())); + if (((((((*x.borrow()) > (*y.borrow())) as i32) != 0) && (!(*cp.borrow()).is_null())) as i32) + != 0) + { + assert!((1 != 0)); + } + if (((((((*x.borrow()) < (*y.borrow())) as i32) != 0) || (!(*cnp.borrow()).is_null())) as i32) + != 0) + { + assert!((0 != 0)); + } + if (((((((*x.borrow()) > (*y.borrow())) as i32) != 0) + && (((((*n.borrow()) != 0) && (!(*cp.borrow()).is_null())) as i32) != 0)) as i32) + != 0) + { + assert!((1 != 0)); + } + if (((((((*x.borrow()) > (*y.borrow())) as i32) != 0) && (({ returns_one_1() }) != 0)) as i32) + != 0) + { + assert!((1 != 0)); + } + if (((((((*x.borrow()) > (*y.borrow())) as i32) != 0) && (!(({ returns_zero_2() }) != 0))) + as i32) + != 0) + { + assert!((1 != 0)); + } + if (((((((*x.borrow()) < (*y.borrow())) as i32) != 0) || (({ returns_one_1() }) != 0)) as i32) + != 0) + { + assert!((1 != 0)); + } + if (((((((*x.borrow()) < (*y.borrow())) as i32) != 0) || (!(({ returns_one_1() }) != 0))) + as i32) + != 0) + { + assert!((0 != 0)); + } + if ((((((((((*p.borrow()) != (Default::default())) as i32) != 0) + && (({ returns_one_1() }) != 0)) as i32) + != 0) + && ((((*n.borrow()) != 0) as i32) != 0)) as i32) + != 0) + { assert!((1 != 0)); } return 0; diff --git a/tests/unit/out/refcount/bool_condition_ptr_c.rs b/tests/unit/out/refcount/bool_condition_ptr_c.rs index 68f93d2..7f2ba9b 100644 --- a/tests/unit/out/refcount/bool_condition_ptr_c.rs +++ b/tests/unit/out/refcount/bool_condition_ptr_c.rs @@ -31,15 +31,15 @@ fn main_0() -> i32 { (*iters.borrow_mut()).prefix_inc(); (*iter.borrow_mut()) = Default::default(); } - assert!(((*iters.borrow()) == 1)); + assert!(((((*iters.borrow()) == 1) as i32) != 0)); let t3: Value = Rc::new(RefCell::new(if !(*p.borrow()).is_null() { 1 } else { 0 })); - assert!(((*t3.borrow()) == 1)); + assert!(((((*t3.borrow()) == 1) as i32) != 0)); let t4: Value = Rc::new(RefCell::new(if !(*np.borrow()).is_null() { 1 } else { 0 })); - assert!(((*t4.borrow()) == 0)); + assert!(((((*t4.borrow()) == 0) as i32) != 0)); let t5: Value = Rc::new(RefCell::new((!!(*p.borrow()).is_null() as i32))); - assert!(((*t5.borrow()) == 0)); + assert!(((((*t5.borrow()) == 0) as i32) != 0)); let t6: Value = Rc::new(RefCell::new((!!(*np.borrow()).is_null() as i32))); - assert!(((*t6.borrow()) == 1)); + assert!(((((*t6.borrow()) == 1) as i32) != 0)); let b2: Value = Rc::new(RefCell::new((!(*p.borrow()).is_null()).clone())); let b3: Value = Rc::new(RefCell::new((!(*np.borrow()).is_null()).clone())); assert!((*b2.borrow())); diff --git a/tests/unit/out/refcount/bst.rs b/tests/unit/out/refcount/bst.rs index 20923c6..2b1d90e 100644 --- a/tests/unit/out/refcount/bst.rs +++ b/tests/unit/out/refcount/bst.rs @@ -26,25 +26,21 @@ impl ByteRepr for node_t {} pub fn find_0(node: Ptr, value: i32) -> Ptr { let node: Value> = Rc::new(RefCell::new(node)); let value: Value = Rc::new(RefCell::new(value)); - if { - let _lhs = { - let _lhs = (*value.borrow()); - _lhs < (*(*(*node.borrow()).upgrade().deref()).value.borrow()) - }; - _lhs && (!((*(*(*node.borrow()).upgrade().deref()).left.borrow()).is_null())).clone() - } { + if ({ + let _lhs = (*value.borrow()); + _lhs < (*(*(*node.borrow()).upgrade().deref()).value.borrow()) + }) && (!((*(*(*node.borrow()).upgrade().deref()).left.borrow()).is_null())) + { return ({ let _node: Ptr = (*(*(*node.borrow()).upgrade().deref()).left.borrow()).clone(); let _value: i32 = (*value.borrow()); find_0(_node, _value) }); - } else if { - let _lhs = { - let _lhs = (*value.borrow()); - _lhs > (*(*(*node.borrow()).upgrade().deref()).value.borrow()) - }; - _lhs && (!((*(*(*node.borrow()).upgrade().deref()).right.borrow()).is_null())).clone() - } { + } else if ({ + let _lhs = (*value.borrow()); + _lhs > (*(*(*node.borrow()).upgrade().deref()).value.borrow()) + }) && (!((*(*(*node.borrow()).upgrade().deref()).right.borrow()).is_null())) + { return ({ let _node: Ptr = (*(*(*node.borrow()).upgrade().deref()).right.borrow()).clone(); @@ -148,62 +144,60 @@ fn main_0() -> i32 { insert_1(_node, _new_node) }); (*ptr1.borrow_mut()) = __rhs; - return (({ - let _lhs = ((((((*(*({ + return ((((((((*(*({ + let _node: Ptr = (*ptr1.borrow()).clone(); + let _value: i32 = 0; + find_0(_node, _value) + }) + .upgrade() + .deref()) + .value + .borrow()) + == 0) + && ((*(*({ + let _node: Ptr = (*ptr1.borrow()).clone(); + let _value: i32 = 1; + find_0(_node, _value) + }) + .upgrade() + .deref()) + .value + .borrow()) + == 1)) + && ((*(*({ + let _node: Ptr = (*ptr1.borrow()).clone(); + let _value: i32 = 2; + find_0(_node, _value) + }) + .upgrade() + .deref()) + .value + .borrow()) + == 2)) + && ((*(*({ + let _node: Ptr = (*ptr1.borrow()).clone(); + let _value: i32 = 3; + find_0(_node, _value) + }) + .upgrade() + .deref()) + .value + .borrow()) + == 3)) + && ((*(*({ let _node: Ptr = (*ptr1.borrow()).clone(); - let _value: i32 = 0; + let _value: i32 = 4; find_0(_node, _value) }) .upgrade() .deref()) .value .borrow()) - == 0) - && ((*(*({ - let _node: Ptr = (*ptr1.borrow()).clone(); - let _value: i32 = 1; - find_0(_node, _value) - }) - .upgrade() - .deref()) - .value - .borrow()) - == 1)) - && ((*(*({ - let _node: Ptr = (*ptr1.borrow()).clone(); - let _value: i32 = 2; - find_0(_node, _value) - }) - .upgrade() - .deref()) - .value - .borrow()) - == 2)) - && ((*(*({ - let _node: Ptr = (*ptr1.borrow()).clone(); - let _value: i32 = 3; - find_0(_node, _value) - }) - .upgrade() - .deref()) - .value - .borrow()) - == 3)) - && ((*(*({ - let _node: Ptr = (*ptr1.borrow()).clone(); - let _value: i32 = 4; - find_0(_node, _value) - }) - .upgrade() - .deref()) - .value - .borrow()) - == 4)); - _lhs && ({ + == 4)) + && (({ let _node: Ptr = (*ptr1.borrow()).clone(); let _value: i32 = 5; find_0(_node, _value) }) - .is_null() - }) as i32); + .is_null())) as i32); } diff --git a/tests/unit/out/refcount/builtin_types_compatible.rs b/tests/unit/out/refcount/builtin_types_compatible.rs index 1509d9c..45339a4 100644 --- a/tests/unit/out/refcount/builtin_types_compatible.rs +++ b/tests/unit/out/refcount/builtin_types_compatible.rs @@ -10,16 +10,16 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - assert!((1 == 1)); - assert!((0 == 0)); + assert!((((1 == 1) as i32) != 0)); + assert!((((0 == 0) as i32) != 0)); let x: Value = Rc::new(RefCell::new(0)); - assert!((1 == 1)); - assert!((0 == 0)); + assert!((((1 == 1) as i32) != 0)); + assert!((((0 == 0) as i32) != 0)); let p: Value> = Rc::new(RefCell::new(Default::default())); - assert!((1 == 1)); - assert!((0 == 0)); + assert!((((1 == 1) as i32) != 0)); + assert!((((0 == 0) as i32) != 0)); let ul: Value = Rc::new(RefCell::new(0_u64)); - assert!((1 == 1)); - assert!((0 == 0)); + assert!((((1 == 1) as i32) != 0)); + assert!((((0 == 0) as i32) != 0)); return 0; } diff --git a/tests/unit/out/refcount/c_struct.rs b/tests/unit/out/refcount/c_struct.rs index 2e2499a..18d5fd6 100644 --- a/tests/unit/out/refcount/c_struct.rs +++ b/tests/unit/out/refcount/c_struct.rs @@ -62,8 +62,8 @@ fn main_0() -> i32 { x: Rc::new(RefCell::new(10)), y: Rc::new(RefCell::new(20)), })); - assert!(((*(*p.borrow()).x.borrow()) == 10)); - assert!(((*(*p.borrow()).y.borrow()) == 20)); + assert!(((((*(*p.borrow()).x.borrow()) == 10) as i32) != 0)); + assert!(((((*(*p.borrow()).y.borrow()) == 20) as i32) != 0)); let l: Value = Rc::new(RefCell::new(Line { start: Rc::new(RefCell::new(Point { x: Rc::new(RefCell::new(1)), @@ -74,8 +74,8 @@ fn main_0() -> i32 { y: Rc::new(RefCell::new(4)), })), })); - assert!(((*(*(*l.borrow()).start.borrow()).x.borrow()) == 1)); - assert!(((*(*(*l.borrow()).end.borrow()).y.borrow()) == 4)); + assert!(((((*(*(*l.borrow()).start.borrow()).x.borrow()) == 1) as i32) != 0)); + assert!(((((*(*(*l.borrow()).end.borrow()).y.borrow()) == 4) as i32) != 0)); let a: Value = Rc::new(RefCell::new(Node { value: Rc::new(RefCell::new(1)), next: Rc::new(RefCell::new(Default::default())), @@ -85,10 +85,11 @@ fn main_0() -> i32 { next: Rc::new(RefCell::new((a.as_pointer()))), })); assert!( - ((*(*(*(*b.borrow()).next.borrow()).upgrade().deref()) + ((((*(*(*(*b.borrow()).next.borrow()).upgrade().deref()) .value .borrow()) - == 1) + == 1) as i32) + != 0) ); let c: Value = Rc::new(RefCell::new(Container { inner: Rc::new(RefCell::new(Inner { @@ -98,12 +99,15 @@ fn main_0() -> i32 { color: Rc::new(RefCell::new(Color::from((Color::GREEN as i32)))), count: Rc::new(RefCell::new(42)), })); - assert!(((*(*(*c.borrow()).inner.borrow()).a.borrow()) == 5)); - assert!(((*(*(*c.borrow()).inner.borrow()).b.borrow()) == 6)); - assert!((((*(*c.borrow()).color.borrow()) as u32) == ((Color::GREEN as i32) as u32))); - assert!(((*(*c.borrow()).count.borrow()) == 42)); + assert!(((((*(*(*c.borrow()).inner.borrow()).a.borrow()) == 5) as i32) != 0)); + assert!(((((*(*(*c.borrow()).inner.borrow()).b.borrow()) == 6) as i32) != 0)); + assert!( + (((((*(*c.borrow()).color.borrow()) as u32) == ((Color::GREEN as i32) as u32)) as i32) + != 0) + ); + assert!(((((*(*c.borrow()).count.borrow()) == 42) as i32) != 0)); let c2: Value = >::default(); (*(*c2.borrow()).color.borrow_mut()) = Color::from((Color::BLUE as i32)); - assert!((((*(*c2.borrow()).color.borrow()) as u32) == 2_u32)); + assert!((((((*(*c2.borrow()).color.borrow()) as u32) == 2_u32) as i32) != 0)); return 0; } diff --git a/tests/unit/out/refcount/enum_int_interop_c.rs b/tests/unit/out/refcount/enum_int_interop_c.rs index 5d77dc5..be36e08 100644 --- a/tests/unit/out/refcount/enum_int_interop_c.rs +++ b/tests/unit/out/refcount/enum_int_interop_c.rs @@ -96,10 +96,10 @@ pub fn main() { } fn main_0() -> i32 { let c: Value = Rc::new(RefCell::new(Color::from((Color::RED as i32)))); - assert!((((*c.borrow()) as u32) == ((Color::RED as i32) as u32))); - assert!((((*c.borrow()) as u32) == 0_u32)); - assert!((((*c.borrow()) as u32) != 1_u32)); - if (((*c.borrow()) as u32) == ((Color::GREEN as i32) as u32)) { + assert!((((((*c.borrow()) as u32) == ((Color::RED as i32) as u32)) as i32) != 0)); + assert!((((((*c.borrow()) as u32) == 0_u32) as i32) != 0)); + assert!((((((*c.borrow()) as u32) != 1_u32) as i32) != 0)); + if (((((*c.borrow()) as u32) == ((Color::GREEN as i32) as u32)) as i32) != 0) { return 1; } 'switch: { @@ -120,54 +120,54 @@ fn main_0() -> i32 { } }; let x: Value = Rc::new(RefCell::new(((*c.borrow()) as i32).clone())); - assert!(((*x.borrow()) == 0)); + assert!(((((*x.borrow()) == 0) as i32) != 0)); let y: Value = Rc::new(RefCell::new( ((((*c.borrow()) as u32).wrapping_add(1_u32)) as i32), )); - assert!(((*y.borrow()) == 1)); + assert!(((((*y.borrow()) == 1) as i32) != 0)); (*c.borrow_mut()) = Color::from(2); - assert!((((*c.borrow()) as u32) == ((Color::BLUE as i32) as u32))); - assert!((((*c.borrow()) as u32) == 2_u32)); + assert!((((((*c.borrow()) as u32) == ((Color::BLUE as i32) as u32)) as i32) != 0)); + assert!((((((*c.borrow()) as u32) == 2_u32) as i32) != 0)); (*c.borrow_mut()) = ({ let _n: i32 = 1; make_color_2(_n) }); - assert!((((*c.borrow()) as u32) == ((Color::GREEN as i32) as u32))); + assert!((((((*c.borrow()) as u32) == ((Color::GREEN as i32) as u32)) as i32) != 0)); let cmp: Value = Rc::new(RefCell::new(Color::from( (((*c.borrow()) as u32).wrapping_add(1_u32)) as i32, ))); - assert!((((*cmp.borrow()) as u32) == ((Color::BLUE as i32) as u32))); + assert!((((((*cmp.borrow()) as u32) == ((Color::BLUE as i32) as u32)) as i32) != 0)); let o: Value