@@ -61,6 +61,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
61
61
}
62
62
63
63
impl < ' mir , ' tcx : ' mir , M : Machine < ' mir , ' tcx > > InterpCx < ' mir , ' tcx , M > {
64
+ fn three_way_compare < T : Ord > ( & self , lhs : T , rhs : T ) -> ( ImmTy < ' tcx , M :: Provenance > , bool ) {
65
+ let res = Ord :: cmp ( & lhs, & rhs) ;
66
+ return ( ImmTy :: from_ordering ( res, * self . tcx ) , false ) ;
67
+ }
68
+
64
69
fn binary_char_op (
65
70
& self ,
66
71
bin_op : mir:: BinOp ,
@@ -69,6 +74,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
69
74
) -> ( ImmTy < ' tcx , M :: Provenance > , bool ) {
70
75
use rustc_middle:: mir:: BinOp :: * ;
71
76
77
+ if bin_op == Cmp {
78
+ return self . three_way_compare ( l, r) ;
79
+ }
80
+
72
81
let res = match bin_op {
73
82
Eq => l == r,
74
83
Ne => l != r,
@@ -231,6 +240,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
231
240
let r = self . sign_extend ( r, right_layout) as i128 ;
232
241
return Ok ( ( ImmTy :: from_bool ( op ( & l, & r) , * self . tcx ) , false ) ) ;
233
242
}
243
+ if bin_op == Cmp {
244
+ let l = self . sign_extend ( l, left_layout) as i128 ;
245
+ let r = self . sign_extend ( r, right_layout) as i128 ;
246
+ return Ok ( self . three_way_compare ( l, r) ) ;
247
+ }
234
248
let op: Option < fn ( i128 , i128 ) -> ( i128 , bool ) > = match bin_op {
235
249
Div if r == 0 => throw_ub ! ( DivisionByZero ) ,
236
250
Rem if r == 0 => throw_ub ! ( RemainderByZero ) ,
@@ -270,6 +284,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
270
284
}
271
285
}
272
286
287
+ if bin_op == Cmp {
288
+ return Ok ( self . three_way_compare ( l, r) ) ;
289
+ }
290
+
273
291
let val = match bin_op {
274
292
Eq => ImmTy :: from_bool ( l == r, * self . tcx ) ,
275
293
Ne => ImmTy :: from_bool ( l != r, * self . tcx ) ,
0 commit comments