From 11c37ed390478393b0ba9b7afd41c92aae27ae05 Mon Sep 17 00:00:00 2001 From: shugo Date: Sat, 5 Nov 2016 16:42:27 +0000 Subject: [PATCH] * compile.c (tailcallable_p): disable tail call optimization for toplevel, eval, and load to avoid SEGV when interrupted by SIGINT. [ruby-core:76327] [Bug #12576] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ compile.c | 4 ++++ test/ruby/test_optimization.rb | 27 +++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/ChangeLog b/ChangeLog index 29a6001d40..2e7e03c43e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Nov 6 01:39:36 2016 Shugo Maeda + + * compile.c (tailcallable_p): disable tail call optimization for + toplevel, eval, and load to avoid SEGV when interrupted by SIGINT. + [ruby-core:76327] [Bug #12576] + Sun Nov 6 01:28:41 2016 Koichi Sasada * vm_insnhelper.h: rename REG_(CFP|PC|SP|EP) to VM_REG_.... diff --git a/compile.c b/compile.c index bdeb7fdac2..b113b08df4 100644 --- a/compile.c +++ b/compile.c @@ -2423,6 +2423,10 @@ static inline int tailcallable_p(rb_iseq_t *iseq) { switch (iseq->body->type) { + case ISEQ_TYPE_TOP: + case ISEQ_TYPE_EVAL: + case ISEQ_TYPE_MAIN: + /* not tail callable because cfp will be over popped */ case ISEQ_TYPE_RESCUE: case ISEQ_TYPE_ENSURE: /* rescue block can't tail call because of errinfo */ diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb index 89a9753f0e..c035a112cb 100644 --- a/test/ruby/test_optimization.rb +++ b/test/ruby/test_optimization.rb @@ -316,6 +316,33 @@ class TestRubyOptimization < Test::Unit::TestCase message(bug12565) {disasm(:add_one_and_two)}) end + def test_tailcall_interrupted_by_sigint + bug = 'ruby-core:76327' + script = < true, + :trace_instruction => false +} + +eval <