Skip to content

Commit 2f2d3b2

Browse files
committed
Avoid iadd for ptr const val with zero offset
1 parent cd2fc77 commit 2f2d3b2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/constant.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,13 @@ pub(crate) fn trans_const_value<'tcx>(
225225
}
226226
None => bug!("missing allocation {:?}", ptr.alloc_id),
227227
};
228-
let val = fx
229-
.bcx
230-
.ins()
231-
.iadd_imm(base_addr, i64::try_from(ptr.offset.bytes()).unwrap());
228+
let val = if ptr.offset.bytes() != 0 {
229+
fx.bcx
230+
.ins()
231+
.iadd_imm(base_addr, i64::try_from(ptr.offset.bytes()).unwrap())
232+
} else {
233+
base_addr
234+
};
232235
return CValue::by_val(val, layout);
233236
}
234237
}

0 commit comments

Comments
 (0)