[Coverage] Precise region termination with deferred regions (reapply)


[Coverage] Precise region termination with deferred regions (reapply)

The current coverage implementation doesn't handle region termination
very precisely. Take for example an if' statement with a return':

void f() {
  if (true) {
    return; // The `if' body's region is terminated here.
  // This line gets the same coverage as the `if' condition.

If the function `f' is called, the line containing the comment will be
marked as having executed once, which is not correct.

The solution here is to create a deferred region after terminating a
region. The deferred region is completed once the start location of the
next statement is known, and is then pushed onto the region stack.
In the cases where it's not possible to complete a deferred region, it
can safely be dropped.

Testing: lit test updates, a stage2 coverage-enabled build of clang

This is a reapplication but there are no changes from the original commit.
With D36813, the segment builder in llvm will be able to handle deferred
regions correctly.


vedantkSep 8 2017, 11:44 AM
rL312817: [Coverage] Build sorted and unique segments