https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93626
Bug ID: 93626
Summary: [GCOV] incorrect coverage when compiled with option
'-fsanitize=undefined' for typedef struct
Product: gcc
Version: 9.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: gcov-profile
Assignee: unassigned at gcc dot gnu.org
Reporter: yangyibiao at hust dot edu.cn
CC: marxin at gcc dot gnu.org
Target Milestone: ---
$ gcov -v
gcov (GCC) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-shared
--enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-lto --enable-plugin --enable-install-libiberty
--with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib
--disable-werror --enable-checking=release --enable-default-pie
--enable-default-ssp --enable-cet=auto gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
gcc version 9.2.0 (GCC)
$ cat small.c
void main()
{
int t = 2;
typedef struct
{
char v[t];
} B;
B b;
for (int i = 0; i < 2; i++)
b.v[i] = 0;
}
$ gcc --coverage -O0 -fsanitize=undefined small.c; ./a.out; gcov small.c; cat
small.c.gcov
File 'small.c'
Lines executed:100.00% of 9
Creating 'small.c.gcov'
-: 0:Source:small.c
-: 0:Graph:small.gcno
-: 0:Data:small.gcda
-: 0:Runs:1
1: 1:void main()
1: 2:{
1: 3: int t = 2;
1: 4: typedef struct
-: 5: {
3: 6: char v[t];
-: 7: } B;
1: 8: B b;
3: 9: for (int i = 0; i < 2; i++)
2: 10: b.v[i] = 0;
1: 11:}
Line #6 is wrongly marked as executed three times. When compiled without option
'-fsanitize=undefined', the coverage report is correct.