https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54224
--- Comment #29 from Dominique d'Humieres <dominiq at lps dot ens.fr> --- I have tried the following patch --- ../_clean/gcc/fortran/trans-decl.c 2015-10-29 18:20:14.000000000 +0100 +++ gcc/fortran/trans-decl.c 2015-11-03 19:39:39.000000000 +0100 @@ -285,7 +285,11 @@ gfc_build_label_decl (tree label_id) void gfc_set_decl_location (tree decl, locus * loc) { - DECL_SOURCE_LOCATION (decl) = loc->lb->location; + unsigned int offset = loc->nextc - loc->lb->line; + DECL_SOURCE_LOCATION (decl) = linemap_position_for_loc_and_offset (line_table, + loc->lb->location, + offset); + /* DECL_SOURCE_LOCATION (decl) = loc->lb->location; */ } but it does not fix the issue and makes gfortran.dg/array_constructor_type_14.f03 and gfortran.dg/realloc_on_assign_18.f90 regress /opt/gcc/work/gcc/testsuite/gfortran.dg/array_constructor_type_14.f03:7:0: PROGRAM test 1 internal compiler error: in linemap_position_for_loc_and_offset, at libcpp/line-map.c:714 so I give up. I am planning to submit the following patch, open a new PR for the bad locus, then close this PR as fixed. --- ../_clean/gcc/testsuite/gfortran.dg/warn_unused_function_2.f90 2014-03-26 17:49:50.000000000 +0100 +++ gcc/testsuite/gfortran.dg/warn_unused_function_2.f90 2015-11-03 12:47:30.000000000 +0100 @@ -2,6 +2,7 @@ ! { dg-options "-Wall" } ! ! [4.8 Regression] PR 54997: -Wunused-function gives false warnings +! PR 54224: missing warnings with -Wunused-function ! ! Contributed by Janus Weil <ja...@gcc.gnu.org> @@ -14,6 +15,9 @@ contains subroutine s1 ! { dg-warning "defined but not used" } call s2(s3) + contains + subroutine s4 ! { dg-warning "defined but not used" } + end subroutine end subroutine subroutine s2(dummy) ! { dg-warning "Unused dummy argument" } @@ -30,5 +34,10 @@ subroutine sub entry en end subroutine +program test +contains + subroutine s5 ! { dg-warning "defined but not used" } + end subroutine +end ! { dg-final { cleanup-modules "m" } }