[llvm-bugs] [Bug 51270] New: [LLVM-COV] Wrong coverage after a "for" loop.
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Jul 29 06:54:36 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=51270
Bug ID: 51270
Summary: [LLVM-COV] Wrong coverage after a "for" loop.
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 <assert.h>
#include <stdio.h>
#include <string.h>
#define SIZE 1000
int t0 = 0;
const char *t2[SIZE];
char buf[SIZE];
void foo(void) {
char *s = buf;
t0 = 1;
for (;;) {
if (*s == '\0')
break;
else {
t2[t0] = s;
t0++;
}
*s++ = '\0';
}
t2[t0] = NULL;
}
int main() {
strcpy(buf, "hello");
foo();
return 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
1| |#include <assert.h>
2| |#include <stdio.h>
3| |#include <string.h>
4| |
5| |#define SIZE 1000
6| |int t0 = 0;
7| |const char *t2[SIZE];
8| |char buf[SIZE];
9| |
10| 1|void foo(void) {
11| 1| char *s = buf;
12| 1| t0 = 1;
13| 1|
14| 6| for (;;) {
15| 6| if (*s == '\0')
16| 1| break;
17| 5| else {
18| 5| t2[t0] = s;
19| 5| t0++;
20| 5| }
21| 6| *s++ = '\0';
22| 5| }
23| 1| t2[t0] = NULL;
24| 1|}
25| |
26| 1|int main() {
27| 1| strcpy(buf, "hello");
28| 1| foo();
29| 1| return 0;
30| 1|}
Line 21 should only be executed 5 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/20210729/157c37df/attachment.html>
More information about the llvm-bugs
mailing list