Step 1: Compile with coverage enabled.
clang -fprofile-instr-generate -fcoverage-mapping t.c test.c -o fooStep 2: Run the program
LLVM_PROFILE_FILE="foo.profraw" ./fooStep 3: Show foo.profraw
llvm-profdata show --all-functions --counts foo.profraw
Counters:
printf_1:
Hash: 0x0000000000000000
Counters: 1
Function count: 8
Block counts: []
main:
Hash: 0x00000000000a0458
Counters: 2
Function count: 1
Block counts: [4]
printf_1:
Hash: 0x0000000000000000
Counters: 1
Function count: 8
Block counts: []
test:
Hash: 0x0000000000002811
Counters: 2
Function count: 1
Block counts: [4]
Instrumentation level: Front-end
Functions shown: 4
Total functions: 4
Maximum function count: 8
Maximum internal block count: 4
Step 4: Index the raw profile
llvm-profdata merge -sparse foo.profraw -o foo.profdataStep 5:Show foo.profdata
Counters:
test:
Hash: 0x0000000000002811
Counters: 2
Function count: 1
Block counts: [4]
main:
Hash: 0x00000000000a0458
Counters: 2
Function count: 1
Block counts: [4]
printf_1:
Hash: 0x0000000000000000
Counters: 1
Function count: 16
Block counts: []
Instrumentation level: Front-end
Functions shown: 3
Total functions: 3
Maximum function count: 16
Maximum internal block count: 4
Step 6: Create a line-oriented coverage report.
llvm-cov show ./foo -instr-profile=foo.profdata
There are some strange phenomenon:
First: In t.c, functin printf_1 counts 16, but ifrom the code logic, the function only runs 4 times. If we count the number of times the printf_1 function runs in the test.c file together, it only runs 8 times, not 16 times
Second: Why is the execution count of the printf_1 function not recorded in the code coverage of the test.c file
clang version
t.c
test.c
Refer to SourceBasedCodeCoverage guide to get code coverage https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
Step 1: Compile with coverage enabled.
clang -fprofile-instr-generate -fcoverage-mapping t.c test.c -o foo
Step 2: Run the programLLVM_PROFILE_FILE="foo.profraw" ./foo
Step 3: Show foo.profrawllvm-profdata show --all-functions --counts foo.profraw
Step 4: Index the raw profile
llvm-profdata merge -sparse foo.profraw -o foo.profdata
Step 5:Show foo.profdataStep 6: Create a line-oriented coverage report.
llvm-cov show ./foo -instr-profile=foo.profdata
There are some strange phenomenon: First: In t.c, functin printf_1 counts 16, but ifrom the code logic, the function only runs 4 times. If we count the number of times the printf_1 function runs in the test.c file together, it only runs 8 times, not 16 times
Second: Why is the execution count of the printf_1 function not recorded in the code coverage of the test.c file
Is this a bug or am I using it incorrectly