[PATCH] D23987: [Coverage] Suppress creating a code region if the same area is covered by an expansion region.

Igor Kudrin via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 29 04:49:25 PDT 2016


ikudrin added a comment.

This patch fixes the following issue:

  $ cat > test.cpp << EOF
  void dummy() {}
  
  #define MACRO_1 dummy()
  
  #define MACRO_2 MACRO_1
  
  int main() {
    int i = 0;
    if (i > 5)
      MACRO_2;
  }
  EOF
  $ clang++ -fprofile-instr-generate -fcoverage-mapping dummy.cpp test.cpp
  $ ./a.out
  $ llvm-profdata merge -o default.profdata default.profraw
  $ llvm-cov show a.out -instr-profile --show-expansions default.profdata
      1|      0|void dummy() {}
      2|       |
      3|      0|#define MACRO_1 dummy()
      4|       |
      5|      1|#define MACRO_2 MACRO_1
      6|       |
      7|      1|int main() {
      8|      1|  int i = 0;
      9|      1|  if (i > 5)
     10|      1|    MACRO_2;
    ------------------
    |  |    5|      1|#define MACRO_2 MACRO_1
    |  |  ------------------
    |  |  |  |    3|      0|#define MACRO_1 dummy()
    |  |  ------------------
    ------------------
     11|      1|}

The result of the fixed version:

    1|      0|void dummy() {}
    2|       |
    3|      0|#define MACRO_1 dummy()
    4|       |
    5|      0|#define MACRO_2 MACRO_1
    6|       |
    7|      1|int main() {
    8|      1|  int i = 0;
    9|      1|  if (i > 5)
   10|      0|    MACRO_2;
  ------------------
  |  |    5|      0|#define MACRO_2 MACRO_1
  |  |  ------------------
  |  |  |  |    3|      0|#define MACRO_1 dummy()
  |  |  ------------------
  ------------------
   11|      1|}


https://reviews.llvm.org/D23987





More information about the cfe-commits mailing list