ruby-changes:46513
From: nagachika <ko1@a...>
Date: Wed, 10 May 2017 00:14:01 +0900 (JST)
Subject: [ruby-changes:46513] nagachika:r58634 (ruby_2_4): merge revision(s) 58398: [Backport #13444]
nagachika 2017-05-10 00:13:55 +0900 (Wed, 10 May 2017) New Revision: 58634 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58634 Log: merge revision(s) 58398: [Backport #13444] compile.c: wrong optimization * compile.c (compile_branch_condition): expression which has side effects should not be eliminated. [ruby-core:80740] [Bug #13444] Modified directories: branches/ruby_2_4/ Modified files: branches/ruby_2_4/compile.c branches/ruby_2_4/test/ruby/test_optimization.rb branches/ruby_2_4/version.h Index: ruby_2_4/compile.c =================================================================== --- ruby_2_4/compile.c (revision 58633) +++ ruby_2_4/compile.c (revision 58634) @@ -2216,7 +2216,7 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/ruby_2_4/compile.c#L2216 OPERAND_AT(pobj, 0) == Qfalse : FALSE); } - else if (IS_INSN_ID(pobj, putstring)) { + else if (IS_INSN_ID(pobj, putstring) || IS_INSN_ID(pobj, duparray)) { cond = IS_INSN_ID(iobj, branchif); } else if (IS_INSN_ID(pobj, putnil)) { @@ -2874,18 +2874,8 @@ compile_branch_condition(rb_iseq_t *iseq https://github.com/ruby/ruby/blob/trunk/ruby_2_4/compile.c#L2874 case NODE_LIT: /* NODE_LIT is always not true */ case NODE_TRUE: case NODE_STR: - case NODE_DSTR: - case NODE_XSTR: - case NODE_DXSTR: - case NODE_DREGX: - case NODE_DREGX_ONCE: - case NODE_DSYM: - case NODE_ARRAY: case NODE_ZARRAY: - case NODE_HASH: case NODE_LAMBDA: - case NODE_DEFN: - case NODE_DEFS: /* printf("useless condition eliminate (%s)\n", ruby_node_name(nd_type(cond))); */ ADD_INSNL(ret, nd_line(cond), jump, then_label); break; Index: ruby_2_4/version.h =================================================================== --- ruby_2_4/version.h (revision 58633) +++ ruby_2_4/version.h (revision 58634) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1 #define RUBY_VERSION "2.4.2" #define RUBY_RELEASE_DATE "2017-05-10" -#define RUBY_PATCHLEVEL 127 +#define RUBY_PATCHLEVEL 128 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 5 Index: ruby_2_4/test/ruby/test_optimization.rb =================================================================== --- ruby_2_4/test/ruby/test_optimization.rb (revision 58633) +++ ruby_2_4/test/ruby/test_optimization.rb (revision 58634) @@ -490,4 +490,47 @@ EOS https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/ruby/test_optimization.rb#L490 bug11816 = '[ruby-core:74993] [Bug #11816]' assert_ruby_status([], 'nil&.foo &&= false', bug11816) end + + def test_branch_condition_backquote + bug = '[ruby-core:80740] [Bug #13444] redefined backquote should be called' + class << self + def `(s) + @q = s + @r + end + end + + @q = nil + @r = nil + assert_equal("bar", ("bar" unless `foo`), bug) + assert_equal("foo", @q, bug) + + @q = nil + @r = true + assert_equal("bar", ("bar" if `foo`), bug) + assert_equal("foo", @q, bug) + + @q = nil + @r = "z" + assert_equal("bar", ("bar" if `foo#{@r}`)) + assert_equal("fooz", @q, bug) + end + + def test_branch_condition_def + bug = '[ruby-core:80740] [Bug #13444] method should be defined' + c = Class.new do + raise "bug" unless def t;:ok;end + end + assert_nothing_raised(NoMethodError, bug) do + assert_equal(:ok, c.new.t) + end + end + + def test_branch_condition_defs + bug = '[ruby-core:80740] [Bug #13444] singleton method should be defined' + raise "bug" unless def self.t;:ok;end + assert_nothing_raised(NameError, bug) do + assert_equal(:ok, t) + end + end end Index: ruby_2_4 =================================================================== --- ruby_2_4 (revision 58633) +++ ruby_2_4 (revision 58634) Property changes on: ruby_2_4 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r58398 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/