in_lhs: CValue<'tcx>,
in_rhs: CValue<'tcx>,
) -> CValue<'tcx> {
- let not_fat = match in_lhs.layout().ty.sty {
- ty::RawPtr(TypeAndMut { ty, mutbl: _ }) => {
- ty.is_sized(fx.tcx.at(DUMMY_SP), ParamEnv::reveal_all())
- }
- ty::FnPtr(..) => true,
- _ => bug!("trans_ptr_binop on non ptr"),
- };
- if not_fat {
+ let is_thin_ptr = in_lhs.layout().ty.builtin_deref(true).map(|TypeAndMut { ty, mutbl: _}| {
+ !has_ptr_meta(fx.tcx, ty)
+ }).unwrap_or(true);
+
+ if is_thin_ptr {
match bin_op {
BinOp::Eq | BinOp::Lt | BinOp::Le | BinOp::Ne | BinOp::Ge | BinOp::Gt => {
let lhs = in_lhs.load_scalar(fx);
return codegen_compare_bin_op(fx, bin_op, false, lhs, rhs);
}
BinOp::Offset => {
+ let pointee_ty = in_lhs.layout().ty.builtin_deref(true).unwrap().ty;
let (base, offset) = (in_lhs, in_rhs.load_scalar(fx));
- let pointee_ty = base.layout().ty.builtin_deref(true).unwrap().ty;
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
let ptr_diff = fx.bcx.ins().imul_imm(offset, pointee_size as i64);
let base_val = base.load_scalar(fx);