Skip to content

Commit 6965b4a

Browse files
committed
Remove Rvalue::CheckedBinaryOp
1 parent ed7d97e commit 6965b4a

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/base.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -609,14 +609,11 @@ fn codegen_stmt<'tcx>(
609609
let lhs = codegen_operand(fx, &lhs_rhs.0);
610610
let rhs = codegen_operand(fx, &lhs_rhs.1);
611611

612-
let res = crate::num::codegen_binop(fx, bin_op, lhs, rhs);
613-
lval.write_cvalue(fx, res);
614-
}
615-
Rvalue::CheckedBinaryOp(bin_op, ref lhs_rhs) => {
616-
let lhs = codegen_operand(fx, &lhs_rhs.0);
617-
let rhs = codegen_operand(fx, &lhs_rhs.1);
618-
619-
let res = crate::num::codegen_checked_int_binop(fx, bin_op, lhs, rhs);
612+
let res = if let Some(bin_op) = bin_op.overflowing_to_wrapping() {
613+
crate::num::codegen_checked_int_binop(fx, bin_op, lhs, rhs)
614+
} else {
615+
crate::num::codegen_binop(fx, bin_op, lhs, rhs)
616+
};
620617
lval.write_cvalue(fx, res);
621618
}
622619
Rvalue::UnaryOp(un_op, ref operand) => {

src/codegen_i128.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub(crate) fn maybe_codegen<'tcx>(
7070
}
7171
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne | BinOp::Cmp => None,
7272
BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked => None,
73+
BinOp::AddWithOverflow | BinOp::SubWithOverflow | BinOp::MulWithOverflow => unreachable!(),
7374
}
7475
}
7576

@@ -132,6 +133,7 @@ pub(crate) fn maybe_codegen_checked<'tcx>(
132133
Some(out_place.to_cvalue(fx))
133134
}
134135
BinOp::AddUnchecked | BinOp::SubUnchecked | BinOp::MulUnchecked => unreachable!(),
136+
BinOp::AddWithOverflow | BinOp::SubWithOverflow | BinOp::MulWithOverflow => unreachable!(),
135137
BinOp::Offset => unreachable!("offset should only be used on pointers, not 128bit ints"),
136138
BinOp::Div | BinOp::Rem => unreachable!(),
137139
BinOp::Cmp => unreachable!(),

src/num.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ pub(crate) fn codegen_int_binop<'tcx>(
179179
}
180180
}
181181
BinOp::Offset => unreachable!("Offset is not an integer operation"),
182+
BinOp::AddWithOverflow | BinOp::SubWithOverflow | BinOp::MulWithOverflow => {
183+
unreachable!("Overflow binops handled by `codegen_checked_int_binop`")
184+
}
182185
// Compare binops handles by `codegen_binop`.
183186
BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge | BinOp::Cmp => {
184187
unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs.layout().ty, in_rhs.layout().ty);

0 commit comments

Comments
 (0)