[PATCH] D35925: [Coverage] Precise region termination with deferred regions

Vedant Kumar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 26 19:07:29 PDT 2017


vsk created this revision.

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.

Example output (pre-patch): F3800158: deferred-regions-before.txt <https://reviews.llvm.org/F3800158>
Example output (post-patch): F3800159: deferred-regions-after.txt <https://reviews.llvm.org/F3800159>

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


https://reviews.llvm.org/D35925

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/deferred-region.cpp
  test/CoverageMapping/label.cpp
  test/CoverageMapping/moremacros.c
  test/CoverageMapping/return.c
  test/CoverageMapping/switch.cpp
  test/CoverageMapping/switchmacro.c
  test/CoverageMapping/trycatch.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35925.108407.patch
Type: text/x-patch
Size: 19345 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170727/dd45cb0b/attachment-0001.bin>


More information about the cfe-commits mailing list