<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: macro leads to wrong code coverage"
   href="https://bugs.llvm.org/show_bug.cgi?id=45844">45844</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>llvm-cov: macro leads to wrong code coverage
          </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>Linux
          </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@hust.edu.cn
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ clang --version
clang version 11.0.0 (/home/yibiao/.cache/yay/llvm-git/llvm-project
871beba234a83a2a02da9dedbd59b91a1bfbd7af)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin


$ clang -O0 -fcoverage-mapping -fprofile-instr-generate=small.profraw small.c;
./a.out; 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
    1|      1|#define INT_MIN (-__INT_MAX__ - 1)
    2|       |
    3|      1|int f(unsigned int u) {
    4|      1|  return (-(int)(u-1U))-1;
    5|      1|}
    6|       |
    7|      1|int main () {
    8|      1|  if(f(__INT_MAX__+1U) != INT_MIN)
    9|      1|    return 0;
   10|      1|  return 1;
   11|      1|}

Line #9 is wrongly marked as executed. This line is not executed in practice as
in lldb this line is not reached as follows:
$ clang -g small.c; lldb a.out
(lldb) target create "a.out"
Current executable set to '/home/yibiao/Decov/a.out' (x86_64).
(lldb) b 9
Breakpoint 1: where = a.out`main + 36 at small.c:9:5, address =
0x0000000000401154
(lldb) run
Process 405847 launched: '/home/yibiao/Decov/a.out' (x86_64)
Process 405847 exited with status = 1 (0x00000001)

$ cat small.c
#define INT_MIN (-__INT_MAX__ - 1)

int f(unsigned int u) {
  return (-(int)(u-1U))-1;
}

int main () {
  if(f(__INT_MAX__+1U) != INT_MIN)
    return 0;
  return 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>