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

ruby-changes:47985

From: nobu <ko1@a...>
Date: Mon, 2 Oct 2017 17:33:35 +0900 (JST)
Subject: [ruby-changes:47985] nobu:r60099 (trunk): compile.c: fix stack consitency error

nobu	2017-10-02 17:33:30 +0900 (Mon, 02 Oct 2017)

  New Revision: 60099

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60099

  Log:
    compile.c: fix stack consitency error
    
    * compile.c (iseq_compile_each0): fix stack consitency error on
      attr-assign with safe navigation operator when the receiver is
      nil, should pop it too.  [ruby-core:83078] [Bug #13964]

  Modified files:
    trunk/compile.c
    trunk/test/ruby/test_call.rb
Index: compile.c
===================================================================
--- compile.c	(revision 60098)
+++ compile.c	(revision 60099)
@@ -5415,8 +5415,11 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L5415
 		ADD_INSN1(ret, line, topn, INT2FIX(1));
 	    }
 	    ADD_SEND_WITH_FLAG(ret, line, aid, INT2FIX(1), INT2FIX(asgnflag));
+	    if (lskip && popped) {
+		ADD_LABEL(ret, lskip);
+	    }
 	    ADD_INSN(ret, line, pop);
-	    if (lskip) {
+	    if (lskip && !popped) {
 		ADD_LABEL(ret, lskip);
 	    }
 	}
Index: test/ruby/test_call.rb
===================================================================
--- test/ruby/test_call.rb	(revision 60098)
+++ test/ruby/test_call.rb	(revision 60099)
@@ -52,6 +52,7 @@ class TestCall < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_call.rb#L52
     assert_nil(o&.x)
     assert_nothing_raised(NoMethodError) {o&.x = 6}
     assert_nothing_raised(NoMethodError) {o&.x *= 7}
+    assert_nothing_raised(NoMethodError) {o&.x *= 8; [].each {}}
   end
 
   def test_safe_call_evaluate_arguments_only_method_call_is_made

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

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