Fix trans_ptr_binop for fn()

This commit is contained in:
bjorn3 2019-09-15 18:15:40 +02:00
parent c34ada7cca
commit 77d33c1707

View file

@ -347,9 +347,11 @@ pub fn trans_ptr_binop<'tcx>(
in_lhs: CValue<'tcx>,
in_rhs: CValue<'tcx>,
) -> CValue<'tcx> {
let pointee_ty = in_lhs.layout().ty.builtin_deref(true).unwrap().ty;
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 !has_ptr_meta(fx.tcx, pointee_ty) {
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);
@ -358,6 +360,7 @@ pub fn trans_ptr_binop<'tcx>(
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_size = fx.layout_of(pointee_ty).size.bytes();
let ptr_diff = fx.bcx.ins().imul_imm(offset, pointee_size as i64);