<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 that may be caused by "ASM" and "volatile""
href="https://bugs.llvm.org/show_bug.cgi?id=51156">51156</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[LLVM-COV] Wrong coverage that may be caused by "ASM" and "volatile"
</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<stdlib.h>
#include<stdio.h>
volatile int cnt = 0;
__attribute__((noinline, noclone)) static int last(void) {
return ++cnt % 5 == 0;
}
__attribute__((noinline, noclone)) static void do_it(void) {
asm volatile("" : : "r"(&cnt) : "memory");
}
__attribute__((noinline, noclone)) static void f1(void) {
for (;; do_it()) {
printf("Enter loop\n");
if (last())
break;
}
do_it(); /* { dg-final { gdb-test . "cnt" "5" } } */
}
__attribute__((noinline, noclone)) static void f2(void) {
while (1) {
if (last())
break;
do_it();
}
do_it(); /* { dg-final { gdb-test . "cnt" "10" } } */
}
__attribute__((noinline, noclone)) static void f3(void) {
for (;; do_it())
if (last())
break;
do_it(); /* { dg-final { gdb-test . "cnt" "15" } } */
}
void (*volatile fnp1)(void) = f1;
void (*volatile fnp2)(void) = f2;
void (*volatile fnp3)(void) = f3;
int main() {
asm volatile("" : : "r"(&fnp1) : "memory");
asm volatile("" : : "r"(&fnp2) : "memory");
asm volatile("" : : "r"(&fnp3) : "memory");
fnp1();
fnp2();
fnp3();
}
$ 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
Enter loop
Enter loop
Enter loop
Enter loop
Enter loop
1| |#include<stdlib.h>
2| |#include<stdio.h>
3| |volatile int cnt = 0;
4| 15|__attribute__((noinline, noclone)) static int last(void) {
5| 15| return ++cnt % 5 == 0;
6| 15|}
7| |
8| 15|__attribute__((noinline, noclone)) static void do_it(void) {
9| 15| asm volatile("" : : "r"(&cnt) : "memory");
10| 15|}
11| |
12| 1|__attribute__((noinline, noclone)) static void f1(void) {
13| 5| for (;; do_it()) {
14| 5| printf("Enter loop\n");
15| 5| if (last())
16| 1| break;
17| 5| }
18| 1| do_it(); /* { dg-final { gdb-test . "cnt" "5" } } */
19| 1|}
20| |
21| 1|__attribute__((noinline, noclone)) static void f2(void) {
22| 5| while (1) {
23| 5| if (last())
24| 1| break;
25| 4| do_it();
26| 4| }
27| 1| do_it(); /* { dg-final { gdb-test . "cnt" "10" } } */
28| 1|}
29| |
30| 1|__attribute__((noinline, noclone)) static void f3(void) {
31| 4| for (;; do_it())
32| 5| if (last())
33| 1| break;
34| 1| do_it(); /* { dg-final { gdb-test . "cnt" "15" } } */
35| 1|}
36| |void (*volatile fnp1)(void) = f1;
37| |void (*volatile fnp2)(void) = f2;
38| |void (*volatile fnp3)(void) = f3;
39| |
40| 1|int main() {
41| 1| asm volatile("" : : "r"(&fnp1) : "memory");
42| 1| asm volatile("" : : "r"(&fnp2) : "memory");
43| 1| asm volatile("" : : "r"(&fnp3) : "memory");
44| 1| fnp1();
45| 1| fnp2();
46| 1| fnp3();
47| 1|}
Line 31 should 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>