1
- use rustc:: ty:: { Ty , layout :: TyLayout } ;
1
+ use rustc:: ty:: Ty ;
2
2
use rustc:: mir;
3
3
4
4
use crate :: * ;
@@ -23,7 +23,6 @@ pub trait EvalContextExt<'tcx> {
23
23
& self ,
24
24
left : Scalar < Borrow > ,
25
25
right : Scalar < Borrow > ,
26
- size : Size ,
27
26
) -> EvalResult < ' tcx , bool > ;
28
27
29
28
fn pointer_offset_inbounds (
@@ -43,12 +42,29 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
43
42
) -> EvalResult < ' tcx , ( Scalar < Borrow > , bool ) > {
44
43
use rustc:: mir:: BinOp :: * ;
45
44
45
+ trace ! ( "ptr_op: {:?} {:?} {:?}" , * left, bin_op, * right) ;
46
+
47
+ // Operations that support fat pointers
48
+ match bin_op {
49
+ Eq | Ne => {
50
+ let eq = match ( * left, * right) {
51
+ ( Immediate :: Scalar ( left) , Immediate :: Scalar ( right) ) =>
52
+ self . ptr_eq ( left. not_undef ( ) ?, right. not_undef ( ) ?) ?,
53
+ ( Immediate :: ScalarPair ( left1, left2) , Immediate :: ScalarPair ( right1, right2) ) =>
54
+ self . ptr_eq ( left1. not_undef ( ) ?, right1. not_undef ( ) ?) ? &&
55
+ self . ptr_eq ( left2. not_undef ( ) ?, right2. not_undef ( ) ?) ?,
56
+ _ => bug ! ( "Type system should not allow comparing Scalar with ScalarPair" ) ,
57
+ } ;
58
+ return Ok ( ( Scalar :: from_bool ( if bin_op == Eq { eq } else { !eq } ) , false ) ) ;
59
+ }
60
+ _ => { } ,
61
+ }
62
+
63
+ // Now we expect no more fat pointers
46
64
let left_layout = left. layout ;
47
65
let left = left. to_scalar ( ) ?;
48
66
let right_layout = right. layout ;
49
67
let right = right. to_scalar ( ) ?;
50
-
51
- trace ! ( "ptr_op: {:?} {:?} {:?}" , left, bin_op, right) ;
52
68
debug_assert ! ( left. is_ptr( ) || right. is_ptr( ) || bin_op == Offset ) ;
53
69
54
70
match bin_op {
@@ -64,11 +80,6 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
64
80
) ?;
65
81
Ok ( ( ptr, false ) )
66
82
}
67
- // These work on anything
68
- Eq =>
69
- Ok ( ( Scalar :: from_bool ( self . ptr_eq ( left, right, left_layout. size ) ?) , false ) ) ,
70
- Ne =>
71
- Ok ( ( Scalar :: from_bool ( !self . ptr_eq ( left, right, left_layout. size ) ?) , false ) ) ,
72
83
// These need both to be pointer, and fail if they are not in the same location
73
84
Lt | Le | Gt | Ge | Sub if left. is_ptr ( ) && right. is_ptr ( ) => {
74
85
let left = left. to_ptr ( ) . expect ( "we checked is_ptr" ) ;
@@ -127,8 +138,8 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
127
138
& self ,
128
139
left : Scalar < Borrow > ,
129
140
right : Scalar < Borrow > ,
130
- size : Size ,
131
141
) -> EvalResult < ' tcx , bool > {
142
+ let size = self . pointer_size ( ) ;
132
143
Ok ( match ( left, right) {
133
144
( Scalar :: Bits { .. } , Scalar :: Bits { .. } ) =>
134
145
left. to_bits ( size) ? == right. to_bits ( size) ?,
0 commit comments