[PATCH] D83592: [Parser] Add comment to skipped regions

Zequan Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 16 12:35:17 PDT 2020


zequanwu added a comment.

In D83592#2151773 <https://reviews.llvm.org/D83592#2151773>, @zequanwu wrote:

> In D83592#2151217 <https://reviews.llvm.org/D83592#2151217>, @vsk wrote:
>
> > Could you add an end-to-end llvm-cov test (see e.g. compiler-rt/test/profile/Linux/coverage_ctors.cpp)? Here are some important cases I think we should check:
> >
> > - `/* comment at the start of a line */ expr;`
> > - `expr; /* comment at the end of a line */`
> > - `expr; // comment at the end of a line`
> > - `// comment spanning entire line`
> >
> >   In all but the last case, llvm-cov should report an execution count for the line. Testing multi-line variations of those cases would also be helpful.
>
>
> llvm-cov doesn't report the execution count for the first 3 liens... I will try to fix that.


The problem is that simply marking comment regions as `SkippedRegion` doesn't give enough information for `llvm-cov` about if there is code area before or after comments in the same line.

  $ clang++ -fcoverage-mapping -fprofile-instr-generate /tmp/a.cpp -Xclang -dump-coverage-mapping && ./a.out && llvm-profdata merge -sparse default.profraw -o a.profdata && llvm-cov show ./a.out -instr-profile=a.profdata -debug-only="coverage-mapping"
  main:
    File 0, 1:12 -> 7:2 = #0
    Skipped,File 0, 2:3 -> 2:39 = 0
    Skipped,File 0, 3:15 -> 3:49 = 0
    Skipped,File 0, 4:15 -> 4:46 = 0
    Skipped,File 0, 5:3 -> 5:34 = 0
  Counter in file 0 1:12 -> 7:2, #0
  Counter in file 0 2:3 -> 2:39, 0
  Counter in file 0 3:15 -> 3:49, 0
  Counter in file 0 4:15 -> 4:46, 0
  Counter in file 0 5:3 -> 5:34, 0
  Emitting segments for file: /tmp/a.cpp
  Combined regions:
    1:12 -> 7:2 (count=1)
    2:3 -> 2:39 (count=0)
    3:15 -> 3:49 (count=0)
    4:15 -> 4:46 (count=0)
    5:3 -> 5:34 (count=0)
  Segment at 1:12 (count = 1), RegionEntry
  Segment at 2:3 (count = 0), RegionEntry, Skipped
  Segment at 2:39 (count = 1)
  Segment at 3:15 (count = 0), RegionEntry, Skipped
  Segment at 3:49 (count = 1)
  Segment at 4:15 (count = 0), RegionEntry, Skipped
  Segment at 4:46 (count = 1)
  Segment at 5:3 (count = 0), RegionEntry, Skipped
  Segment at 5:34 (count = 1)
  Segment at 7:2 (count = 0), Skipped
      1|      1|int main() {
      2|       |  /* comment at the start of a line */ int x = 0;
      3|       |  int y = 0;  /* comment at the end of a line */
      4|       |  int z = 0;  // comment at the end of a line
      5|       |  // comment spanning entire line
      6|      1|  return 0;
      7|      1|}
      8|       |

One way I could think is probably when we visit decl in `CounterCoverageMappingBuilder`, check for if there is `SkippedRegion` in the same line and then mark the decl range as `CodeRegion`. For the example, we will have 3 more `CodeRegion` which covers the ranges of `int x = 0`, `int y = 0` and `int z = 0`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83592/new/

https://reviews.llvm.org/D83592





More information about the cfe-commits mailing list