<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 with a function pointer points to the exit() function"
href="https://bugs.llvm.org/show_bug.cgi?id=45850">45850</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>llvm-cov: wrong coverage with a function pointer points to the exit() function
</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| |void exit(int);
2| |void (*myexit)(int);
3| |
4| |int main()
5| 1|{
6| 1| int i = 0, j = 0;
7| 1| myexit = exit;
8| 3| for (i=0;i<5;i++) {
9| 2| if (i)
10| 1| myexit(0);
11| 2| j++;
12| 2| }
13| 1|}
***
Line 11 is wrongly marked as executed twice. myexit is a function pointer. When
setting breakpoint for Line 11 in lldb, only hit one time.
When replace Line 10 with exit(0), the coverage will be correct as follow:
1| |void exit(int);
2| |void (*myexit)(int);
3| |
4| |int main()
5| 1|{
6| 1| int i = 0, j = 0;
7| 1| myexit = exit;
8| 2| for (i=0;i<5;i++) {
9| 2| if (i)
10| 1| exit(0); // myexit(0);
11| 1| j++;
12| 1| }
13| 1|}
$ cat small.c
void exit(int);
void (*myexit)(int);
int main()
{
int i = 0, j = 0;
myexit = exit;
for (i=0;i<5;i++) {
if (i)
exit(0); // myexit(0);
j++;
}
}</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>