This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, fortran] PR18111 - spurious warnings with -W -Wunused


:ADDPATCH fortran:

The source of this problem is that various of the declarations that are made by the compiler are not marked as either being TREE_USED or DECL_ARTIFICIAL. Since none can be referenced by the original fortran, it is the latter flag which should be set. As explained in both the ChangeLog and the testcase, the three categories of declaration that are now so marked are:

(i) Dummy arrays, where a copy or a new array is made. Here the original is set DECL_ARTIFICAL;
(ii) The __ENTRY dummy in entry_master functions; and
(iii) The parameters, representing the original dummies, in entry thunks.


(i) is spread over two functions because gfc_build_dummy_array_decl resets the backend_decl for some arrays. Before this is done, the artificial flag is set.

The testcase is a straight forward check that the above work. Rather than using compiler flags -W and -Wunused, I used -Wunused-parameter, since that was always where the problem was. However, the original flags would catch regressions for which we do not otherwise check and I am open to setting it that way.

Regtested on SUSE10.1/amd64 - OK for trunk and 4.1?

Paul

2006-08-18 Paul Thomas <pault@gcc.gnu.org>

   PR fortran/18111
   * trans-decl.c (gfc_build_dummy_array_decl): Before resetting
   reference to backend_decl, set it DECL_ARTIFICIAL.
   (gfc_get_symbol_decl): Likewise for original dummy decl, when
   a copy is made of an array.
   (create_function_arglist): Likewise for the _entry paramter
   in entry_masters.
   (build_entry_thunks): Likewise for dummies in entry thunks.

2006-08-18 Paul Thomas <pault@gcc.gnu.org>

   PR fortran/18111
   * gfortran.dg/unused_artificial_dummies_1.f90: New test.

Index: gcc/fortran/trans-decl.c
===================================================================
*** gcc/fortran/trans-decl.c	(revision 116226)
--- gcc/fortran/trans-decl.c	(working copy)
*************** gfc_build_dummy_array_decl (gfc_symbol *
*** 728,733 ****
--- 728,734 ----
        /* We now have an expression for the element size, so create a fully
  	 qualified type.  Reset sym->backend decl or this will just return the
  	 old type.  */
+       DECL_ARTIFICIAL (sym->backend_decl) = 1;
        sym->backend_decl = NULL_TREE;
        type = gfc_sym_type (sym);
        packed = 2;
*************** gfc_get_symbol_decl (gfc_symbol * sym)
*** 892,899 ****
        /* Use a copy of the descriptor for dummy arrays.  */
        if (sym->attr.dimension && !TREE_USED (sym->backend_decl))
          {
!           sym->backend_decl =
!             gfc_build_dummy_array_decl (sym, sym->backend_decl);
  	}
  
        TREE_USED (sym->backend_decl) = 1;
--- 893,903 ----
        /* Use a copy of the descriptor for dummy arrays.  */
        if (sym->attr.dimension && !TREE_USED (sym->backend_decl))
          {
! 	  decl = gfc_build_dummy_array_decl (sym, sym->backend_decl);
! 	  /* Prevent the dummy from being detected as unused if it is copied.  */
! 	  if (sym->backend_decl != NULL && decl != sym->backend_decl)
! 	    DECL_ARTIFICIAL (sym->backend_decl) = 1;
! 	  sym->backend_decl = decl;
  	}
  
        TREE_USED (sym->backend_decl) = 1;
*************** create_function_arglist (gfc_symbol * sy
*** 1284,1289 ****
--- 1288,1294 ----
        DECL_ARG_TYPE (parm) = type;
        TREE_READONLY (parm) = 1;
        gfc_finish_decl (parm, NULL_TREE);
+       DECL_ARTIFICIAL (parm) = 1;
  
        arglist = chainon (arglist, parm);
        typelist = TREE_CHAIN (typelist);
*************** build_entry_thunks (gfc_namespace * ns)
*** 1603,1608 ****
--- 1608,1614 ----
  	  if (thunk_formal)
  	    {
  	      /* Pass the argument.  */
+ 	      DECL_ARTIFICIAL (thunk_formal->sym->backend_decl) = 1;
  	      args = tree_cons (NULL_TREE, thunk_formal->sym->backend_decl,
  				args);
  	      if (formal->sym->ts.type == BT_CHARACTER)
Index: gcc/testsuite/gfortran.dg/unused_artificial_dummies_1.f90
===================================================================
*** gcc/testsuite/gfortran.dg/unused_artificial_dummies_1.f90	(revision 0)
--- gcc/testsuite/gfortran.dg/unused_artificial_dummies_1.f90	(revision 0)
***************
*** 0 ****
--- 1,49 ----
+ ! { dg-do compile }
+ ! { dg-options "-Wunused-variable -Wunused-parameter" }
+ ! This tests the fix for PR18111 in which some artificial declarations
+ ! were being listed as unused parameters:
+ ! (i) Array dummies, where a copy is made;
+ ! (ii) The dummies of "entry thunks" (ie. the articial procedures that
+ ! represent ENTRYs and call the "entry_master" function; and
+ ! (iii) The __entry parameter of the entry_master function, which
+ ! indentifies the calling entry thunk.
+ ! All of these have DECL_ARTIFICIAL (tree) set.
+ !
+ ! Contributed by Paul Thomas  <pault@gcc.gnu.org>
+ !
+ module foo
+   implicit none
+ contains
+ 
+ !This is the original problem
+ 
+   subroutine bar(arg1, arg2, arg3, arg4, arg5)
+     character(len=80), intent(in) :: arg1
+     character(len=80), dimension(:), intent(in) :: arg2
+     integer, dimension(arg4), intent(in) :: arg3
+     integer, intent(in) :: arg4
+     character(len=arg4), intent(in) :: arg5
+     print *, arg1, arg2, arg3, arg4, arg5
+   end subroutine bar
+ 
+ ! This ICED with the first version of the fix because gfc_build_dummy_array_decl
+ ! sometimes NULLS sym->backend_decl; taken from aliasing_dummy_1.f90
+ 
+   subroutine foo1 (slist, i)
+     character(*), dimension(*) :: slist
+     integer i
+     write (slist(i), '(2hi=,i3)') i
+   end subroutine foo1
+ 
+ ! This tests the additions to the fix that prevent the dummies of entry thunks
+ ! and entry_master __entry parameters from being listed as unused.
+ 
+   function f1 (a)
+     integer, dimension (2, 2) :: a, b, f1, e1
+     f1 (:, :) = 15 + a
+     return
+   entry e1 (b)
+     e1 (:, :) = 42 + b
+   end function
+ 
+ end module foo

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]