[LLVM-COV] A "break;" statement is wrongly marked as executed when it is after the "abort();" statement in switch-case
| Bugzilla Link | 41821 |
| Version | trunk |
| OS | Linux |
| Reporter | LLVM Bugzilla Contributor |
| CC | @zygoloid |
Extended Description
$ clang -v clang version 9.0.0-svn358899-1~exp1+0~20190422164136.937~1.gbpac4d8e (trunk) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.5 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.5.0 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.5 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Candidate multilib: x32;@mx32 Selected multilib: .;@m64
$ rm a.out small.lcov small.p*; 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.lcov; cat small.lcov 1| |int main() 2| 1|{ 3| 1| switch (8) 4| 1| { 5| 1| case 8: 6| 1| break; 7| 1| default: 8| 0| abort (); 9| 1| break; 10| 1| } 11| 1| return 0; 12| 1|}
Line #9 is wrongly marked as executed. In fact, it is obvious that Line #9 is not executed.
When Line #8 is removed, the coverage is correct as follows:
$ rm a.out small.lcov small.p*; 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.lcov; cat small.lcov 1| |int main() 2| 1|{ 3| 1| switch (8) 4| 1| { 5| 1| case 8: 6| 1| break; 7| 1| default: 8| 0| // abort (); 9| 0| break; 10| 1| } 11| 1| return 0; 12| 1|}
mentioned in issue llvm/llvm-bugzilla-archive#44011
$ cat small.c int main() { switch (8) { case 8: break; default: abort (); break; } return 0; }
$ rm a.out small.lcov small.p*; 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.lcov; cat small.lcov 1| |int main() 2| 1|{ 3| 1| switch (8) 4| 1| { 5| 1| case 8: 6| 1| break; 7| 1| default: 8| 0| abort (); 9| 1| break; 10| 1| } 11| 1| return 0; 12| 1|}
Line #9 is wrongly marked as executed. In fact, it is obvious that Line #9 is not executed.
$ 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| |#include <stdio.h>
2| |#include <stdlib.h>
3| |int main()
4| 1|{
5| 1| switch (8)
6| 1| {
7| 1| case 8:
8| 1| break;
9| 0| default:
10| 0| abort ();
11| 0| break;
12| 1| }
13| 1| return 0;
14| 1|}
$ clang --version
Ubuntu clang version 16.0.0-++20220905063833+2417618d5ca4-1~exp1~20220905183932.719
As can be seen, in the trunk version, the code coverage for Line #10 and Line #11 are both correct.
I was wondering that whether this bug should be also closed as fixed. Thank you very much.