re PR fortran/54997 (-Wunused-function gives false warnings)

2012-11-26  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/54997
	* decl.c (match_procedure_decl): Don't set 'referenced' attribute
	for PROCEDURE declarations.
	* parse.c (gfc_fixup_sibling_symbols,parse_contained): Don't set
	'referenced' attribute for all contained procedures.
	* trans-decl.c (gfc_get_symbol_decl): Allow for unreferenced procedures.
	(build_function_decl): Set TREE_USED for referenced procedures.

2012-11-26  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/54997
	* gfortran.dg/warn_unused_function_2.f90: New.

From-SVN: r193811
This commit is contained in:
Janus Weil 2012-11-26 12:16:31 +01:00
parent 3383b7fa40
commit 29be7510af
6 changed files with 57 additions and 8 deletions

View File

@ -1,3 +1,13 @@
2012-11-26 Janus Weil <janus@gcc.gnu.org>
PR fortran/54997
* decl.c (match_procedure_decl): Don't set 'referenced' attribute
for PROCEDURE declarations.
* parse.c (gfc_fixup_sibling_symbols,parse_contained): Don't set
'referenced' attribute for all contained procedures.
* trans-decl.c (gfc_get_symbol_decl): Allow for unreferenced procedures.
(build_function_decl): Set TREE_USED for referenced procedures.
2012-11-26 Janus Weil <janus@gcc.gnu.org>
PR fortran/54881

View File

@ -4941,8 +4941,6 @@ match_procedure_decl (void)
}
gfc_set_sym_referenced (sym);
if (gfc_match_eos () == MATCH_YES)
return MATCH_YES;
if (gfc_match_char (',') != MATCH_YES)

View File

@ -3928,7 +3928,6 @@ gfc_fixup_sibling_symbols (gfc_symbol *sym, gfc_namespace *siblings)
gfc_symtree *st;
gfc_symbol *old_sym;
sym->attr.referenced = 1;
for (ns = siblings; ns; ns = ns->sibling)
{
st = gfc_find_symtree (ns->sym_root, sym->name);
@ -4050,7 +4049,6 @@ parse_contained (int module)
/* Mark this as a contained function, so it isn't replaced
by other module functions. */
sym->attr.contained = 1;
sym->attr.referenced = 1;
/* Set implicit_pure so that it can be reset if any of the
tests for purity fail. This is used for some optimisation

View File

@ -1195,10 +1195,11 @@ gfc_get_symbol_decl (gfc_symbol * sym)
bool intrinsic_array_parameter = false;
gcc_assert (sym->attr.referenced
|| sym->attr.use_assoc
|| sym->ns->proc_name->attr.if_source == IFSRC_IFBODY
|| (sym->module && sym->attr.if_source != IFSRC_DECL
&& sym->backend_decl));
|| sym->attr.flavor == FL_PROCEDURE
|| sym->attr.use_assoc
|| sym->ns->proc_name->attr.if_source == IFSRC_IFBODY
|| (sym->module && sym->attr.if_source != IFSRC_DECL
&& sym->backend_decl));
if (sym->ns && sym->ns->proc_name && sym->ns->proc_name->attr.function)
byref = gfc_return_by_reference (sym->ns->proc_name);
@ -1851,6 +1852,9 @@ build_function_decl (gfc_symbol * sym, bool global)
|| sym->attr.public_used))
TREE_PUBLIC (fndecl) = 1;
if (sym->attr.referenced || sym->attr.entry_master)
TREE_USED (fndecl) = 1;
attributes = add_attributes_to_decl (attr, NULL_TREE);
decl_attributes (&fndecl, attributes, 0);

View File

@ -1,3 +1,8 @@
2012-11-26 Janus Weil <janus@gcc.gnu.org>
PR fortran/54997
* gfortran.dg/warn_unused_function_2.f90: New.
2012-11-26 Janus Weil <janus@gcc.gnu.org>
PR fortran/54881

View File

@ -0,0 +1,34 @@
! { dg-do compile }
! { dg-options "-Wall" }
!
! [4.8 Regression] PR 54997: -Wunused-function gives false warnings
!
! Contributed by Janus Weil <janus@gcc.gnu.org>
module m
implicit none
private :: s1,s2,s3
contains
subroutine s1 ! { dg-warning "defined but not used" }
call s2(s3)
end subroutine
subroutine s2(dummy) ! { dg-warning "Unused dummy argument" }
procedure() :: dummy
end subroutine
subroutine s3()
end subroutine
end module
subroutine sub
entry en
end subroutine
! { dg-final { cleanup-modules "m" } }