[llvm-bugs] [Bug 41849] New: [[LLVM-COV] #if #endif in the source code lead to incorrect coverage report when exit() statement follows "while() ; "
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun May 12 05:46:07 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=41849
Bug ID: 41849
Summary: [[LLVM-COV] #if #endif in the source code lead to
incorrect coverage report when exit() statement
follows "while() ;"
Product: Runtime Libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: libprofile library
Assignee: unassignedbugs at nondot.org
Reporter: yangyibiao at nju.edu.cn
CC: llvm-bugs at lists.llvm.org
$ clang -v
clang version 9.0.0-svn358899-1~exp1+0~20190422164136.937~1.gbpac4d8e (trunk)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
$ cat small.c
extern void abort (void);
extern void exit (int);
int
main (void)
{
#if __INT_MAX__ >= 2147483647
struct { int count: 31; } s = { 0 };
while (s.count--)
; // abort ();
#elif __INT_MAX__ >= 32767
abort(1);
#else
#endif
exit (2);
}
$ clang -w -O0 -g -fcoverage-mapping -fprofile-instr-generate=small.profraw
small.c; ./a.out; echo $?; 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
2
1| |extern void abort (void);
2| |extern void exit (int);
3| |
4| |int
5| |main (void)
6| 1|{
7| 1|#if __INT_MAX__ >= 2147483647
8| 1| struct { int count: 31; } s = { 0 };
9| 1| while (s.count--)
10| 0| ; // abort ();
11| |#elif __INT_MAX__ >= 32767
12| | abort(1);
13| |#else
14| |#endif
15| | exit (2);
16| 1|}
Line # 15 is marked as "" which indicates that it is not an instrumentation
site.
However, we can found that the exit code of this program is 2. Thus we can
determine that line #15 is executed during this execution.
When Line #10 is not removed, Line #15 is marked as executed once as follows.
$ clang -w -O0 -g -fcoverage-mapping -fprofile-instr-generate=small.profraw
small.c; ./a.out; echo $?; 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
2
1| |extern void abort (void);
2| |extern void exit (int);
3| |
4| |int
5| |main (void)
6| 1|{
7| 1|#if __INT_MAX__ >= 2147483647
8| 1| struct { int count: 31; } s = { 0 };
9| 1| while (s.count--)
10| 0| abort ();
11| |#elif __INT_MAX__ >= 32767
12| | abort(1);
13| |#else
14| |#endif
15| 1| exit (2);
16| 1|}
--
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/20190512/f7720a8a/attachment-0001.html>
More information about the llvm-bugs
mailing list