[llvm-bugs] [Bug 49428] New: [LLVM-COV] Wrong coverage with for statement

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 3 23:48:44 PST 2021


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

            Bug ID: 49428
           Summary: [LLVM-COV] Wrong coverage with for statement
           Product: Runtime Libraries
           Version: 11.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          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
int a, b, c, e, f;
void fn1(int p) {}
int fn2(int p) { return a ? p % a : 0; }
short fn3(int p) { return (1 >> p) < 1 ? 1 : p; }
int fn4() {
  int g = 0, h = 1;
  if (b)
    goto lbl;
  fn2(0);
  if (fn3(1))
    fn1(e && c);
  if (h) {
    int i = 1;
  lbl:
    if (i)
      return 0;
    for (; g < 1; g++)
      ;
  }
  for (;;)
    f || g > 0;
}

int main() {
  fn4();
}

$ 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|       |int a, b, c, e, f;
    2|      1|void fn1(int p) {}
    3|      1|int fn2(int p) { return a ? p % a : 0; }
    4|      1|short fn3(int p) { return (1 >> p) < 1 ? 1 : p; }
    5|      1|int fn4() {
    6|      1|  int g = 0, h = 1;
    7|      1|  if (b)
    8|      0|    goto lbl;
    9|      1|  fn2(0);
   10|      1|  if (fn3(1))
   11|      1|    fn1(e && c);
   12|      1|  if (h) {
   13|      1|    int i = 1;
   14|      1|  lbl:
   15|      1|    if (i)
   16|      1|      return 0;
   17|      0|    for (; g < 1; g++)
   18|      0|      ;
   19|      0|  }
   20|      1|  for (;;)
   21|      0|    f || g > 0;
   22|      0|}
   23|       |
   24|      1|int main() {
   25|      1|  fn4();
   26|      1|}


The number of executions of line #20 should be 0, the same as line #17

-- 
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/20210304/dcb4ff24/attachment.html>


More information about the llvm-bugs mailing list