@@ -61,6 +61,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
6161}
6262
6363impl < ' 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+
6469 fn binary_char_op (
6570 & self ,
6671 bin_op : mir:: BinOp ,
@@ -69,6 +74,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
6974 ) -> ( ImmTy < ' tcx , M :: Provenance > , bool ) {
7075 use rustc_middle:: mir:: BinOp :: * ;
7176
77+ if bin_op == Cmp {
78+ return self . three_way_compare ( l, r) ;
79+ }
80+
7281 let res = match bin_op {
7382 Eq => l == r,
7483 Ne => l != r,
@@ -231,6 +240,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
231240 let r = self . sign_extend ( r, right_layout) as i128 ;
232241 return Ok ( ( ImmTy :: from_bool ( op ( & l, & r) , * self . tcx ) , false ) ) ;
233242 }
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+ }
234248 let op: Option < fn ( i128 , i128 ) -> ( i128 , bool ) > = match bin_op {
235249 Div if r == 0 => throw_ub ! ( DivisionByZero ) ,
236250 Rem if r == 0 => throw_ub ! ( RemainderByZero ) ,
@@ -270,6 +284,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
270284 }
271285 }
272286
287+ if bin_op == Cmp {
288+ return Ok ( self . three_way_compare ( l, r) ) ;
289+ }
290+
273291 let val = match bin_op {
274292 Eq => ImmTy :: from_bool ( l == r, * self . tcx ) ,
275293 Ne => ImmTy :: from_bool ( l != r, * self . tcx ) ,
0 commit comments