Skip to content

Commit efc5814

Browse files
committed
Remove untested arithmetic ops.
1 parent bf5efc5 commit efc5814

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

+5-19
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! Currently, this pass only propagates scalar values.
44
55
use rustc_const_eval::interpret::{
6-
ImmTy, Immediate, InterpCx, OpTy, PlaceTy, Pointer, PointerArithmetic, Projectable,
6+
ImmTy, Immediate, InterpCx, OpTy, PlaceTy, PointerArithmetic, Projectable,
77
};
88
use rustc_data_structures::fx::FxHashMap;
99
use rustc_hir::def::DefKind;
@@ -945,10 +945,12 @@ impl<'mir, 'tcx: 'mir> rustc_const_eval::interpret::Machine<'mir, 'tcx> for Dumm
945945
use rustc_middle::mir::BinOp::*;
946946
Ok(match bin_op {
947947
Eq | Ne | Lt | Le | Gt | Ge => {
948-
assert_eq!(left.layout.abi, right.layout.abi); // types an differ, e.g. fn ptrs with different `for`
948+
// Types can differ, e.g. fn ptrs with different `for`.
949+
assert_eq!(left.layout.abi, right.layout.abi);
949950
let size = ecx.pointer_size();
950951
// Just compare the bits. ScalarPairs are compared lexicographically.
951952
// We thus always compare pairs and simply fill scalars up with 0.
953+
// If the pointer has provenance, `to_bits` will return `Err` and we bail out.
952954
let left = match **left {
953955
Immediate::Scalar(l) => (l.to_bits(size)?, 0),
954956
Immediate::ScalarPair(l1, l2) => (l1.to_bits(size)?, l2.to_bits(size)?),
@@ -974,23 +976,7 @@ impl<'mir, 'tcx: 'mir> rustc_const_eval::interpret::Machine<'mir, 'tcx> for Dumm
974976
// Some more operations are possible with atomics.
975977
// The return value always has the provenance of the *left* operand.
976978
Add | Sub | BitOr | BitAnd | BitXor => {
977-
assert!(left.layout.ty.is_unsafe_ptr());
978-
assert!(right.layout.ty.is_unsafe_ptr());
979-
let ptr = left.to_scalar().to_pointer(ecx)?;
980-
// We do the actual operation with usize-typed scalars.
981-
let usize_layout = ecx.layout_of(ecx.tcx.types.usize).unwrap();
982-
let left = ImmTy::from_uint(ptr.addr().bytes(), usize_layout);
983-
let right = ImmTy::from_uint(right.to_scalar().to_target_usize(ecx)?, usize_layout);
984-
let (result, overflowing) = ecx.overflowing_binary_op(bin_op, &left, &right)?;
985-
// Construct a new pointer with the provenance of `ptr` (the LHS).
986-
let result_ptr = Pointer::new(
987-
ptr.provenance,
988-
Size::from_bytes(result.to_scalar().to_target_usize(ecx)?),
989-
);
990-
(
991-
ImmTy::from_scalar(Scalar::from_maybe_pointer(result_ptr, ecx), left.layout),
992-
overflowing,
993-
)
979+
throw_machine_stop_str!("pointer arithmetic is not handled")
994980
}
995981

996982
_ => span_bug!(ecx.cur_span(), "Invalid operator on pointers: {:?}", bin_op),

0 commit comments

Comments
 (0)