[llvm-bugs] [Bug 50857] New: [LLVM-COV] Wrong coverage in "if" branch structure.

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jun 24 20:37:55 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50857

            Bug ID: 50857
           Summary: [LLVM-COV] Wrong coverage in "if" branch structure.
           Product: Runtime Libraries
           Version: 11.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: libprofile library
          Assignee: unassignedbugs at nondot.org
          Reporter: cnwy1996 at outlook.com
                CC: llvm-bugs at lists.llvm.org

$ 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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210625/50d1e9b7/attachment.html>


More information about the llvm-bugs mailing list