public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran] PR 54997: -Wunused-function gives false warnings for procedures passed as actual argument
@ 2012-10-21 23:33 Janus Weil
  2012-10-22 15:22 ` Janus Weil
  0 siblings, 1 reply; 6+ messages in thread
From: Janus Weil @ 2012-10-21 23:33 UTC (permalink / raw)
  To: gfortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1036 bytes --]

Hi all,

here is another patch to silence some more of the bogus warnings about
unused functions that gfortran is currently throwing (cf. also the
previous patch for PR 54224).

It fixes the usage of the 'referenced' attribute, which should only be
given to procedures which are actually 'used' (called/referenced).
Then TREE_USED is set according to this attribute, which in turn
silences the warning in the middle-end.

The patch was regtested on x86_64-unknown-linux-gnu. Ok for trunk?

Cheers,
Janus


2012-10-21  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-10-21  Janus Weil  <janus@gcc.gnu.org>

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

[-- Attachment #2: pr54997.diff --]
[-- Type: application/octet-stream, Size: 2322 bytes --]

Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(revision 192619)
+++ gcc/fortran/trans-decl.c	(working copy)
@@ -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);
@@ -1854,6 +1855,9 @@ build_function_decl (gfc_symbol * sym, bool global
 	  || sym->attr.public_used))
     TREE_PUBLIC (fndecl) = 1;
 
+  if (sym->attr.referenced)
+    TREE_USED (fndecl) = 1;
+
   attributes = add_attributes_to_decl (attr, NULL_TREE);
   decl_attributes (&fndecl, attributes, 0);
 
Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 192619)
+++ gcc/fortran/decl.c	(working copy)
@@ -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)
Index: gcc/fortran/parse.c
===================================================================
--- gcc/fortran/parse.c	(revision 192619)
+++ gcc/fortran/parse.c	(working copy)
@@ -3928,7 +3928,6 @@ gfc_fixup_sibling_symbols (gfc_symbol *sym, gfc_na
   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

[-- Attachment #3: warn_unused_function_2.f90 --]
[-- Type: application/octet-stream, Size: 548 bytes --]

! { dg-do compile }
! { dg-options "-Wall" }
!
! PR 54997: -Wunused-function gives false warnings for procedures passed as actual argument
!
! 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

! { dg-final { cleanup-modules "m" } }

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-11-26 11:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-21 23:33 [Patch, Fortran] PR 54997: -Wunused-function gives false warnings for procedures passed as actual argument Janus Weil
2012-10-22 15:22 ` Janus Weil
2012-10-29 20:36   ` Janus Weil
2012-11-25 19:17   ` Mikael Morin
2012-11-26 11:21     ` Janus Weil
2012-11-26 11:48       ` Mikael Morin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).