interpret: make overflowing binops just normal binops

This commit is contained in:
Ralf Jung
2024-05-21 12:17:34 +02:00
parent 9cb6bb8599
commit c0b4b454c3
40 changed files with 323 additions and 349 deletions

View File

@@ -167,19 +167,17 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let left = self.read_immediate(&self.eval_operand(left, layout)?)?;
let layout = util::binop_right_homogeneous(bin_op).then_some(left.layout);
let right = self.read_immediate(&self.eval_operand(right, layout)?)?;
if let Some(bin_op) = bin_op.overflowing_to_wrapping() {
self.binop_with_overflow(bin_op, &left, &right, &dest)?;
} else {
self.binop_ignore_overflow(bin_op, &left, &right, &dest)?;
}
let result = self.binary_op(bin_op, &left, &right)?;
assert_eq!(result.layout, dest.layout, "layout mismatch for result of {bin_op:?}");
self.write_immediate(*result, &dest)?;
}
UnaryOp(un_op, ref operand) => {
// The operand always has the same type as the result.
let val = self.read_immediate(&self.eval_operand(operand, Some(dest.layout))?)?;
let val = self.wrapping_unary_op(un_op, &val)?;
assert_eq!(val.layout, dest.layout, "layout mismatch for result of {un_op:?}");
self.write_immediate(*val, &dest)?;
let result = self.unary_op(un_op, &val)?;
assert_eq!(result.layout, dest.layout, "layout mismatch for result of {un_op:?}");
self.write_immediate(*result, &dest)?;
}
Aggregate(box ref kind, ref operands) => {