[llvm-bugs] [Bug 51153] New: [LLVM-COV] Wrong coverage with the "for" and "setjmp"
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Jul 21 05:54:22 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=51153
Bug ID: 51153
Summary: [LLVM-COV] Wrong coverage with the "for" and "setjmp"
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
extern int strcmp(const char *, const char *);
extern char *strcpy(char *, const char *);
extern void abort(void);
extern void exit(int);
void *buf[20];
void __attribute__((noinline)) sub2(void) { __builtin_longjmp(buf, 1); }
int main() {
char *p = (char *)__builtin_alloca(20);
strcpy(p, "test");
if (__builtin_setjmp(buf)) {
if (strcmp(p, "test") != 0)
abort();
exit(0);
}
{
int *q = (int *)__builtin_alloca(p[2] * sizeof(int));
printf("Excuted!\n");
int i;
for (i = 0; i < p[2]; i++)
q[i] = 0;
while (1)
sub2();
}
}
$ 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
Excuted!
1| |#include<stdio.h>
2| |extern int strcmp(const char *, const char *);
3| |extern char *strcpy(char *, const char *);
4| |extern void abort(void);
5| |extern void exit(int);
6| |
7| |void *buf[20];
8| |
9| 1|void __attribute__((noinline)) sub2(void) {
__builtin_longjmp(buf, 1); }
10| |
11| 1|int main() {
12| 1| char *p = (char *)__builtin_alloca(20);
13| 1|
14| 1| strcpy(p, "test");
15| 1|
16| 1| if (__builtin_setjmp(buf)) {
17| 1| if (strcmp(p, "test") != 0)
18| 0| abort();
19| 1|
20| 1| exit(0);
21| 1| }
22| 0|
23| 0| {
24| 0| int *q = (int *)__builtin_alloca(p[2] * sizeof(int));
25| 0| printf("Excuted!\n");
26| 0| int i;
27| 0|
28| 115| for (i = 0; i < p[2]; i++)
29| 115| q[i] = 0;
30| 0|
31| 1| while (1)
32| 1| sub2();
33| 0| }
34| 0|}
line 16 was executed twice, line 24 to 26 was executed once and line 28 was
executed 116 times.
--
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/20210721/f8e19a98/attachment.html>
More information about the llvm-bugs
mailing list