<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [[LLVM-COV] #if #endif in the source code lead to incorrect coverage report when exit() statement follows "while() ;""
   href="https://bugs.llvm.org/show_bug.cgi?id=41849">41849</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[[LLVM-COV] #if #endif in the source code lead to incorrect coverage report when exit() statement follows "while() ;"
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Runtime Libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>libprofile library
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>yangyibiao@nju.edu.cn
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ clang -v
clang version 9.0.0-svn358899-1~exp1+0~20190422164136.937~1.gbpac4d8e (trunk)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64


$ cat small.c
extern void abort (void);
extern void exit (int);

int
main (void)
{
#if __INT_MAX__ >= 2147483647
  struct { int count: 31; } s = { 0 };
  while (s.count--)
    ; // abort ();
#elif __INT_MAX__ >= 32767
  abort(1);
#else
#endif
  exit (2);
}



$ clang -w -O0 -g -fcoverage-mapping -fprofile-instr-generate=small.profraw
small.c; ./a.out; echo $?; llvm-profdata merge small.profraw -o small.profdata;
llvm-cov show a.out -instr-profile=small.profdata small.c > small.c.lcov; cat
small.c.lcov
2
    1|       |extern void abort (void);
    2|       |extern void exit (int);
    3|       |
    4|       |int
    5|       |main (void)
    6|      1|{
    7|      1|#if __INT_MAX__ >= 2147483647
    8|      1|  struct { int count: 31; } s = { 0 };
    9|      1|  while (s.count--)
   10|      0|    ; // abort ();
   11|       |#elif __INT_MAX__ >= 32767
   12|       |  abort(1);
   13|       |#else
   14|       |#endif
   15|       |  exit (2);
   16|      1|}

Line # 15 is marked as "" which indicates that it is not an instrumentation
site.
However, we can found that the exit code of this program is 2. Thus we can
determine that line #15 is executed during this execution. 

When Line #10 is not removed, Line #15 is marked as executed once as follows. 

$ clang -w -O0 -g -fcoverage-mapping -fprofile-instr-generate=small.profraw
small.c; ./a.out; echo $?; llvm-profdata merge small.profraw -o small.profdata;
llvm-cov show a.out -instr-profile=small.profdata small.c > small.c.lcov; cat
small.c.lcov
2
    1|       |extern void abort (void);
    2|       |extern void exit (int);
    3|       |
    4|       |int
    5|       |main (void)
    6|      1|{
    7|      1|#if __INT_MAX__ >= 2147483647
    8|      1|  struct { int count: 31; } s = { 0 };
    9|      1|  while (s.count--)
   10|      0|    abort ();
   11|       |#elif __INT_MAX__ >= 32767
   12|       |  abort(1);
   13|       |#else
   14|       |#endif
   15|      1|  exit (2);
   16|      1|}</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>