llvm/llvm-project

[LLVM-COV] Dead code after goto statement was wrongly marked as executed

Closed this issue · 1 comments

Bugzilla Link 49426
Version 11.0
OS Linux
Reporter LLVM Bugzilla Contributor

Extended Description

$ clang -v
clang version 11.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/wangyang/llvm-project/build/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

$ cat test.c
extern void abort(void);
extern void exit(int);

int sub1(int val) { return val; }

int testcond(int val) {
int flag1;

{
int t1 = val;
{
int t2 = t1;
{
flag1 = sub1(t2) == 0;
goto lab1;
t2++;
};
}
lab1:;
}

if (flag1 != 0)
return 0x4d0000;
else
return 0;
}

int main(void) {
if (testcond(1))
abort();
exit(0);
}

$ clang -w -O0 -g -fcoverage-mapping -fprofile-instr-generate=test.profraw test.c; ./a.out; llvm-profdata merge test.profraw -o test.profdata; llvm-cov show a.out -instr-profile=test.profdata test.c > test.lcov; cat test.lcov
1| |extern void abort(void);
2| |extern void exit(int);
3| |
4| 1|int sub1(int val) { return val; }
5| |
6| 1|int testcond(int val) {
7| 1| int flag1;
8| 1|
9| 1| {
10| 1| int t1 = val;
11| 1| {
12| 1| int t2 = t1;
13| 1| {
14| 1| flag1 = sub1(t2) == 0;
15| 1| goto lab1;
16| 1| t2++;
17| 0| };
18| 0| }
19| 1| lab1:;
20| 1| }
21| 1|
22| 1| if (flag1 != 0)
23| 0| return 0x4d0000;
24| 1| else
25| 1| return 0;
26| 1|}
27| |
28| 1|int main(void) {
29| 1| if (testcond(1))
30| 0| abort();
31| 1| exit(0);
32| 1|}

Line #​16 should never be excuted.

In 14, the coverage is correct with the same commands.

    1|       |extern void abort(void);
    2|       |extern void exit(int);
    3|       |
    4|      1|int sub1(int val) { return val; }
    5|       |
    6|      1|int testcond(int val) {
    7|      1|  int flag1;
    8|       |
    9|      1|  {
   10|      1|    int t1 = val;
   11|      1|    {
   12|      1|      int t2 = t1;
   13|      1|      {
   14|      1|        flag1 = sub1(t2) == 0;
   15|      1|        goto lab1;
   16|      0|        t2++;
   17|      0|      };
   18|      0|    }
   19|      1|  lab1:;
   20|      1|  }
   21|       |
   22|      1|  if (flag1 != 0)
   23|      0|    return 0x4d0000;
   24|      1|  else
   25|      1|    return 0;
   26|      1|}
   27|       |
   28|      1|int main(void) {
   29|      1|  if (testcond(1))
   30|      0|    abort();
   31|      1|  exit(0);
   32|      1|}