gcov incorrectly shows that a lone return statement inside a block has executed when in fact it has not
Environment: System: Linux mercury.acucorp.com 2.4.18-27.8.0smp #1 SMP Fri Mar 14 07:13:13 EST 2003 i686 athlon i386 GNU/Linux Architecture: i686 host: i686-pc-linux-gnu build: i686-pc-linux-gnu target: i686-pc-linux-gnu configured with: ../gcc-4.0.2/configure --prefix=/usr/local/gcc-4.0.2 How-To-Repeat: Compile the following program, run it, then run gcov on the source: gcc -fprofile-arcs -ftest-coverage -o foo foo.c ./foo gcov -b foo.c ------- foo.c: #include <stdio.h> static void foo(int num) { if (num <= 1) { /* uncomment following line to get correct results */ // printf("num <= 1\n"); /* this return is never executed, but gcov says it is */ return; } printf("num > 1\n"); } /* foo */ int main(void) { foo(3); foo(3); foo(3); foo(3); foo(3); foo(3); foo(3); return 0; } ------- foo.c.gcov: -: 0:Source:foo.c -: 0:Graph:foo.gcno -: 0:Data:foo.gcda -: 0:Runs:1 -: 0:Programs:1 -: 1:#include <stdio.h> -: 2: -: 3:static void -: 4:foo(int num) function foo called 7 returned 100% blocks executed 100% 7: 5:{ 7: 6: if (num <= 1) { branch 0 taken 100% (fallthrough) branch 1 taken 0% -: 7: /* uncomment following line to get correct results */ -: 8:// printf("num <= 1\n"); -: 9: -: 10: /* this return is never executed, but gcov says it is */ 7: 11: return; -: 12: } -: 13: 7: 14: printf("num > 1\n"); call 0 returned 100% -: 15:} /* foo */ -: 16: -: 17: -: 18:int -: 19:main(void) function main called 1 returned 100% blocks executed 100% 1: 20:{ 1: 21: foo(3); call 0 returned 100% 1: 22: foo(3); call 0 returned 100% 1: 23: foo(3); call 0 returned 100% 1: 24: foo(3); call 0 returned 100% 1: 25: foo(3); call 0 returned 100% 1: 26: foo(3); call 0 returned 100% 1: 27: foo(3); call 0 returned 100% 1: 28: return 0; -: 29:} ------- Comment #1 from mark at acucorp dot com 2005-12-23 18:57 ------- Fix: unknown -- Summary: gcov incorrect count for lone return in block Product: gcc Version: 4.0.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: mark at acucorp dot com GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25551