From: Janus Weil Date: Mon, 26 Nov 2012 11:16:31 +0000 (+0100) Subject: re PR fortran/54997 (-Wunused-function gives false warnings) X-Git-Tag: upstream/12.2.0~72587 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=29be7510afa5761eb64db71df7ef8b2d2d57d8cf;p=platform%2Fupstream%2Fgcc.git re PR fortran/54997 (-Wunused-function gives false warnings) 2012-11-26 Janus Weil 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 PR fortran/54997 * gfortran.dg/warn_unused_function_2.f90: New. From-SVN: r193811 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 1223dcb..d6c759c 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,5 +1,15 @@ 2012-11-26 Janus Weil + 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 + PR fortran/54881 * match.c (select_derived_set_tmp,select_class_set_tmp): Removed and unified into ... diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 6f609e9..77ca993 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -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) diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c index f31e309..659e9fc 100644 --- a/gcc/fortran/parse.c +++ b/gcc/fortran/parse.c @@ -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 diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 6827298..9adcb8b 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f59ff29..ce211d2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2012-11-26 Janus Weil + PR fortran/54997 + * gfortran.dg/warn_unused_function_2.f90: New. + +2012-11-26 Janus Weil + PR fortran/54881 * gfortran.dg/associated_6.f90: New. * gfortran.dg/select_type_30.f03: New. diff --git a/gcc/testsuite/gfortran.dg/warn_unused_function_2.f90 b/gcc/testsuite/gfortran.dg/warn_unused_function_2.f90 new file mode 100644 index 0000000..8d65dab --- /dev/null +++ b/gcc/testsuite/gfortran.dg/warn_unused_function_2.f90 @@ -0,0 +1,34 @@ +! { dg-do compile } +! { dg-options "-Wall" } +! +! [4.8 Regression] PR 54997: -Wunused-function gives false warnings +! +! Contributed by Janus Weil + +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" } }