https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78792
Bug ID: 78792 Summary: gfortran + gcov confused by #line directive Product: gcc Version: 6.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: gcov-profile Assignee: unassigned at gcc dot gnu.org Reporter: patrick.seewald at gmail dot com Target Milestone: --- $ cat example.in PROGRAM example PRINT *, "example" END PROGRAM $ cat example.f90 #line 1 "example.in" PROGRAM example PRINT *, "example" END PROGRAM $ gfortran -fprofile-arcs -ftest-coverage -cpp example.f90 -o example.out $ ./example.out $ gcov example.in File 'example.f90' Lines executed:100.00% of 3 Creating 'example.f90.gcov' $ cat example.f90.gcov -: 0:Source:example.f90 -: 0:Graph:example.gcno -: 0:Data:example.gcda -: 0:Runs:1 -: 0:Programs:1 1: 1:#line 1 "example.in" 1: 2:PROGRAM example 2: 3:PRINT *, "example" -: 4:END PROGRAM The output example.f90.gcov refers to example.f90 instead of example.in. Note that the line statistics are shifted by one line, I guess they really refer to the line numbers of example.in. For some reason, the coverage report is correct if an #include statement is present: $ touch inc $ cat example2.in #include "inc" PROGRAM example2 PRINT *, "example2" END PROGRAM $ cat example2.f90 #line 1 "example2.in" #include "inc" PROGRAM example2 PRINT *, "example2" END PROGRAM $ gfortran -fprofile-arcs -ftest-coverage -cpp example2.f90 -o example2.out $ ./example2.out $ gcov example2.in File 'example2.in' Lines executed:100.00% of 3 Creating 'example2.in.gcov' $ cat example2.in.gcov -: 0:Source:example2.in -: 0:Graph:example2.gcno -: 0:Data:example2.gcda -: 0:Runs:1 -: 0:Programs:1 -: 1:#include "inc" 1: 2:PROGRAM example2 1: 3:PRINT *, "example2" 2: 4:END PROGRAM