Commit 29be7510 by Janus Weil

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
parent 3383b7fa
2012-11-26 Janus Weil <janus@gcc.gnu.org> 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 PR fortran/54881
* match.c (select_derived_set_tmp,select_class_set_tmp): Removed and * match.c (select_derived_set_tmp,select_class_set_tmp): Removed and
unified into ... unified into ...
......
...@@ -4941,8 +4941,6 @@ match_procedure_decl (void) ...@@ -4941,8 +4941,6 @@ match_procedure_decl (void)
} }
gfc_set_sym_referenced (sym);
if (gfc_match_eos () == MATCH_YES) if (gfc_match_eos () == MATCH_YES)
return MATCH_YES; return MATCH_YES;
if (gfc_match_char (',') != MATCH_YES) if (gfc_match_char (',') != MATCH_YES)
......
...@@ -3928,7 +3928,6 @@ gfc_fixup_sibling_symbols (gfc_symbol *sym, gfc_namespace *siblings) ...@@ -3928,7 +3928,6 @@ gfc_fixup_sibling_symbols (gfc_symbol *sym, gfc_namespace *siblings)
gfc_symtree *st; gfc_symtree *st;
gfc_symbol *old_sym; gfc_symbol *old_sym;
sym->attr.referenced = 1;
for (ns = siblings; ns; ns = ns->sibling) for (ns = siblings; ns; ns = ns->sibling)
{ {
st = gfc_find_symtree (ns->sym_root, sym->name); st = gfc_find_symtree (ns->sym_root, sym->name);
...@@ -4050,7 +4049,6 @@ parse_contained (int module) ...@@ -4050,7 +4049,6 @@ parse_contained (int module)
/* Mark this as a contained function, so it isn't replaced /* Mark this as a contained function, so it isn't replaced
by other module functions. */ by other module functions. */
sym->attr.contained = 1; sym->attr.contained = 1;
sym->attr.referenced = 1;
/* Set implicit_pure so that it can be reset if any of the /* Set implicit_pure so that it can be reset if any of the
tests for purity fail. This is used for some optimisation tests for purity fail. This is used for some optimisation
......
...@@ -1195,6 +1195,7 @@ gfc_get_symbol_decl (gfc_symbol * sym) ...@@ -1195,6 +1195,7 @@ gfc_get_symbol_decl (gfc_symbol * sym)
bool intrinsic_array_parameter = false; bool intrinsic_array_parameter = false;
gcc_assert (sym->attr.referenced gcc_assert (sym->attr.referenced
|| sym->attr.flavor == FL_PROCEDURE
|| sym->attr.use_assoc || sym->attr.use_assoc
|| sym->ns->proc_name->attr.if_source == IFSRC_IFBODY || sym->ns->proc_name->attr.if_source == IFSRC_IFBODY
|| (sym->module && sym->attr.if_source != IFSRC_DECL || (sym->module && sym->attr.if_source != IFSRC_DECL
...@@ -1851,6 +1852,9 @@ build_function_decl (gfc_symbol * sym, bool global) ...@@ -1851,6 +1852,9 @@ build_function_decl (gfc_symbol * sym, bool global)
|| sym->attr.public_used)) || sym->attr.public_used))
TREE_PUBLIC (fndecl) = 1; TREE_PUBLIC (fndecl) = 1;
if (sym->attr.referenced || sym->attr.entry_master)
TREE_USED (fndecl) = 1;
attributes = add_attributes_to_decl (attr, NULL_TREE); attributes = add_attributes_to_decl (attr, NULL_TREE);
decl_attributes (&fndecl, attributes, 0); decl_attributes (&fndecl, attributes, 0);
......
2012-11-26 Janus Weil <janus@gcc.gnu.org> 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 PR fortran/54881
* gfortran.dg/associated_6.f90: New. * gfortran.dg/associated_6.f90: New.
* gfortran.dg/select_type_30.f03: New. * gfortran.dg/select_type_30.f03: New.
......
! { 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" } }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment