From 68bcca4c2bfa716b965554057b098cefcba00f66 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Thu, 21 Dec 2023 15:45:10 -0800 Subject: [PATCH] RJIT: Fix unwanted shadowing in set_local_type local_idx should not be overwritten. --- bootstraptest/test_rjit.rb | 14 ++++++++++++++ lib/ruby_vm/rjit/context.rb | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/bootstraptest/test_rjit.rb b/bootstraptest/test_rjit.rb index 464af7a6e6..e123f35160 100644 --- a/bootstraptest/test_rjit.rb +++ b/bootstraptest/test_rjit.rb @@ -42,3 +42,17 @@ assert_equal '1', %q{ entry } + +# Updating local type in Context +assert_normal_exit %q{ + def foo(flag, object) + klass = if flag + object + end + klass ||= object + return klass.new + end + + foo(false, Object) + foo(true, Object) +} diff --git a/lib/ruby_vm/rjit/context.rb b/lib/ruby_vm/rjit/context.rb index 66da478c7f..c34572ecf1 100644 --- a/lib/ruby_vm/rjit/context.rb +++ b/lib/ruby_vm/rjit/context.rb @@ -264,9 +264,9 @@ module RubyVM::RJIT # noop in MapToSelf # noop - in MapToLocal[local_idx] - if stack_idx == local_idx - self.temp_types[stack_idx] = self.local_types[local_idx]; + in MapToLocal[temp_local_idx] + if stack_idx == temp_local_idx + self.temp_types[stack_idx] = self.local_types[temp_local_idx] self.temp_mapping[stack_idx] = MapToStack else # noop