llvm/llvm-project

[LLVM-COV] Wrong coverage in "if" branch structure.

Opened this issue · 1 comments

Bugzilla Link 50857
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
#include<stdio.h>
#include<stdlib.h>
#define F 140
#define T 13

feq(x, y) long long int x;
long long int y;
{
if (x == y)
return T;
else
return F;
}

long long args[] = {0LL,1LL,-1LL};

int correct_results[] = {
T, F, F, T};

main() {
int i, j, *res = correct_results;

for (i = 0; i < 2; i++) {
long long arg0 = args[i];
for (j = 0; j < 2; j++) {
long long arg1 = args[j];
if (feq(arg0, arg1) != *res++)
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| |#include<stdio.h>
2| |#include<stdlib.h>
3| 2|#define F 140
4| 2|#define T 13
5| |
6| |feq(x, y) long long int x;
7| |long long int y;
8| 4|{
9| 4| if (x == y)
10| 2| return T;
11| 4| else
12| 4| return F;
13| 4|}
14| |
15| |
16| |long long args[] = {0LL,1LL,-1LL};
17| |
18| |int correct_results[] = {
19| | T, F, F, T};
20| |
21| 1|main() {
22| 1| int i, j, *res = correct_results;
23| 1|
24| 3| for (i = 0; i < 2; i++) {
25| 2| long long arg0 = args[i];
26| 6| for (j = 0; j < 2; j++) {
27| 4| long long arg1 = args[j];
28| 4| if (feq(arg0, arg1) != *res++)
29| 0| abort();
30| 4| }
31| 2| }
32| 1| exit(0);
33| 1|}
34| |

Line 12 should only be executed 2 times, and I'm not sure if the coverage of line 3 and 4 is 2.

In 14, the coverage of line 12 is correct with the same commands. How about line 3 and 4?

    1|       |#include<stdio.h>
    2|       |#include<stdlib.h>
    3|      2|#define F 140
    4|      2|#define T 13
    5|       |
    6|       |feq(x, y) long long int x;
    7|       |long long int y;
    8|      4|{
    9|      4|  if (x == y)
   10|      2|    return T;
   11|      2|  else
   12|      2|    return F;
   13|      4|}
   14|       |
   15|       |
   16|       |long long args[] = {0LL,1LL,-1LL};
   17|       |
   18|       |int correct_results[] = {
   19|       |    T, F, F, T};
   20|       |
   21|      1|main() {
   22|      1|  int i, j, *res = correct_results;
   23|       |
   24|      3|  for (i = 0; i < 2; i++) {
   25|      2|    long long arg0 = args[i];
   26|      6|    for (j = 0; j < 2; j++) {
   27|      4|      long long arg1 = args[j];
   28|      4|      if (feq(arg0, arg1) != *res++)
   29|      0|        abort();
   30|      4|    }
   31|      2|  }
   32|      1|  exit(0);
   33|      1|}