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] PR29373 and PR29407 - more association problems


:ADDPATCH fortran:

Two more fixes for things that can loosely be described as association:

PR29373 is due to an implicit character length screwing up a function declaration because the functions in decl.c have not been told about implicit types. The patch is 'obvious'. However, once this association problem is fixed, another, to do with array constructors, is exposed. This has been re-emitted as PR29431.

PR29407 comes about because a local variable declaration is ignored, which triggers a conflict between the procedure and namelist attributes of an object in the encompassing namespace. The fix is to stop looking for such conflicts, if the symbol, already in the namelist, is perfectly satisfactory.

Apart from avoiding PR29431 in the first, the test cases are those from the reporters.

Regtested on amd64/Cygwin_NT - OK for trunk?

Paul

2006-10-12 Paul Thomas <pault@gcc.gnu.org>

   PR fortran/29373
   * decl.c (get_proc_name, gfc_match_function_decl): Add
   attr.implicit_type to conditions that throw error for
   existing explicit interface and that allow new type-
   spec to be applied.

   PR fortran/29407
   * resolve.c (resolve_fl_namelist): Do not check for
   nemlist/procedure conflict, if the symbol corresponds
   to a good local variable declaration.

2006-10-12 Paul Thomas <pault@gcc.gnu.org>

   PR fortran/29373
   * gfortran.dg/implicit_9.f90: New test.

   PR fortran/29407
   * gfortran.dg/namelist_25.f90: New test.


Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c	(revision 117628)
--- gcc/fortran/resolve.c	(working copy)
*************** resolve_fl_namelist (gfc_symbol *sym)
*** 5668,5683 ****
       same message has been used.  */
    for (nl = sym->namelist; nl; nl = nl->next)
      {
        nlsym = NULL;
! 	if (sym->ns->parent && nl->sym && nl->sym->name)
! 	  gfc_find_symbol (nl->sym->name, sym->ns->parent, 0, &nlsym);
! 	if (nlsym && nlsym->attr.flavor == FL_PROCEDURE)
! 	  {
! 	    gfc_error ("PROCEDURE attribute conflicts with NAMELIST "
! 		       "attribute in '%s' at %L", nlsym->name,
! 		       &sym->declared_at);
! 	    return FAILURE;
! 	  }
      }
  
    return SUCCESS;
--- 5668,5685 ----
       same message has been used.  */
    for (nl = sym->namelist; nl; nl = nl->next)
      {
+       if (nl->sym->ts.kind != 0 && nl->sym->attr.flavor == FL_VARIABLE)
+ 	continue;
        nlsym = NULL;
!       if (sym->ns->parent && nl->sym && nl->sym->name)
! 	gfc_find_symbol (nl->sym->name, sym->ns->parent, 0, &nlsym);
!       if (nlsym && nlsym->attr.flavor == FL_PROCEDURE)
! 	{
! 	  gfc_error ("PROCEDURE attribute conflicts with NAMELIST "
! 		     "attribute in '%s' at %L", nlsym->name,
! 		     &sym->declared_at);
! 	  return FAILURE;
! 	}
      }
  
    return SUCCESS;
Index: gcc/fortran/decl.c
===================================================================
*** gcc/fortran/decl.c	(revision 117628)
--- gcc/fortran/decl.c	(working copy)
*************** get_proc_name (const char *name, gfc_sym
*** 643,648 ****
--- 643,649 ----
  	 signature for this is that ts.kind is set.  Legitimate
  	 references only set ts.type.  */
        if (sym->ts.kind != 0
+ 	    && !sym->attr.implicit_type
  	    && sym->attr.proc == 0
  	    && gfc_current_ns->parent != NULL
  	    && sym->attr.access == 0
*************** gfc_match_function_decl (void)
*** 2679,2685 ****
        || copy_prefix (&sym->attr, &sym->declared_at) == FAILURE)
      goto cleanup;
  
!   if (current_ts.type != BT_UNKNOWN && sym->ts.type != BT_UNKNOWN)
      {
        gfc_error ("Function '%s' at %C already has a type of %s", name,
  		 gfc_basic_typename (sym->ts.type));
--- 2680,2688 ----
        || copy_prefix (&sym->attr, &sym->declared_at) == FAILURE)
      goto cleanup;
  
!   if (current_ts.type != BT_UNKNOWN
! 	&& sym->ts.type != BT_UNKNOWN
! 	&& !sym->attr.implicit_type)
      {
        gfc_error ("Function '%s' at %C already has a type of %s", name,
  		 gfc_basic_typename (sym->ts.type));
Index: gcc/testsuite/gfortran.dg/implicit_9.f90
===================================================================
*** gcc/testsuite/gfortran.dg/implicit_9.f90	(revision 0)
--- gcc/testsuite/gfortran.dg/implicit_9.f90	(revision 0)
***************
*** 0 ****
--- 1,24 ----
+ ! { dg-do compile }
+ ! Tests patch for PR29373, in which the implicit character
+ ! statement messes up the function declaration because the
+ ! requisite functions in decl.c were told nothing about
+ ! implicit types.
+ !
+ ! Contributed by Tobias Schlueter  <tobi@gcc.gnu.org>
+ !
+   implicit character*32 (a-z)
+   CHARACTER(len=255), DIMENSION(1,2)  :: a
+ 
+ ! Reporters original, which triggers another error:
+ ! gfc_todo: Not Implemented: complex character array
+ ! constructors.=> PR29431
+ !  a = reshape((/ to_string(1.0) /), (/ 1, 2 /))
+ 
+   a = to_string(1.0)
+   print *, a
+   CONTAINS
+     CHARACTER*(32) FUNCTION to_string(x)
+       REAL, INTENT(in) :: x
+       WRITE(to_string, FMT="(F6.3)") x
+     END FUNCTION
+ END PROGRAM
\ No newline at end of file
Index: gcc/testsuite/gfortran.dg/namelist_25.f90
===================================================================
*** gcc/testsuite/gfortran.dg/namelist_25.f90	(revision 0)
--- gcc/testsuite/gfortran.dg/namelist_25.f90	(revision 0)
***************
*** 0 ****
--- 1,17 ----
+ ! { dg-do compile }
+ ! Tests patch for PR29407, in which the declaration of 'my' as
+ ! a local variable was ignored, so that the procedure and namelist
+ ! attributes for 'my' clashed..
+ !
+ ! Contributed by Tobias Burnus  <tobias.burnus@physik.fu-berlin.de>
+ !
+ program main
+   implicit none
+ contains
+   subroutine my
+   end subroutine my
+   subroutine bar
+     integer :: my
+     namelist /ops/ my
+   end subroutine bar
+ end program main
2006-10-12 Paul Thomas <pault@gcc.gnu.org>

	PR fortran/29373
	* decl.c (get_proc_name, gfc_match_function_decl): Add
	attr.implicit_type to conditions that throw error for
	existing explicit interface and that allow new type-
	spec to be applied.

	PR fortran/29407
	* resolve.c (resolve_fl_namelist): Do not check for
	nemlist/procedure conflict, if the symbol corresponds
	to a good local variable declaration.

2006-10-12 Paul Thomas <pault@gcc.gnu.org>

	PR fortran/29373
	* gfortran.dg/implicit_9.f90: New test.

	PR fortran/29407
	* gfortran.dg/namelist_25.f90: New test.

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