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

    <tr>
        <th>Summary</th>
        <td>
            [coverage] __noreturn__ attribute leads to incorrect coverage report
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    The `__noreturn__` attribute appears to invalidate coverage of the following line, whereas `_Noreturn` demonstrates correct behavior.

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

__attribute__ ((__noreturn__)) void foo(void) { while (1); }
_Noreturn void bar(void) { while (1); }

int main(int argc, char **argv) {
    int rc = ({ if (argc > 3) foo(); 0; });
    printf("coverage after foo is missing\n");

 int rc2 = ({ if (argc > 3) bar(); 0; });
    printf("coverage after bar is present\n");
    return rc + rc2;
}
```

```bash
# 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
```

Running the script:

```
$ ./build.sh
clang version 19.1.1 (Red Hat, Inc. 19.1.1-5.el10)
coverage after foo is missing
coverage after bar is present
    1|       |#include <stdio.h>
    2|       |
    3|      0|__attribute__ ((__noreturn__)) void foo(void) { while (1); }
    4|      0|_Noreturn void bar(void) { while (1); }
    5|       |
    6|      1|int main(int argc, char **argv) {
    7| 1|    int rc = ({ if (argc > 3) foo(); 0; });
    8|      0| printf("coverage after foo is missing\n");
    9|       |
   10|      1| int rc2 = ({ if (argc > 3) bar(); 0; });
   11|      1| printf("coverage after bar is present\n");
   12|      1|    return rc + rc2;
   13|      1|}

$
```

- Line 8 is reported as uncovered, though it prints as expected. (incorrect behavior)
- Line 11 is reported as covered, and prints as expected. (correct behavior)

This seems like a bug connected to `__noreturn__`. FWIW I also tested this in C++ and observed the same results.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0Vk2P4jgQ_TXmUiJKHELgwIGPQTvSag-jkeaInLiSeNbYke3Azr9fVRLSQHfPrnpnEYfYrnr1qlx-tvBe1QZxw7Idyw4z0YXGus33zgdlSiF_zAorf2y-NghsGZ9OxjoMnTOnE1vGIEJwqugCgmhbFM5DsKDMRWglRUAo7QWdqBFsBaFBqKzW9qpMDVoZZHwP1wYdCt-D_zFiE7LEszU-OBHQQ2mdwzJAgY24KOsiFm_pv4yHf0kDfmT8OEWMhrlUmVJ3EoGlex-kslHD0k-D--k00T-dgPEV46uHBPma8TVcrJJQWcv4ij5piuU7uDZKI3klZJfugOUHAr0lMfgVwv07PxZvlQlwFsowvqJP4eqSKlQ2wgHjW8a3wtWXEYfFWwAAMnQlsPTQJ5DvQFX0Rc7A0k-Qkv3AfowX34L2wxGndcqEqjfi06aJKqAjZ1Aezsp7ZWqW7Q3jfHIm_4EE_ycWQy0-yKIQjli0Dj2a8MyCnMeyUzX4jviMBIfy3lrlqXMK4ZuhUaDolJbRODx23jF-LGg3jqUWpob5_ILOK2uA5XuYFmuHLRDf3mg0IW7vwVSts5XSOFfU3_MaDVKXw7y6pTw_i7alQ_LSzDC304jF24jgXoZPgbS-nOcURYog4IyuRpj7VjiPILESnQ4RLTtxJdz7KfJ4B7C0F_CNvcJ9cBizGHNi6eEttMfif-mMoexIEHzpVBtYun3al57Dog91ty8PNYZkHSVRQn32BSX8JgKdls-mjMaVeRahTmJqknj786Z-tf7UbkOHJbTxw4_l-5-IC1nwR-NhMp0mY5bv_xcBIvDFY5gPShL5Z29lsZwmqSIfka2cEG7l_FUatnrI-uOSRgjrN_JO4oe8f5nsJckj7n9RwYQ_Yr2vi2SRPhhPFxHji9endg6_K4OwovgOW-sCShAeOtNzREmbHhrb1Q2oMCThyQD_arEMKCPoO-T5Lh-O54ieJM_wd-DCyPdg3wZl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