Skip to content

Commit b4ae118

Browse files
committed
YJIT: Fix return type of Integer#/ with T_FIXNUM inputs
Issue found by running ruby/spec with `--yjit-verify-ctx`. Thanks!
1 parent c8d6419 commit b4ae118

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

bootstraptest/test_yjit.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# regression test for return type of Integer#/
2+
# It can return a T_BIGNUM when inputs are T_FIXNUM.
3+
assert_equal 0x3fffffffffffffff.to_s, %q{
4+
def call(fixnum_min)
5+
(fixnum_min / -1) - 1
6+
end
7+
8+
call(-(2**62))
9+
}
10+
111
# regression test for return type of String#<<
212
assert_equal 'Sub', %q{
313
def call(sub) = (sub << sub).itself

yjit/src/codegen.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4531,6 +4531,9 @@ fn jit_rb_int_div(
45314531
}
45324532
guard_two_fixnums(jit, asm, ocb);
45334533

4534+
// rb_fix_div_fix may GC-allocate for Bignum
4535+
jit_prepare_routine_call(jit, asm);
4536+
45344537
asm.comment("Integer#/");
45354538
let obj = asm.stack_pop(1);
45364539
let recv = asm.stack_pop(1);
@@ -4541,7 +4544,7 @@ fn jit_rb_int_div(
45414544

45424545
let ret = asm.ccall(rb_fix_div_fix as *const u8, vec![recv, obj]);
45434546

4544-
let ret_opnd = asm.stack_push(Type::Fixnum);
4547+
let ret_opnd = asm.stack_push(Type::Unknown);
45454548
asm.mov(ret_opnd, ret);
45464549
true
45474550
}

0 commit comments

Comments
 (0)