[前][次][番号順一覧][スレッド一覧]

ruby-changes:60118

From: Takashi <ko1@a...>
Date: Wed, 19 Feb 2020 16:19:23 +0900 (JST)
Subject: [ruby-changes:60118] c4794ed73a (master): Avoid jumping to a wrong destination

https://git.ruby-lang.org/ruby.git/commit/?id=c4794ed73a

From c4794ed73ad348a61a7cfbe3da0a7eb49ba46eb9 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Tue, 18 Feb 2020 23:16:19 -0800
Subject: Avoid jumping to a wrong destination

when the next insn is already compiled by former branches.

diff --git a/test/ruby/test_jit.rb b/test/ruby/test_jit.rb
index a8ce18b..f3dca57 100644
--- a/test/ruby/test_jit.rb
+++ b/test/ruby/test_jit.rb
@@ -828,6 +828,16 @@ class TestJIT < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_jit.rb#L828
     end;
   end
 
+  def test_jump_to_precompiled_branch
+    assert_eval_with_jit("#{<<~'begin;'}\n#{<<~'end;'}", stdout: ".0", success_count: 1, min_calls: 1)
+    begin;
+      def test(foo)
+        ".#{foo unless foo == 1}" if true
+      end
+      print test(0)
+    end;
+  end
+
   def test_clean_so
     if RUBY_PLATFORM.match?(/mswin/)
       skip 'Removing so file is randomly failing on AppVeyor/RubyCI mswin due to Permission Denied.'
diff --git a/tool/ruby_vm/views/_mjit_compile_insn.erb b/tool/ruby_vm/views/_mjit_compile_insn.erb
index b2dea03..8f45121 100644
--- a/tool/ruby_vm/views/_mjit_compile_insn.erb
+++ b/tool/ruby_vm/views/_mjit_compile_insn.erb
@@ -76,9 +76,14 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_mjit_compile_insn.erb#L76
     }
     fprintf(f, "}\n");
 %
-% # compiler: If insn has conditional JUMP, the branch which is not targeted by JUMP should be compiled too.
+% # compiler: If insn has conditional JUMP, the code should go to the branch not targeted by JUMP next.
 % if insn.expr.expr =~ /if\s+\([^{}]+\)\s+\{[^{}]+JUMP\([^)]+\);[^{}]+\}/
-    compile_insns(f, body, b->stack_size, pos + insn_len(insn), status);
+    if (ALREADY_COMPILED_P(status, pos + insn_len(insn))) {
+        fprintf(f, "goto label_%d;\n", pos + insn_len(insn));
+    }
+    else {
+        compile_insns(f, body, b->stack_size, pos + insn_len(insn), status);
+    }
 % end
 %
 % # compiler: If insn returns (leave) or does longjmp (throw), the branch should no longer be compiled. TODO: create attr for it?
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]