<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - [LLVM-COV] Wrong coverage after a "for" loop."
href="https://bugs.llvm.org/show_bug.cgi?id=51270">51270</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[LLVM-COV] Wrong coverage after a "for" loop.
</td>
</tr>
<tr>
<th>Product</th>
<td>Runtime Libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>11.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>libprofile library
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>cnwy1996@outlook.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>$ 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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>