summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2022-12-25 22:48:35 -0800
committerTakashi Kokubun <takashikkbn@gmail.com>2022-12-25 22:48:36 -0800
commitfc03ba50f1ff6c30f7c654f564b4dffbed0844ef (patch)
tree5fa9bffbce44b3db52b977c23664deaf0575eeca
parent39a96b4344c7b0f8bd895a6e81d3dc840ea07e9c (diff)
downloadruby-fc03ba50f1ff6c30f7c654f564b4dffbed0844ef.tar.gz
MJIT: Fix JIT code for multiple values in a single case
[Bug #19263]
-rw-r--r--lib/ruby_vm/mjit/compiler.rb2
-rw-r--r--test/ruby/test_mjit.rb10
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/ruby_vm/mjit/compiler.rb b/lib/ruby_vm/mjit/compiler.rb
index 3ef3babf66..a9f2aeda8d 100644
--- a/lib/ruby_vm/mjit/compiler.rb
+++ b/lib/ruby_vm/mjit/compiler.rb
@@ -536,7 +536,7 @@ class RubyVM::MJIT::Compiler # :nodoc: all
when /\A\s+JUMP\((?<dest>[^)]+)\);\s+\z/
dest = Regexp.last_match[:dest]
if insn.name == :opt_case_dispatch # special case... TODO: use another macro to avoid checking name
- hash_offsets = C.rb_hash_values(operands[0])
+ hash_offsets = C.rb_hash_values(operands[0]).uniq
else_offset = cast_offset(operands[1])
base_pos = pos + insn_len
diff --git a/test/ruby/test_mjit.rb b/test/ruby/test_mjit.rb
index 399bf20071..a97747eb88 100644
--- a/test/ruby/test_mjit.rb
+++ b/test/ruby/test_mjit.rb
@@ -518,6 +518,16 @@ class TestMJIT < Test::Unit::TestCase
end;
end
+ def test_compile_multiple_values_case
+ assert_compile_twice("#{<<~"begin;"}\n#{<<~"end;"}", result_inspect: '"world"', insns: %i[opt_case_dispatch])
+ begin;
+ case 'hello'
+ when 'hello', 'world'
+ 'world'
+ end
+ end;
+ end
+
def test_compile_insn_opt_calc
assert_compile_twice('4 + 2 - ((2 * 3 / 2) % 2)', result_inspect: '5', insns: %i[opt_plus opt_minus opt_mult opt_div opt_mod])
assert_compile_twice('4.0 + 2.0 - ((2.0 * 3.0 / 2.0) % 2.0)', result_inspect: '5.0', insns: %i[opt_plus opt_minus opt_mult opt_div opt_mod])