diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-03 16:00:34 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-03 16:00:34 +0000 |
commit | 91b51140d7f2b79f8fb7d0ea8901de89fa0304d6 (patch) | |
tree | f6bf28a6603ef69e17ec1209788fb17de851693c /compile.c | |
parent | b17da781050f2bd464b7dbff759783e04428f4b4 (diff) |
merge revision(s) 59183,59184: [Backport #13682]
fix return in toplevel rescue/ensure
* compile.c (iseq_compile_each0): throw TAG_RETURN at return in
toplevel rescue/ensure to adjust VM stack properly.
[ruby-core:81777] [Bug #13682]
* vm_insnhelper.c (vm_throw_start): allow return in toplevel
rescue/ensure.
fix return in toplevel ensure
* compile.c (iseq_compile_each0): adjust stack after return in
toplevel ensure, when the value is used.
[ruby-core:81777] [Bug #13682]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@59493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -4647,8 +4647,6 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int poppe CHECK(COMPILE_POPPED(ensr, "ensure ensr", node->nd_ensr)); last = ensr->last; last_leave = last && IS_INSN(last) && IS_INSN_ID(last, leave); - if (!popped && last_leave) - popped = 1; er.begin = lstart; er.end = lend; @@ -4656,13 +4654,16 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int poppe push_ensure_entry(iseq, &enl, &er, node->nd_ensr); ADD_LABEL(ret, lstart); - CHECK(COMPILE_(ret, "ensure head", node->nd_head, popped)); + CHECK(COMPILE_(ret, "ensure head", node->nd_head, (popped | last_leave))); ADD_LABEL(ret, lend); if (ensr->anchor.next == 0) { ADD_INSN(ret, line, nop); } else { ADD_SEQ(ret, ensr); + if (!popped && last_leave) { + ADD_INSN(ret, line, putnil); + } } ADD_LABEL(ret, lcont); if (last_leave) ADD_INSN(ret, line, pop); @@ -5476,15 +5477,23 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int poppe if (is) { enum iseq_type type = is->body->type; const rb_iseq_t *parent_iseq = is->body->parent_iseq; - enum iseq_type parent_type = parent_iseq ? parent_iseq->body->type : type; + enum iseq_type parent_type; - if (type == ISEQ_TYPE_TOP || type == ISEQ_TYPE_MAIN || - ((type == ISEQ_TYPE_RESCUE || type == ISEQ_TYPE_ENSURE) && - (parent_type == ISEQ_TYPE_TOP || parent_type == ISEQ_TYPE_MAIN))) { + if (type == ISEQ_TYPE_TOP || type == ISEQ_TYPE_MAIN) { ADD_ADJUST(ret, line, 0); ADD_INSN(ret, line, putnil); ADD_INSN(ret, line, leave); } + else if ((type == ISEQ_TYPE_RESCUE || type == ISEQ_TYPE_ENSURE) && + parent_iseq && + ((parent_type = parent_iseq->body->type) == ISEQ_TYPE_TOP || + parent_type == ISEQ_TYPE_MAIN)) { + ADD_INSN(ret, line, putnil); + ADD_INSN1(ret, line, throw, INT2FIX(TAG_RETURN)); + if (popped) { + ADD_INSN(ret, line, pop); + } + } else { LABEL *splabel = 0; |