[llvm-bugs] [Bug 45821] New: wrong coverage for struct pointer array assignment

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 6 17:49:20 PDT 2020


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

            Bug ID: 45821
           Summary: wrong coverage for struct pointer array assignment
           Product: Runtime Libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: libprofile library
          Assignee: unassignedbugs at nondot.org
          Reporter: yangyibiao at hust.edu.cn
                CC: llvm-bugs at lists.llvm.org

$ clang -v
clang version 11.0.0 (/home/yibiao/.cache/yay/llvm-git/llvm-project
871beba234a83a2a02da9dedbd59b91a1bfbd7af)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/9.3.0
Found candidate GCC installation:
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.3.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0
Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/9.3.0
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.3.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

$ clang -O0 -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 <setjmp.h>
    2|       |#include <stdlib.h>
    3|       |
    4|       |jmp_buf buf;
    5|       |struct S { const int f; } g;
    6|       |
    7|      1|void foo(void) { longjmp(buf, 1); }
    8|       |
    9|      1|int main () {
   10|      1|  if(setjmp(buf)) {
   11|      1|    return 0;
   12|      1|  }
   13|      0|  struct S * const sa[2] = {&g, &g};
   14|      1|  while (1) foo();
   15|      0|}

*****
Line #13 is wrongly marked as not executed. In fact, this line should be
executed. When setting breakpoint for line 13, lldb reaches this line as
follow:

$ clang -g small.c; lldb a.out
(lldb) target create "a.out"
Current executable set to '/home/yibiao/a.out' (x86_64).
(lldb) b 13
Breakpoint 1: where = a.out`main + 47 at small.c:13:20, address =
0x000000000040118f
(lldb) run
Process 87671 launched: '/home/yibiao/a.out' (x86_64)
Process 87671 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x000000000040118f a.out`main at small.c:13:20
   10     if(setjmp(buf)) {
   11       return 0;
   12     }
-> 13     struct S * const sa[2] = {&g, &g};
   14     while (1) foo();
   15   }
(lldb)  



$ cat small.c
#include <setjmp.h>
#include <stdlib.h>

jmp_buf buf;
struct S { const int f; } g;

void foo(void) { longjmp(buf, 1); }

int main () {
  if(setjmp(buf)) {
    return 0;
  }
  struct S * const sa[2] = {&g, &g};
  while (1) foo();
}

-- 
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/20200507/8e2a5990/attachment.html>


More information about the llvm-bugs mailing list