Skip to content

Commit b208f46

Browse files
committed
ZJIT: Don't fold LoadField with negative offsets and use byte_add
No point doing the manual size unit conversion for add. Sorry, no new tests since there is no way to generate a LoadField with a negative offset from ruby code AFAICT. Careful with the `as` casts.
1 parent 029a481 commit b208f46

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

zjit/src/hir.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3682,14 +3682,14 @@ impl Function {
36823682
// Don't bother re-inferring the type of val; we already know it.
36833683
continue;
36843684
}
3685-
Insn::LoadField { recv, offset, return_type, .. } if return_type.is_subtype(types::BasicObject) => {
3685+
Insn::LoadField { recv, offset, return_type, .. } if return_type.is_subtype(types::BasicObject) &&
3686+
u32::try_from(offset).is_ok() => {
3687+
let offset = (offset as u32).to_usize();
36863688
let recv_type = self.type_of(recv);
36873689
match recv_type.ruby_object() {
36883690
Some(recv_obj) if recv_obj.is_frozen() => {
36893691
let recv_ptr = recv_obj.as_ptr() as *const VALUE;
3690-
// Rust pointer .add() scales by size_of::<T>() and offset is
3691-
// already scaled by SIZEOF_VALUE, so undo that.
3692-
let val = unsafe { *recv_ptr.add(offset as usize / SIZEOF_VALUE) };
3692+
let val = unsafe { recv_ptr.byte_add(offset).read() };
36933693
self.new_insn(Insn::Const { val: Const::Value(val) })
36943694
}
36953695
_ => insn_id,

0 commit comments

Comments
 (0)