ruby-changes:42554
From: nobu <ko1@a...>
Date: Mon, 18 Apr 2016 15:10:27 +0900 (JST)
Subject: [ruby-changes:42554] nobu:r54628 (trunk): compile.c: fix dangling link
nobu 2016-04-18 16:07:03 +0900 (Mon, 18 Apr 2016) New Revision: 54628 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54628 Log: compile.c: fix dangling link * compile.c (iseq_peephole_optimize): should not replace the current target INSN, not to follow the replaced dangling link in the caller. [ruby-core:74993] [Bug #11816] Modified files: trunk/ChangeLog trunk/compile.c trunk/test/ruby/test_optimization.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 54627) +++ ChangeLog (revision 54628) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Apr 18 16:07:01 2016 Nobuyoshi Nakada <nobu@r...> + + * compile.c (iseq_peephole_optimize): should not replace the + current target INSN, not to follow the replaced dangling link in + the caller. [ruby-core:74993] [Bug #11816] + Mon Apr 18 12:56:31 2016 Nobuyoshi Nakada <nobu@r...> * numeric.c (flo_truncate): add an optional parameter, digits, as Index: compile.c =================================================================== --- compile.c (revision 54627) +++ compile.c (revision 54628) @@ -852,6 +852,7 @@ INSERT_ELEM_PREV(LINK_ELEMENT *elem1, LI https://github.com/ruby/ruby/blob/trunk/compile.c#L852 } } +#if 0 /* * elemX, elem1, elemY => elemX, elem2, elemY */ @@ -867,6 +868,7 @@ REPLACE_ELEM(LINK_ELEMENT *elem1, LINK_E https://github.com/ruby/ruby/blob/trunk/compile.c#L868 elem1->next->prev = elem2; } } +#endif static void REMOVE_ELEM(LINK_ELEMENT *elem) @@ -2056,15 +2058,13 @@ iseq_peephole_optimize(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L2058 * LABEL: * leave */ - INSN *eiobj = new_insn_core(iseq, iobj->line_no, BIN(leave), - diobj->operand_size, diobj->operands); INSN *popiobj = new_insn_core(iseq, iobj->line_no, BIN(pop), 0, 0); /* replace */ unref_destination(iobj, 0); - REPLACE_ELEM((LINK_ELEMENT *)iobj, (LINK_ELEMENT *)eiobj); - INSERT_ELEM_NEXT((LINK_ELEMENT *)eiobj, (LINK_ELEMENT *)popiobj); - iobj = eiobj; + iobj->insn_id = BIN(leave); + iobj->operand_size = 0; + INSERT_ELEM_NEXT(&iobj->link, &popiobj->link); goto again; } /* Index: test/ruby/test_optimization.rb =================================================================== --- test/ruby/test_optimization.rb (revision 54627) +++ test/ruby/test_optimization.rb (revision 54628) @@ -424,4 +424,9 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L424 end assert_nil result, '[ruby-dev:49423] [Bug #11804]' end + + def test_nil_safe_conditional_assign + bug11816 = '[ruby-core:74993] [Bug #11816]' + assert_ruby_status([], 'nil&.foo &&= false', bug11816) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/