Skip to content

Commit 77d33c1

Browse files
committed
Fix trans_ptr_binop for fn()
1 parent c34ada7 commit 77d33c1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/num.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,11 @@ pub fn trans_ptr_binop<'tcx>(
347347
in_lhs: CValue<'tcx>,
348348
in_rhs: CValue<'tcx>,
349349
) -> CValue<'tcx> {
350-
let pointee_ty = in_lhs.layout().ty.builtin_deref(true).unwrap().ty;
350+
let is_thin_ptr = in_lhs.layout().ty.builtin_deref(true).map(|TypeAndMut { ty, mutbl: _}| {
351+
!has_ptr_meta(fx.tcx, ty)
352+
}).unwrap_or(true);
351353

352-
if !has_ptr_meta(fx.tcx, pointee_ty) {
354+
if is_thin_ptr {
353355
match bin_op {
354356
BinOp::Eq | BinOp::Lt | BinOp::Le | BinOp::Ne | BinOp::Ge | BinOp::Gt => {
355357
let lhs = in_lhs.load_scalar(fx);
@@ -358,6 +360,7 @@ pub fn trans_ptr_binop<'tcx>(
358360
return codegen_compare_bin_op(fx, bin_op, false, lhs, rhs);
359361
}
360362
BinOp::Offset => {
363+
let pointee_ty = in_lhs.layout().ty.builtin_deref(true).unwrap().ty;
361364
let (base, offset) = (in_lhs, in_rhs.load_scalar(fx));
362365
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
363366
let ptr_diff = fx.bcx.ins().imul_imm(offset, pointee_size as i64);

0 commit comments

Comments
 (0)