3
3
//! Currently, this pass only propagates scalar values.
4
4
5
5
use rustc_const_eval:: interpret:: {
6
- ImmTy , Immediate , InterpCx , OpTy , PlaceTy , Pointer , PointerArithmetic , Projectable ,
6
+ ImmTy , Immediate , InterpCx , OpTy , PlaceTy , PointerArithmetic , Projectable ,
7
7
} ;
8
8
use rustc_data_structures:: fx:: FxHashMap ;
9
9
use rustc_hir:: def:: DefKind ;
@@ -945,10 +945,12 @@ impl<'mir, 'tcx: 'mir> rustc_const_eval::interpret::Machine<'mir, 'tcx> for Dumm
945
945
use rustc_middle:: mir:: BinOp :: * ;
946
946
Ok ( match bin_op {
947
947
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) ;
949
950
let size = ecx. pointer_size ( ) ;
950
951
// Just compare the bits. ScalarPairs are compared lexicographically.
951
952
// 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.
952
954
let left = match * * left {
953
955
Immediate :: Scalar ( l) => ( l. to_bits ( size) ?, 0 ) ,
954
956
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
974
976
// Some more operations are possible with atomics.
975
977
// The return value always has the provenance of the *left* operand.
976
978
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" )
994
980
}
995
981
996
982
_ => span_bug ! ( ecx. cur_span( ) , "Invalid operator on pointers: {:?}" , bin_op) ,
0 commit comments