llvm-cov: wrong coverage for multiple calling a function with conditional operator statement
| Bugzilla Link | 48818 |
| Version | trunk |
| OS | Linux |
| Reporter | LLVM Bugzilla Contributor |
| CC | @dwblaikie,@vedantk,@ZequanWu |
Extended Description
Consider this case: ... $ cat small.c int f(int i) { int r = (i-1) > 0 ? i : 0; return r; }
int main() { f(1); f(2); } ...
$ clang -O0 -w -fcoverage-mapping -fprofile-instr-generate=small.profraw small.c; ./a.out; llvm-profdata merge small.profraw -o small.profdata; llvm-cov show a.out -instr-profile=small.profdata small.c > small.c.lcov; cat small.c.lcov 1| |int f(int i) 2| 2|{ 3| 1| int r = (i-1) > 0 ? i : 0; 4| 2| return r; 5| 2|} 6| | 7| |int main() 8| 1|{ 9| 1| f(1); 10| 1| f(2); 11| 1|} 12| |
...
We can found that Line #3 is wrongly marked as execute 1 times. Line #3 should be executed 2 times.
... $ clang --version Ubuntu clang version 12.0.0-++20210117052627+ed396212da41-1~exp1~20210117163329.287 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin
$ clang -w -O0 -g -fcoverage-mapping -fprofile-instr-generate=small.profraw small.c; ./a.out; llvm-profdata merge small.profraw -o small.profdata; llvm-cov show a.out -instr-profile=small.profdata small.c > small.c.lcov; cat small.c.lcov
1| |int f(int i)
2| 2|{
3| 2| int r = (i-1) > 0 ? i : 0;
4| 2| return r;
5| 2|}
6| |
7| |int main()
8| 1|{
9| 1| f(1);
10| 1| f(2);
11| 1|}
$ clang --version Ubuntu clang version 16.0.0-++20220905063833+2417618d5ca4-1~exp1~20220905183932.719 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin
In the trunk version, the reported code coverage for Line #3 is correct. I was wondering that whether this bug should be closed as fixed.