Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

[LLVM-COV] wrong coverage with setjmp #36054

Open Quuxplusone opened 6 years ago

Quuxplusone commented 6 years ago
Bugzilla Link PR37081
Status REOPENED
Importance P normal
Reported by Yibiao Yang (yangyibiao@nju.edu.cn)
Reported on 2018-04-10 18:29:10 -0700
Last modified on 2018-04-24 00:10:50 -0700
Version trunk
Hardware PC All
CC dblaikie@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@ndave.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also PR37125
$ clang -v
clang version 7.0.0- (trunk)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.1
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8.0.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.2.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8.0.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8.0.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

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

int bar(jmp_buf buf, int i)
{
  printf("Inside bar %d\n", i);
  longjmp(buf, i);
}

int main()
{
  jmp_buf buf;
  int ret;

  if ((ret = setjmp(buf)) != 0) {
    printf("True  branch.\n");
  } else {
    printf("False branch.\n");
    bar(buf, 2);
  }

  return 0;
}

$ clang -w -O0 -g -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.gcov; cat small.gcov
False branch.
Inside bar 2
True  branch.
    1|       |#include <setjmp.h>
    2|       |#include <stdio.h>
    3|       |
    4|       |int bar(jmp_buf buf, int i)
    5|      1|{
    6|      1|  printf("Inside bar %d\n", i);
    7|      1|  longjmp(buf, i);
    8|      1|}
    9|       |
   10|       |int main()
   11|      1|{
   12|      1|  jmp_buf buf;
   13|      1|  int ret;
   14|      1|
   15|      1|  if ((ret = setjmp(buf)) != 0) {
   16|      1|    printf("True  branch.\n");
   17|      1|  } else {
   18|      0|    printf("False branch.\n");
   19|      0|    bar(buf, 2);
   20|      0|  }
   21|      1|
   22|      1|  return 0;
   23|      1|}

*****
Line #18 and Line 19 are wrongly marked as not executed.
However, in terms of output, Line #18 and #19 are executed.
Quuxplusone commented 6 years ago

_This bug has been marked as a duplicate of bug 37125_

Quuxplusone commented 6 years ago

My mistake. This is not a duplication of bug 37125