Project

General

Profile

Bug #16397

Line coverage is broken for until and while after guard clause

Added by puchuu (Andrew Aladjev) about 2 months ago. Updated about 2 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
2.6.5
[ruby-core:96088]

Description

Hello. I was working on ruby gem and received a bug with simplecov. See the following coverage report for stream reader. Simplecov uses line coverage report from ruby vm.

Today I've finally found a way to extract this bug from gem source. Please use ruby 2.6.5 to run ruby test.rb. The result will be [1, nil, 1, nil, 0, nil, 1]. The right result is [1, nil, 1, nil, 1, nil, 1].

We can workaround this bug by adding puts after guard clause. Another workaround is to rewrite inline until using loop do + break if. But guard case is the key. It breaks vm or vm trace system.

I will continue to investigate vm system. The suspicious thing is the method of calculating line number use pos-1 because PC points next instruction at the beginning of instruction but I am not sure.


Files

test.rb (78 Bytes) test.rb puchuu (Andrew Aladjev), 12/03/2019 09:25 PM
cov.rb (67 Bytes) cov.rb puchuu (Andrew Aladjev), 12/03/2019 09:25 PM

Related issues

Is duplicate of Ruby master - Bug #15980: Coverage shows while/until after raise if/unless as uncovered lineClosedActions

Associated revisions

Revision f9e5c74c
Added by mame (Yusuke Endoh) about 2 months ago

compile.c: stop wrong peephole optimization when covearge is enabled

jump-jump optimization ignores the event flags of the jump instruction
being skipped, which leads to overlook of line events.

This changeset stops the wrong optimization when coverage measurement is
neabled and when the jump instruction has any event flag.

Note that this issue is not only for coverage but also for TracePoint,
and this change does not fix TracePoint.
However, fixing it fundamentally is tough (which requires revamp of
the compiler). This issue is critical in terms of coverage measurement,
but minor for TracePoint (ko1 said), so we here choose a stopgap
measurement.

[Bug #15980] [Bug #16397]

Note for backporters: this changeset can be viewed by git diff -w.

History

#1

Updated by jeremyevans0 (Jeremy Evans) about 2 months ago

  • Is duplicate of Bug #15980: Coverage shows while/until after raise if/unless as uncovered line added
#2

Updated by mame (Yusuke Endoh) about 2 months ago

  • Status changed from Open to Closed

Applied in changeset git|f9e5c74cd24025a5aa19e318e8fecabf207f1b7b.


compile.c: stop wrong peephole optimization when covearge is enabled

jump-jump optimization ignores the event flags of the jump instruction
being skipped, which leads to overlook of line events.

This changeset stops the wrong optimization when coverage measurement is
neabled and when the jump instruction has any event flag.

Note that this issue is not only for coverage but also for TracePoint,
and this change does not fix TracePoint.
However, fixing it fundamentally is tough (which requires revamp of
the compiler). This issue is critical in terms of coverage measurement,
but minor for TracePoint (ko1 said), so we here choose a stopgap
measurement.

[Bug #15980] [Bug #16397]

Note for backporters: this changeset can be viewed by git diff -w.

Also available in: Atom PDF