ruby-changes:54461
From: mame <ko1@a...>
Date: Tue, 1 Jan 2019 12:03:22 +0900 (JST)
Subject: [ruby-changes:54461] mame:r66676 (trunk): compile.c (iseq_set_sequence): fix branch coverage table
mame 2019-01-01 12:03:17 +0900 (Tue, 01 Jan 2019) New Revision: 66676 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66676 Log: compile.c (iseq_set_sequence): fix branch coverage table Not only TRACE_ELEMENT but also INSN_ELEMENT may have events. The old pc2branchindex was created using only events of TRACE_ELEMENTs. This change uses events of INSN_ELEMENTs too for pc2branchindex table. [Bug #15476] Modified files: trunk/compile.c trunk/test/coverage/test_coverage.rb Index: test/coverage/test_coverage.rb =================================================================== --- test/coverage/test_coverage.rb (revision 66675) +++ test/coverage/test_coverage.rb (revision 66676) @@ -167,6 +167,20 @@ class TestCoverage < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/coverage/test_coverage.rb#L167 end; end + def test_coverage_optimized_branch + result = { + :branches => { + [:"&.", 0, 1, 0, 1, 8] => { + [:then, 1, 1, 0, 1, 8] => 1, + [:else, 2, 1, 0, 1, 8] => 0, + }, + }, + } + assert_coverage(<<~"end;", { branches: true }, result) # Bug #15476 + nil&.foo + end; + end + def assert_coverage(code, opt, stdout) stdout = [stdout] unless stdout.is_a?(Array) stdout = stdout.map {|s| s.to_s } Index: compile.c =================================================================== --- compile.c (revision 66675) +++ compile.c (revision 66676) @@ -2061,6 +2061,7 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L2061 /* update sp */ sp = calc_sp_depth(sp, iobj); insn_num++; + events = iobj->insn_info.events |= events; if (ISEQ_COVERAGE(iseq)) { if (ISEQ_LINE_COVERAGE(iseq) && (events & RUBY_EVENT_COVERAGE_LINE) && !(rb_get_coverage_mode() & COVERAGE_TARGET_ONESHOT_LINES)) { @@ -2077,7 +2078,6 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L2078 } } code_index += insn_data_length(iobj); - iobj->insn_info.events |= events; events = 0; data = 0; break; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/