8000 Merge pull request #130 from Shopify/fix-expandarray-codegen · eileencodes/ruby@f82e359 · GitHub
[go: up one dir, main page]

Skip to content

Commit f82e359

Browse files
authored
Merge pull request ruby#130 from Shopify/fix-expandarray-codegen
Ensure we guard the value before we return
2 parents 5ead1ae + 8582bda commit f82e359

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

bootstraptest/test_yjit.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,3 +1479,18 @@ def expandarray_postarg
14791479
expandarray_postarg
14801480
expandarray_postarg
14811481
}
1482+
1483+
assert_equal '10', %q{
1484+
obj = Object.new
1485+
val = nil
1486+
obj.define_singleton_method(:to_ary) { val = 10; [] }
1487+
1488+
def expandarray_always_call_to_ary(object)
1489+
* = object
1490+
end
1491+
1492+
expandarray_always_call_to_ary(obj)
1493+
expandarray_always_call_to_ary(obj)
1494+
1495+
val
1496+
}

yjit_codegen.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -772,16 +772,16 @@ gen_expandarray(jitstate_t* jit, ctx_t* ctx)
772772
rb_num_t num = (rb_num_t) jit_get_arg(jit, 0);
773773
x86opnd_t array_opnd = ctx_stack_pop(ctx, 1);
774774

775-
// If we don't actually want any values, then just return.
776-
if (num == 0) {
777-
return YJIT_KEEP_COMPILING;
778-
}
779-
780775
// Move the array from the stack into REG0 and check that it's an array.
781776
mov(cb, REG0, array_opnd);
782777
guard_object_is_heap(cb, REG0, ctx, COUNTED_EXIT(side_exit, expandarray_not_array));
783778
guard_object_is_array(cb, REG0, REG1, ctx, COUNTED_EXIT(side_exit, expandarray_not_array));
784779

780+
// If we don't actually want any values, then just return.
781+
if (num == 0) {
782+
return YJIT_KEEP_COMPILING;
783+
}
784+
785785
// Pull out the embed flag to check if it's an embedded array.
786786
x86opnd_t flags_opnd = member_opnd(REG0, struct RBasic, flags);
787787
mov(cb, REG1, flags_opnd);

0 commit comments

Comments
 (0)
0