aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/translate_c.zig14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/translate_c.zig b/src/translate_c.zig
index e6305feec3..5683855d23 100644
--- a/src/translate_c.zig
+++ b/src/translate_c.zig
@@ -3807,11 +3807,7 @@ fn transCreateCompoundAssign(
const rhs_qt = getExprQualType(c, rhs);
const is_signed = cIsSignedInteger(lhs_qt);
const is_ptr_op_signed = qualTypeIsPtr(lhs_qt) and cIsSignedInteger(rhs_qt);
- const requires_int_cast = blk: {
- const are_integers = cIsInteger(lhs_qt) and cIsInteger(rhs_qt);
- const are_same_sign = cIsSignedInteger(lhs_qt) == cIsSignedInteger(rhs_qt);
- break :blk are_integers and !(are_same_sign and cIntTypeCmp(lhs_qt, rhs_qt) == .eq);
- };
+ const requires_cast = !lhs_qt.eq(rhs_qt) and !is_ptr_op_signed;
if (used == .unused) {
// common case
@@ -3822,7 +3818,7 @@ fn transCreateCompoundAssign(
if (is_ptr_op_signed) rhs_node = try usizeCastForWrappingPtrArithmetic(c.arena, rhs_node);
if ((is_mod or is_div) and is_signed) {
- if (requires_int_cast) rhs_node = try transCCast(c, scope, loc, lhs_qt, rhs_qt, rhs_node);
+ if (requires_cast) rhs_node = try transCCast(c, scope, loc, lhs_qt, rhs_qt, rhs_node);
const operands = .{ .lhs = lhs_node, .rhs = rhs_node };
const builtin = if (is_mod)
try Tag.signed_remainder.create(c.arena, operands)
@@ -3834,7 +3830,7 @@ fn transCreateCompoundAssign(
if (is_shift) {
rhs_node = try Tag.int_cast.create(c.arena, rhs_node);
- } else if (requires_int_cast) {
+ } else if (requires_cast) {
rhs_node = try transCCast(c, scope, loc, lhs_qt, rhs_qt, rhs_node);
}
return transCreateNodeInfixOp(c, op, lhs_node, rhs_node, .used);
@@ -3861,7 +3857,7 @@ fn transCreateCompoundAssign(
var rhs_node = try transExpr(c, &block_scope.base, rhs, .used);
if (is_ptr_op_signed) rhs_node = try usizeCastForWrappingPtrArithmetic(c.arena, rhs_node);
if ((is_mod or is_div) and is_signed) {
- if (requires_int_cast) rhs_node = try transCCast(c, scope, loc, lhs_qt, rhs_qt, rhs_node);
+ if (requires_cast) rhs_node = try transCCast(c, scope, loc, lhs_qt, rhs_qt, rhs_node);
const operands = .{ .lhs = ref_node, .rhs = rhs_node };
const builtin = if (is_mod)
try Tag.signed_remainder.create(c.arena, operands)
@@ -3873,7 +3869,7 @@ fn transCreateCompoundAssign(
} else {
if (is_shift) {
rhs_node = try Tag.int_cast.create(c.arena, rhs_node);
- } else if (requires_int_cast) {
+ } else if (requires_cast) {
rhs_node = try transCCast(c, &block_scope.base, loc, lhs_qt, rhs_qt, rhs_node);
}