https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85351
Bug ID: 85351 Summary: [GCOV] Wrong coverage with an executed exit() in if statement within a called function Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: gcov-profile Assignee: unassigned at gcc dot gnu.org Reporter: yangyibiao at nju dot edu.cn CC: marxin at gcc dot gnu.org Target Milestone: --- /********************** small.c *********************/ $ cat small.c #include <stdlib.h> void foo1(int x) { if (x < 1) exit(0); } int main() { foo1(0); return 0; } $ gcc --coverage small.c; ./a.out; gcov-8 small.c; cat small.c.gcov File 'small.c' Lines executed:71.43% of 7 Creating 'small.c.gcov' -: 0:Source:small.c -: 0:Graph:small.gcno -: 0:Data:small.gcda -: 0:Runs:1 -: 0:Programs:1 -: 1:#include <stdlib.h> -: 2: 1: 3:void foo1(int x) -: 4:{ 1: 5: if (x < 1) 1: 6: exit(0); #####: 7:} -: 8: 1: 9:int main() -: 10:{ 1: 11: foo1(0); #####: 12: return 0; -: 13:} ************************* Line #7 is wrongly marked as "#####" ************************* /********************** small2.c *********************/ $ cat small2.c #include <stdlib.h> void foo1(int x) { // if (x < 1) exit(0); } int main() { foo1(0); return 0; } $ gcc --coverage small2.c; ./a.out; gcov-8 small2.c; cat small2.c.gcov File 'small2.c' Lines executed:80.00% of 5 Creating 'small2.c.gcov' -: 0:Source:small2.c -: 0:Graph:small2.gcno -: 0:Data:small2.gcda -: 0:Runs:1 -: 0:Programs:1 -: 1:#include <stdlib.h> -: 2: 1: 3:void foo1(int x) -: 4:{ -: 5: // if (x < 1) 1: 6: exit(0); -: 7:} -: 8: 1: 9:int main() -: 10:{ 1: 11: foo1(0); #####: 12: return 0; -: 13:} *************************** While comparing the coverage of small.c and small2.c, we can find that the marks of Line #7 in these two files is inconsistant. This confirms that the coverage of small.c is incorrect.