https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65831
Bug ID: 65831 Summary: gcov does not output 0% coverage files Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: gcov-profile Assignee: unassigned at gcc dot gnu.org Reporter: afineman at afineman dot com Created attachment 35378 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35378&action=edit Always create .gcov file if there is no .gcda file. When running gcov against a file that was not covered at all (i.e., has no corresponding .gcda file), gcov 4.6 would correctly output a .gcov file that indicates 0% coverage. gcov 4.8 does not output any .gcov file in this case, which I believe is a regression. ===================== afineman@hotdog:/tmp$ diff test6.c test8.c afineman@hotdog:/tmp$ cat test6.c int main() { return 0; } afineman@hotdog:/tmp$ gcc-4.6 --version gcc-4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 Copyright (C) 2011 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. afineman@hotdog:/tmp$ gcov-4.6 --version gcov (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 Copyright (C) 2011 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. afineman@hotdog:/tmp$ gcov-4.8 --version gcov (GCC) 4.8.2 Copyright (C) 2013 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. afineman@hotdog:/tmp$ gcc-4.8 --version gcc-4.8 (GCC) 4.8.2 Copyright (C) 2013 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. afineman@hotdog:/tmp$ gcc-4.6 --coverage test6.c -o test6 afineman@hotdog:/tmp$ gcc-4.8 --coverage test8.c -o test8 afineman@hotdog:/tmp$ gcov-4.6 test6.c test6.gcda:cannot open data file, assuming not executed File 'test6.c' Lines executed:0.00% of 2 test6.c:creating 'test6.c.gcov' afineman@hotdog:/tmp$ cat test6.c.gcov -: 0:Source:test6.c -: 0:Graph:test6.gcno -: 0:Data:- -: 0:Runs:0 -: 0:Programs:0 -: 1:int #####: 2:main() -: 3:{ #####: 4: return 0; -: 5:} afineman@hotdog:/tmp$ gcov-4.8 test8.c test8.gcda:cannot open data file, assuming not executed File 'test8.c' No executable lines Removing 'test8.c.gcov' afineman@hotdog:/tmp$ ===================== I believe that this is not a duplicate of Bug 35568. Or, at least, in 35568 there seem to be tests involving missing graph files along with missing data files. This bug is only about (correctly) missing data files due to 0% coverage, but failing to produce a .gcov file that indicates 0% coverage. ===================== I've attached a patch that fixes the problem in my case, but I don't know if my solution is the correct approach. Also, I would like to have included something in the testsuite to avoid this in the future, but I don't have the time right now. If the maintainers want such a test, I volunteer to write one. (I've never contributed to this project before, and can't promise when I'll get to it.) ====================== Results from running gcov after applying the attached patch: afineman@hotdog:/tmp$ ./build-gcc/gcc/gcov test8.c test8.gcda:cannot open data file, assuming not executed File 'test8.c' Lines executed:0.00% of 2 Creating 'test8.c.gcov' afineman@hotdog:/tmp$ cat test8.c.gcov -: 0:Source:test8.c -: 0:Graph:test8.gcno -: 0:Data:- -: 0:Runs:0 -: 0:Programs:0 -: 1:int #####: 2:main() -: 3:{ #####: 4: return 0; -: 5:} afineman@hotdog:/tmp$