From a42be1e048e9dc7eb5e0453beea678dea95e5194 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 27 Jun 2017 06:57:34 +0000 Subject: 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- vm_insnhelper.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'vm_insnhelper.c') diff --git a/vm_insnhelper.c b/vm_insnhelper.c index eea16d730e..b678b02884 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1126,6 +1126,7 @@ vm_throw_start(rb_thread_t *const th, rb_control_frame_t *const reg_cfp, enum ru const VALUE *current_ep = GET_EP(); const VALUE *target_lep = VM_EP_LEP(current_ep); int in_class_frame = 0; + int toplevel = 1; escape_cfp = reg_cfp; while (escape_cfp < eocfp) { @@ -1144,6 +1145,7 @@ vm_throw_start(rb_thread_t *const th, rb_control_frame_t *const reg_cfp, enum ru if (lep == target_lep) { if (VM_FRAME_LAMBDA_P(escape_cfp)) { + toplevel = 0; if (in_class_frame) { /* lambda {class A; ... return ...; end} */ goto valid_return; @@ -1160,6 +1162,20 @@ vm_throw_start(rb_thread_t *const th, rb_control_frame_t *const reg_cfp, enum ru } } } + else if (VM_FRAME_RUBYFRAME_P(escape_cfp)) { + switch (escape_cfp->iseq->body->type) { + case ISEQ_TYPE_TOP: + case ISEQ_TYPE_MAIN: + if (toplevel) goto valid_return; + break; + case ISEQ_TYPE_EVAL: + case ISEQ_TYPE_CLASS: + toplevel = 0; + break; + default: + break; + } + } } if (escape_cfp->ep == target_lep && escape_cfp->iseq->body->type == ISEQ_TYPE_METHOD) { -- cgit v1.2.3