https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101413
Bug ID: 101413 Summary: [Gcov] wrong coverage for a return 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 —————————————————————————— const volatile short int true_var = 1; volatile int false_var = 0; #include <time.h> static int weak_gettime (clockid_t clk_id, struct timespec *tp) __attribute__((__weakref__("clock_gettime"))); int main() { if (!clock_gettime) return 0; struct timespec ts; if( true_var > 0 ) { return weak_gettime(CLOCK_MONOTONIC, &ts); } } —————————————————————————— $gcc -O0 --coverage test.c;./a.out;gcov test;cat test.c.gcov -: 1:/* { dg-do run { target { *-*-linux* *-*-freebsd* } } } */ -: 2: -: 3:const volatile short int true_var = 1; -: 4:volatile int false_var = 0; -: 5: -: 6:#include <time.h> -: 7:static int weak_gettime (clockid_t clk_id, struct timespec *tp) -: 8: __attribute__((__weakref__("clock_gettime"))); 1: 9:int main() { -: 10: if (!clock_gettime) 1: 11: return 0; -: 12: struct timespec ts; 1: 13: if( true_var > 0 ) -: 14: { 1: 15: return weak_gettime(CLOCK_MONOTONIC, &ts); -: 16: } -: 17:} Line 11 should not be executed.