Skip to content

Commit bd73128

Browse files
committed
Implement lt, le, ge and gt for fat pointers
1 parent c0779d5 commit bd73128

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/base.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,7 @@ fn trans_ptr_binop<'a, 'tcx: 'a>(
10521052
} else {
10531053
let (lhs_ptr, lhs_extra) = lhs.load_scalar_pair(fx);
10541054
let (rhs_ptr, rhs_extra) = rhs.load_scalar_pair(fx);
1055+
10551056
let res = match bin_op {
10561057
BinOp::Eq => {
10571058
let ptr_eq = fx.bcx.ins().icmp(IntCC::Equal, lhs_ptr, rhs_ptr);
@@ -1063,10 +1064,28 @@ fn trans_ptr_binop<'a, 'tcx: 'a>(
10631064
let extra_ne = fx.bcx.ins().icmp(IntCC::NotEqual, lhs_extra, rhs_extra);
10641065
fx.bcx.ins().bor(ptr_ne, extra_ne)
10651066
}
1066-
_ => unimplemented!(
1067-
"trans_ptr_binop({:?}, <fat ptr>, <fat ptr>) not implemented",
1068-
bin_op
1069-
),
1067+
BinOp::Lt | BinOp::Le | BinOp::Ge | BinOp::Gt => {
1068+
let ptr_eq = fx.bcx.ins().icmp(IntCC::Equal, lhs_ptr, rhs_ptr);
1069+
1070+
let ptr_cmp = fx.bcx.ins().icmp(match bin_op {
1071+
BinOp::Lt => IntCC::UnsignedLessThan,
1072+
BinOp::Le => IntCC::UnsignedLessThanOrEqual,
1073+
BinOp::Ge => IntCC::UnsignedGreaterThanOrEqual,
1074+
BinOp::Gt => IntCC::UnsignedGreaterThan,
1075+
_ => unreachable!(),
1076+
}, lhs_ptr, rhs_ptr);
1077+
1078+
let extra_cmp = fx.bcx.ins().icmp(match bin_op {
1079+
BinOp::Lt => IntCC::UnsignedLessThan,
1080+
BinOp::Le => IntCC::UnsignedLessThanOrEqual,
1081+
BinOp::Ge => IntCC::UnsignedGreaterThanOrEqual,
1082+
BinOp::Gt => IntCC::UnsignedGreaterThan,
1083+
_ => unreachable!(),
1084+
}, lhs_extra, rhs_extra);
1085+
1086+
fx.bcx.ins().select(ptr_eq, extra_cmp, ptr_cmp)
1087+
}
1088+
_ => panic!("bin_op {:?} on ptr", bin_op),
10701089
};
10711090

10721091
assert_eq!(fx.tcx.types.bool, ret_ty);

0 commit comments

Comments
 (0)