<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 for the "for-expression""
href="https://bugs.llvm.org/show_bug.cgi?id=45846">45846</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>llvm-cov: wrong coverage for the "for-expression"
</td>
</tr>
<tr>
<th>Product</th>
<td>Runtime Libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</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>normal
</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>yangyibiao@hust.edu.cn
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>$ clang --version
clang version 11.0.0 (/home/yibiao/.cache/yay/llvm-git/llvm-project
871beba234a83a2a02da9dedbd59b91a1bfbd7af)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ clang -O0 -w -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.c.lcov; cat
small.c.lcov
1| 1|void ok() { exit(0); }
2| |
3| 1|void foo() {
4| 1| int i;
5| 2| for (i=1; 1>0; ++i)
6| 1| ok();
7| 1|}
8| |
9| 1|int main() {
10| 1| foo();
11| 1|}
***
Line 5 is wrongly marked as executed twice. However, when called ok, the
program is exit. Thus, the for expression should be executed only once. When
setting breakpoint for Line 5 in LLDB, it only hit one time as follow:
$ clang -w -g small.c; lldb a.out
(lldb) target create "a.out"
Current executable set to '/home/yibiao/Decov/a.out' (x86_64).
(lldb) b 5
Breakpoint 1: where = a.out`foo + 8 at small.c:5:9, address =
0x0000000000401148
(lldb) r
Process 447035 launched: '/home/yibiao/Decov/a.out' (x86_64)
Process 447035 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
frame #0: 0x0000000000401148 a.out`foo at small.c:5:9
2
3 void foo() {
4 int i;
-> 5 for (i=1; 1>0; ++i)
6 ok();
7 }
8
(lldb) c
Process 447035 resuming
Process 447035 exited with status = 0 (0x00000000)
When we replace Line 6 with "exit(0); // ok();", the coverage is correct as
follow:
1| 0|void ok() { exit(0); }
2| |
3| 1|void foo() {
4| 1| int i;
5| 1| for (i=1; 1>0; ++i)
6| 1| exit(0); // ok();
7| 1|}
8| |
9| 1|int main() {
10| 1| foo();
11| 1|}
$ cat small.c
void ok() { exit(0); }
void foo() {
int i;
for (i=1; 1>0; ++i)
ok();
}
int main() {
foo();
}</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>