<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 - clang coverage shows incorrect number of macro expansions"
   href="https://bugs.llvm.org/show_bug.cgi?id=47301">47301</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang coverage shows incorrect number of macro expansions
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>All
          </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>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>zequanwu@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In the following code example, it shows the macro executed 4 times, but it
should be 1. It also generates 4 identical regions, File 1, 4:15 -> 4:24 = #0 ,
which I believe is the cause for that.



$ clang++ -fcoverage-mapping -fprofile-instr-generate b.cpp -Xclang
-dump-coverage-mapping && ./a.out && llvm-profdata merge -sparse
default.profraw -o a.profdata && llvm-cov show -color ./a.out
-instr-profile=a.profdata  -debug-only=coverage-mapping

main:
  File 0, 3:12 -> 7:2 = #0
  Expansion,File 0, 5:5 -> 5:6 = #0 (Expanded file = 1)
  File 1, 4:15 -> 4:24 = #0
  File 1, 4:15 -> 4:24 = #0
  File 1, 4:15 -> 4:24 = #0
  File 1, 4:15 -> 4:24 = #0
Counter in file 0 3:12 -> 7:2, #0
Counter in file 0 5:5 -> 5:6, Expands to file 1
Counter in file 1 4:15 -> 4:24, #0
Counter in file 1 4:15 -> 4:24, #0
Counter in file 1 4:15 -> 4:24, #0
Counter in file 1 4:15 -> 4:24, #0
Emitting segments for file:
/usr/local/google/home/zequanwu/llvm-project/build/master/b.cpp
Combined regions:
  3:12 -> 7:2 (count=1)
  4:15 -> 4:24 (count=4)
  5:5 -> 5:6 (count=1)
Segment at 3:12 (count = 1), RegionEntry
Segment at 4:15 (count = 4), RegionEntry
Segment at 4:24 (count = 1)
Segment at 5:5 (count = 1), RegionEntry
Segment at 5:6 (count = 1)
Segment at 7:2 (count = 0), Skipped
    1|       |#include <iostream>
    2|       |
    3|      1|int main() {
    4|      4|    #define O std::cout
    5|      1|    O << "" << "" << "";
    6|      1|    return 0;
    7|      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>