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

    <tr>
        <th>Summary</th>
        <td>
            [coverage] -fprofile-list cannot be used to ignore non-emitted code
        </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>
    It appears `-fprofile-list` cannot be used to ignore coverage for non-emitted code. Here's an example (LLVM 17.0.6):

```c
// discard.c
static int foo() {
    return 55;
}

int main() {
    foo();
    return 0;
}
```

```
# ignore.list
!fun:foo
```

```bash
# build.sh
clang -fprofile-instr-generate -fcoverage-mapping discard.c -o discard -fprofile-list=ignore.list -mllvm -enable-name-compression=false
./discard
llvm-profdata merge -sparse default.profraw -o default.profdata
llvm-cov show ./discard -instr-profile=default.profdata
llvm-objdump -j__llvm_prf_names -s discard
```

Running it as above:

```shell
$ ./build.sh
    1|       |static int foo() {
    2|       |    return 55;
    3|       |}
    4|       |
    5|      1|int main() {
 6|      1|    foo();
    7|      1|    return 0;
    8| 1|}


discard:        file format elf64-x86-64
Contents of section __llvm_prf_names:
 2091f8 04006d61 696e ..main
```

Notice two details:

- There is no coverage reporting for `foo()`.
- There is no name `foo` in `__llvm_prf_names`.

But when we remove the call to `foo()` from `main()`:

```shell
$ ./build.sh
    1|      0|static int foo() {
    2|      0|    return 55;
    3|      0|}
    4|       |
 5|      1|int main() {
    6|       |    //foo();
    7|      1| return 0;
    8|      1|}


discard:        file format elf64-x86-64
Contents of section __llvm_prf_names:
 2091f8 12006d61 696e0164 69736361 72642e63  ..main.discard.c
 209208 3a666f6f :foo
```

- There **is** now coverage reporting for `foo()`.
- The name `foo` **is** present in `__llvm_prf_names`.

This seems like a bug with `-fprofile-list`. Or, if not via that flag, how can uncalled code be explicitly ignored such that it is not instrumented for coverage reports and associated data is not emitted to the various coverage sections?

cc @ZequanWu 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVl2L6zYT_jXKzWAjy4kcX-Riz4bwvnDaQjm00JtFtse2trLkSnJyzr8v8keSzWZ70lJoCDIazYzm4xnNCOdkoxF3ZPOJbPYrMfjW2N3r4LzUpai-rQpTfdv934PoexTWAeE0qntraqkwUtJ5wimUQmvjoUAYHFbgDchGG4tQmiNa0SDUxoI2OsJOeo8VlKbCGP6HFgnLHAgN-FV0vUIgbPv58y8_QJLFNOaE5SR9InRP6LJyOv3Lec8OhB2gkq4UtopnqvPCyxKk9lAbQ9iWsBxI9mk6BQCw6AerYbMh6Uwl2f76oiDbCanvCZ91noWvVNI7Ghej73qyOJLOYYvHuM7EpB40SZ_CjQ-oKoRrL-qKQaoqXiilErqBS_akdt5GDWq0wiNE9ZKtqBN9L3VzCSpEZtnATfrT_ZXREHVKHTuIUItCYaRFh1Fput6ic9Joku5roRxOBsWEHWatEyHIRkF7JbyADm2DELleWIdQYS0G5eNwbMVptOiKFCSulJTmCK41J7i6A2aPZ_NJuv8LBaZ4rYauh-j15SUQXnpbvwR3HEQO3lh9NyM_D1qHEEoPwoEozBE_ArJrUaklaevR4reJC9hKSPYM049kz9-HN3vDfx_wgZq-4TsDNuzXb4_O9M2ZHoz6sEz4G7aPqyZ7x_eujgJxGw6Taxuv1yUh6dNsMYQUh2enEx5Q1Xwdfd3yiK8n_mejPWrvwNTgsPTSaLhN9DlfwGie1Fuga0p5xRPgOUeI49HtjyHwo_GyRPCngFQvpHI3CIjgS4sWQTrQ5vJWWuyN9QE84dUknF7ixml8TzSYuzByClKHzTt3zsLT-mnwcGpRwylc2Zkjgm8RSqFUeMFv7oXami4QL7kO7v47kKZ_E9L0QUjThyD9IJ4BriC9FNXUfR4C9seoPvP8d9BO2BW0acLXwPMs5SlPIGN8zZCnMCM-vmm1QQWjW0gF57zmNXy3Wy3gJeyJsCfppi9oc_oHRXAL_hulofOg9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