<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 - line coverage shows coverage of unreachable whitespace in switch statements"
   href="https://bugs.llvm.org/show_bug.cgi?id=44011">44011</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>line coverage shows coverage of unreachable whitespace in switch statements
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>hans@chromium.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>efriedma@quicinc.com, htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, vsk@apple.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Example:

$ cat /tmp/c.c
int main(int argc, char **argv) {
  switch (argc) {

  case 1:
    return 0;

  default:
    return 1;
  }
}

$ bin/clang -fcoverage-mapping -fprofile-instr-generate /tmp/c.c -Xclang
-dump-coverage-mapping && ./a.out && bin/llvm-profdata merge default.profraw -o
default.profdata && bin/llvm-cov show a.out -instr-profile=default.profdata
main:
  File 0, 1:33 -> 10:2 = #0
  File 0, 4:3 -> 5:13 = #2
  File 0, 7:3 -> 8:13 = #3
    1|      1|int main(int argc, char **argv) {
    2|      1|  switch (argc) {
    3|      1|
    4|      1|  case 1:
    5|      1|    return 0;
    6|      1|
    7|      1|  default:
    8|      0|    return 1;
    9|      1|  }
   10|      1|}


Note how lines 3 and 6 are shown as covered, even though control can never pass
through those lines.
Line 7 is also marked as executed, though a color terminal reveals it's only
the whitespace before "default" that was hit.

I think what's happening is that the whitespace inside the switch ends up in
region #0, which is used for the function body, which is obviously marked
executed.


Looking at <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - Line coverage counts in coverage reports coverage for whitespace instead of code"
   href="show_bug.cgi?id=34612">https://bugs.llvm.org/show_bug.cgi?id=34612</a>, perhaps the fix here is
to insert "gap" regions in between the switch cases. Or, would it work if we
emitted one big "gap" region for the whole switch body, kind of nested
underneath the regions for the cases?

+eli and +vedant who seem familiar with this area.



There are several similar bugs. I'm guessing most are due to the same problem:
<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [LLVM-COV] wrong coverage with switch-case statement"
   href="show_bug.cgi?id=37072">https://bugs.llvm.org/show_bug.cgi?id=37072</a>
<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [LLVM-COV] wrong coverage with switch-case statement when some case is empty"
   href="show_bug.cgi?id=37124">https://bugs.llvm.org/show_bug.cgi?id=37124</a>
<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [LLVM-COV] A "break;" statement is wrongly marked as executed when it is after the "abort();" statement in switch-case"
   href="show_bug.cgi?id=41821">https://bugs.llvm.org/show_bug.cgi?id=41821</a>


(This was reported in Chromium: <a href="https://crbug.com/1024987">https://crbug.com/1024987</a>)</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>