[llvm-bugs] [Bug 50775] New: [LLVM-COV] Using "setjmp" statement leads wrong coverage
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Jun 20 00:32:56 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=50775
Bug ID: 50775
Summary: [LLVM-COV] Using "setjmp" statement leads wrong
coverage
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 <setjmp.h>
#include <stdlib.h>
jmp_buf env;
extern void sub(void);
int called;
__attribute__((__noinline__)) int sjtest() {
int i;
if (setjmp(env))
return 99;
for (i = 0; i < 10; i++)
sub();
printf("Executed!\n");
longjmp(env, 1);
}
__attribute__((__noinline__)) void sub(void) { called++; }
int main(void) {
if (sjtest() != 99 || called != 10)
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
Executed!
1| |#include <setjmp.h>
2| |#include <stdlib.h>
3| |
4| |jmp_buf env;
5| |extern void sub(void);
6| |int called;
7| 1|__attribute__((__noinline__)) int sjtest() {
8| 1| int i;
9| 1| if (setjmp(env))
10| 1| return 99;
11| 0|
12| 10| for (i = 0; i < 10; i++)
13| 10| sub();
14| 0| printf("Executed!\n");
15| 0| longjmp(env, 1);
16| 0|}
17| |
18| 10|__attribute__((__noinline__)) void sub(void) { called++; }
19| |
20| |
21| 1|int main(void) {
22| 1| if (sjtest() != 99 || called != 10)
23| 0| abort();
24| 1| exit(0);
25| 1|}
We can see that line 14 and 15 were wrongly marked as unexecuted, and the
coverage of line 12 should be 11.
--
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/20210620/25b968cc/attachment.html>
More information about the llvm-bugs
mailing list