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

        <tr>
          <th>Summary</th>
          <td>llvm-cov: marco in if statement 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>normal
          </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>$ cat test.c
#define MK(A) (A << 2)

int foo(int q)
{
  if (q != MK(2))
    return 0;
  else
    return 1;
}

void main()
{
  int q = MK(2);
  int r = foo(q);
  printf("%d\n", r);
}

$ clang -O0 -w -fcoverage-mapping -fprofile-instr-generate=test.profraw test.c;
./a.out; llvm-profdata merge test.profraw -o test.profdata; llvm-cov show a.out
-instr-profile=test.profdata test.c > test.c.lcov; cat test.c.lcov
1
    1|      2|#define MK(A) (A << 2)
    2|       |
    3|       |int foo(int q)
    4|      1|{
    5|      1|  if (q != MK(2))
    6|      1|    return 0;
    7|      1|  else
    8|      1|    return 1;
    9|      1|}
   10|       |
   11|       |void main()
   12|      1|{
   13|      1|  int q = MK(2);
   14|      1|  int r = foo(q);
   15|      1|  printf("%d\n", r);
   16|      1|}

#################
Line #6 is wrongly marked as executed. When debug this program, Line#6 is not
hit by LLDB.


$ clang --version; llvm-cov --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
LLVM (<a href="http://llvm.org/">http://llvm.org/</a>):
  LLVM version 11.0.0
  Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: skylake</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>