<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/144416>144416</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [coverage] incorrect coverage for lines following conditional terminating statements
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            coverage
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          justincady
      </td>
    </tr>
</table>

<pre>
    Code coverage reporting is incorrect in situations like this:

```
// coverage.c
#include <stdio.h>

int main(int argc, char *argv[])
{
 {
        if (argc > 2) {
            return 2;
        }
 printf("one\n");
    }
    printf("two\n");
    return 0;
}
```

The expectation is without additional arguments both "one" and "two" will be printed and both print statements will be reported as covered, but:

```
# build.sh
/usr/bin/clang --version | /bin/grep "clang version"
/usr/bin/clang -fprofile-instr-generate -fcoverage-mapping coverage.c -o coverage
./coverage
/usr/bin/llvm-profdata merge -sparse default.profraw -o default.profdata
/usr/bin/llvm-cov show ./coverage -instr-profile=default.profdata
```

The coverage report incorrectly marks the second `printf` statement as uncovered:

```
$ ./build.sh
clang version 21.0.0
one
two
    1|       |#include <stdio.h>
    2|       |
 3|       |int main(int argc, char *argv[])
    4|      1|{
    5|      1| {
    6|      1|        if (argc > 2) {
    7|      0|            return 2;
    8|      0|        }
    9|      1|        printf("one\n");
 10|      1|    }
   11|      0|    printf("two\n"); // INCORRECT
   12| 1|    return 0;
   13|      1|}
```

It appears related to the region-terminating statement in the conditional. The same behavior appears with `abort()` or `goto` instead of `return 2`, for example. But the behavior disappears if the statement is non-region-terminating:

```
$ ./build.sh
clang version 21.0.0
one
two
    1|       |#include <stdio.h>
    2|       |
    3|       |int main(int argc, char *argv[])
 4|      1|{
    5|      1|    {
    6|      1|        if (argc > 2) {
 7|      0|            printf("zero\n"); // NO LONGER TERMINATING
    8| 0|        }
    9|      1|        printf("one\n");
   10|      1| }
   11|      1|    printf("two\n"); // NOW CORRECT
   12|      1| return 0;
   13|      1|}
```

I have not narrowed down if this is a region mapping issue versus an llvm-cov reporting issue.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVk1v2zgT_jX0ZWCBouSvgw-uExcB3tcBggB7psSRxFYmBZKy2_31i5Fk2U6cbtvdwxoCEg7ng8N5nuFI73VpENds9onNHiayDZV16y-tD9rkUn2fZFZ9X2-tQsjtEZ0sERw21gVtStAetMmtc5gH0Aa8Dq0M2hoPtf6KECrtWbJhvPvmfPj4hokdE7vRZZR3skSbvG4VAku2Pihto4olj721NgEOUhsmlvSvdGXOxBbySjpgYiNdeexzYGJFFotPjG9g-DP8dAFMLMkUWPIIgonVGw36OQytMyBYcr3DFg-0apw2oWBiyYSwBtlsa5ggRxftQRPgRjmc7D3lIRjvJb3pzUXxzWuFgN8azEN3tXTpJx0q2waQSmmSyZoupD2gCR4yGyoYjicESKNgiC8EnHRdQ4b90VB1u51BJwAfZMDezVmzrzap-r5eqOjiszZ8UNkEslbXKvJVX-jWOyZ2GZVul9fSlDCdHtF5yoUttjBulg4bOmqvNKjQhX3kpmicLXSNU218cNMSDToZEKbFGVjTg2waQuoFaTC144rxTUTuLss3ger6eJhSFCWDhAO6EmHqG-k8gsJCtnWIaNvJE_m9FpHFBw5zewRf2RNcB4chiyEnljzc8_YeGm9oeSFk_R0O0n31ECoEj7klIMz5AMo5vxSbStuac3HvVzXtDntV2ZsqgYgjHpEmoY5vCG09wGMq8ZlC2x9wnDTErTLfQHIj-cUmQFbp6IBOcmH77EZ-1Qbmtxs_1ToWoya_srnfTJZ3dS9NY3U3_t_1nZi_MxtdxvG7kD_qTDA056f99vnl5XH7OnjpinN2ddu3aDt5c9F3OtlTANk0KJ0Hh7WkphJsB0-HpbZmGtAdtJHd23JBpzadDgF46HYREPK9PCBkWMmjtm70TL2RcC4z60KX4YrAbh0JSxssrYhqKBXYgqRjkeac4FRYB_hNHpoaI_jUhi76GEdpfw6li55bl5N6MNZM32fz3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