[coverage] -fprofile-list cannot be used to ignore non-emitted code
It appears -fprofile-list cannot be used to ignore coverage for non-emitted code. Here's an example (LLVM 17.0.6):
// discard.c
static int foo() {
return 55;
}
int main() {
foo();
return 0;
}
# ignore.list
!fun:foo
# 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:
$ ./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
fooin__llvm_prf_names.
But when we remove the call to foo() from main():
$ ./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
foois 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
Could you please try 18 or main branch? https://godbolt.org should be helpful.
It looks like a bug. This flag was added at https://reviews.llvm.org/D94820. @petrhosek, do you take a look on this?
@EugeneZelenko I couldn't figure out how to get the coverage report generated in Compiler Explorer, but if it's helpful this Godbolt demonstrates the __llvm_prf_names section issue with 18.1.0.