| ... | @@ -3807,11 +3807,7 @@ fn transCreateCompoundAssign( | ... | @@ -3807,11 +3807,7 @@ fn transCreateCompoundAssign( |
| 3807 | const rhs_qt = getExprQualType(c, rhs); | 3807 | const rhs_qt = getExprQualType(c, rhs); |
| 3808 | const is_signed = cIsSignedInteger(lhs_qt); | 3808 | const is_signed = cIsSignedInteger(lhs_qt); |
| 3809 | const is_ptr_op_signed = qualTypeIsPtr(lhs_qt) and cIsSignedInteger(rhs_qt); | 3809 | const is_ptr_op_signed = qualTypeIsPtr(lhs_qt) and cIsSignedInteger(rhs_qt); |
| 3810 | const requires_int_cast = blk: { | 3810 | const requires_cast = !lhs_qt.eq(rhs_qt) and !is_ptr_op_signed; |
| 3811 | const are_integers = cIsInteger(lhs_qt) and cIsInteger(rhs_qt); | | |
| 3812 | const are_same_sign = cIsSignedInteger(lhs_qt) == cIsSignedInteger(rhs_qt); | | |
| 3813 | break :blk are_integers and !(are_same_sign and cIntTypeCmp(lhs_qt, rhs_qt) == .eq); | | |
| 3814 | }; | | |
| 3815 | | 3811 | |
| 3816 | if (used == .unused) { | 3812 | if (used == .unused) { |
| 3817 | // common case | 3813 | // common case |
| ... | @@ -3822,7 +3818,7 @@ fn transCreateCompoundAssign( | ... | @@ -3822,7 +3818,7 @@ fn transCreateCompoundAssign( |
| 3822 | if (is_ptr_op_signed) rhs_node = try usizeCastForWrappingPtrArithmetic(c.arena, rhs_node); | 3818 | if (is_ptr_op_signed) rhs_node = try usizeCastForWrappingPtrArithmetic(c.arena, rhs_node); |
| 3823 | | 3819 | |
| 3824 | if ((is_mod or is_div) and is_signed) { | 3820 | if ((is_mod or is_div) and is_signed) { |
| 3825 | if (requires_int_cast) rhs_node = try transCCast(c, scope, loc, lhs_qt, rhs_qt, rhs_node); | 3821 | if (requires_cast) rhs_node = try transCCast(c, scope, loc, lhs_qt, rhs_qt, rhs_node); |
| 3826 | const operands = .{ .lhs = lhs_node, .rhs = rhs_node }; | 3822 | const operands = .{ .lhs = lhs_node, .rhs = rhs_node }; |
| 3827 | const builtin = if (is_mod) | 3823 | const builtin = if (is_mod) |
| 3828 | try Tag.signed_remainder.create(c.arena, operands) | 3824 | try Tag.signed_remainder.create(c.arena, operands) |
| ... | @@ -3834,7 +3830,7 @@ fn transCreateCompoundAssign( | ... | @@ -3834,7 +3830,7 @@ fn transCreateCompoundAssign( |
| 3834 | | 3830 | |
| 3835 | if (is_shift) { | 3831 | if (is_shift) { |
| 3836 | rhs_node = try Tag.int_cast.create(c.arena, rhs_node); | 3832 | rhs_node = try Tag.int_cast.create(c.arena, rhs_node); |
| 3837 | } else if (requires_int_cast) { | 3833 | } else if (requires_cast) { |
| 3838 | rhs_node = try transCCast(c, scope, loc, lhs_qt, rhs_qt, rhs_node); | 3834 | rhs_node = try transCCast(c, scope, loc, lhs_qt, rhs_qt, rhs_node); |
| 3839 | } | 3835 | } |
| 3840 | return transCreateNodeInfixOp(c, op, lhs_node, rhs_node, .used); | 3836 | return transCreateNodeInfixOp(c, op, lhs_node, rhs_node, .used); |
| ... | @@ -3861,7 +3857,7 @@ fn transCreateCompoundAssign( | ... | @@ -3861,7 +3857,7 @@ fn transCreateCompoundAssign( |
| 3861 | var rhs_node = try transExpr(c, &block_scope.base, rhs, .used); | 3857 | var rhs_node = try transExpr(c, &block_scope.base, rhs, .used); |
| 3862 | if (is_ptr_op_signed) rhs_node = try usizeCastForWrappingPtrArithmetic(c.arena, rhs_node); | 3858 | if (is_ptr_op_signed) rhs_node = try usizeCastForWrappingPtrArithmetic(c.arena, rhs_node); |
| 3863 | if ((is_mod or is_div) and is_signed) { | 3859 | if ((is_mod or is_div) and is_signed) { |
| 3864 | if (requires_int_cast) rhs_node = try transCCast(c, scope, loc, lhs_qt, rhs_qt, rhs_node); | 3860 | if (requires_cast) rhs_node = try transCCast(c, scope, loc, lhs_qt, rhs_qt, rhs_node); |
| 3865 | const operands = .{ .lhs = ref_node, .rhs = rhs_node }; | 3861 | const operands = .{ .lhs = ref_node, .rhs = rhs_node }; |
| 3866 | const builtin = if (is_mod) | 3862 | const builtin = if (is_mod) |
| 3867 | try Tag.signed_remainder.create(c.arena, operands) | 3863 | try Tag.signed_remainder.create(c.arena, operands) |
| ... | @@ -3873,7 +3869,7 @@ fn transCreateCompoundAssign( | ... | @@ -3873,7 +3869,7 @@ fn transCreateCompoundAssign( |
| 3873 | } else { | 3869 | } else { |
| 3874 | if (is_shift) { | 3870 | if (is_shift) { |
| 3875 | rhs_node = try Tag.int_cast.create(c.arena, rhs_node); | 3871 | rhs_node = try Tag.int_cast.create(c.arena, rhs_node); |
| 3876 | } else if (requires_int_cast) { | 3872 | } else if (requires_cast) { |
| 3877 | rhs_node = try transCCast(c, &block_scope.base, loc, lhs_qt, rhs_qt, rhs_node); | 3873 | rhs_node = try transCCast(c, &block_scope.base, loc, lhs_qt, rhs_qt, rhs_node); |
| 3878 | } | 3874 | } |
| 3879 | | 3875 | |