Skip to content

Commit 5b38674

Browse files
committed
Fix "offset" intrinsic
It didn't multiply the offset given by the pointee type size.
1 parent 91385ba commit 5b38674

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/intrinsics.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ pub fn codegen_intrinsic_call<'a, 'tcx: 'a>(
127127
likely | unlikely, (c a) {
128128
ret.write_cvalue(fx, a);
129129
};
130+
breakpoint, () {
131+
fx.bcx.ins().debugtrap();
132+
};
130133
copy | copy_nonoverlapping, <elem_ty> (v src, v dst, v count) {
131134
let elem_size: u64 = fx.layout_of(elem_ty).size.bytes();
132135
let elem_size = fx
@@ -286,8 +289,12 @@ pub fn codegen_intrinsic_call<'a, 'tcx: 'a>(
286289
let res = fx.bcx.ins().rotr(x, y);
287290
ret.write_cvalue(fx, CValue::ByVal(res, layout));
288291
};
289-
offset, (v base, v offset) {
290-
let res = fx.bcx.ins().iadd(base, offset);
292+
offset, (c base, v offset) {
293+
let pointee_ty = base.layout().ty.builtin_deref(true).unwrap().ty;
294+
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
295+
let ptr_diff = fx.bcx.ins().imul_imm(offset, pointee_size as i64);
296+
let base_val = base.load_scalar(fx);
297+
let res = fx.bcx.ins().iadd(base_val, ptr_diff);
291298
ret.write_cvalue(fx, CValue::ByVal(res, args[0].layout()));
292299
};
293300
transmute, <src_ty, dst_ty> (c from) {

0 commit comments

Comments
 (0)