[Coverage] Precise region termination with deferred regions
authorVedant Kumar <vsk@apple.com>
Fri, 4 Aug 2017 00:29:20 +0000 (00:29 +0000)
committerVedant Kumar <vsk@apple.com>
Fri, 4 Aug 2017 00:29:20 +0000 (00:29 +0000)
commit85e6dce1ebfc714b975a023e59054ab2bdc979bc
tree6ba1f096bcc98e05ea873cc65e26f8640f84cf3c
parent5bd0503680935112f63d0277748ecd9a112a7467
[Coverage] Precise region termination with deferred regions

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
llvm-svn: 310010
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/test/CoverageMapping/deferred-region.cpp [new file with mode: 0644]
clang/test/CoverageMapping/label.cpp
clang/test/CoverageMapping/moremacros.c
clang/test/CoverageMapping/return.c
clang/test/CoverageMapping/switch.cpp
clang/test/CoverageMapping/switchmacro.c
clang/test/CoverageMapping/trycatch.cpp