[Bug gcov-profile/101412] New: [Gcov] an if statement leads to incorrect coverage of the case statement
byone.heng at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sun Jul 11 07:33:48 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101412
Bug ID: 101412
Summary: [Gcov] an if statement leads to incorrect coverage of
the case statement
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: gcov-profile
Assignee: unassigned at gcc dot gnu.org
Reporter: byone.heng at gmail dot com
CC: marxin at gcc dot gnu.org
Target Milestone: ---
$./gcc -v
Using built-in specs.
COLLECT_GCC=./gcc
COLLECT_LTO_WRAPPER=/home/x/project/gcc/build/install/libexec/gcc/x86_64-pc-linux-gnu/11.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/home/x/project/gcc/build/install
--enable-checking=release --enable-languages=c,c++ --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.0 20210105 (experimental) (GCC)
$cat test.c
——————————————————————————
#include <stdio.h>
static volatile unsigned char true_var = 1;
const unsigned short int false_var = 0;
g ()
{
return '\n';
}
f ()
{
char s[] = "abcedfg012345";
char *sp = s + 12;
switch (g ())
{
if( true_var > 0 )
{
case '\n':
break;
}
}
while (*--sp == '0')
;
sprintf (sp + 1, "X");
if (s[12] != 'X')
abort ();
}
main ()
{
f ();
exit (0);
}
——————————————————————————
$gcc -O0 --coverage test.c;./a.out;gcov test;cat test.c.gcov
-: 1:#include <stdio.h>
-: 2:
-: 3:static volatile unsigned char true_var = 1;
-: 4:const unsigned short int false_var = 0;
1: 5:g ()
-: 6:{
1: 7: return '\n';
-: 8:}
-: 9:
1: 10:f ()
-: 11:{
1: 12: char s[] = "abcedfg012345";
1: 13: char *sp = s + 12;
-: 14:
1: 15: switch (g ())
-: 16: {
-: 17: if( true_var > 0 )
-: 18: {
-: 19: case '\n':
1: 20: break;
-: 21: }
-: 22: }
-: 23:
1: 24: while (*--sp == '0')
-: 25: ;
1: 26: sprintf (sp + 1, "X");
-: 27:
1: 28: if (s[12] != 'X')
#####: 29: abort ();
1: 30:}
-: 31:
1: 32:main ()
-: 33:{
1: 34: f ();
1: 35: exit (0);
-: 36:}
Line 19 should be executed once.
More information about the Gcc-bugs
mailing list