This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, fortran] PR27701 PR29232 and PR29364 - association of objects
- From: Paul Thomas <paulthomas2 at wanadoo dot fr>
- To: "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>, patch <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 11 Oct 2006 17:33:12 +0200
- Subject: [Patch, fortran] PR27701 PR29232 and PR29364 - association of objects
:ADDPATCH fortran:
This patch fixes three problems that are quite difference, except that
they all involve association of objects,... or not:
PR27701 results from an incomplete detection of contained procedures
with the same name; two subroutines with the same name but no arguments
are still capable of passing get_proc_name because the presence of a
formal argument list was used to detect that the procedure was declared
rather than inferred. The fix uses the attributes subrouitine and
function, together with the type of interface being known.
PR29232 pertains to host association of derived types that should be
blocked by the presence of another class I object in the namespace.
This is fixed by searching for a symbol of the same name and checking if
it is the same as the host associated derived type.
PR29364 concerns derived types with derived type pointer components, for
which no derived type declaration is available. At present, gfortran
does not diagnose this at all. The existing test, implicit actual has
had to modified so that the pointer to type is declared correctly; as
required by Lahey, ifort and g95.
The testcases are modelled on the reporters'.
Regtested on AMD64/Cygwin_NT - OK for trunk?
Paul
2006-10-12 Paul Thomas <pault@gcc.gnu.org>
PR fortran/27701
* decl.c (get_proc_name): Replace the detection of a declared
procedure by the presence of a formal argument list by the
attributes of the symbol and the presence of an explicit
interface.
PR fortran/29232
* resolve.c (resolve_fl_variable): See if the host association
of a derived type is blocked by the presence of another type I
object in the current namespace.
PR fortran/29364
* resolve.c (resolve_fl_derived): Check for the presence of
the derived type for a derived type component.
2006-10-12 Paul Thomas <pault@gcc.gnu.org>
PR fortran/27701
* gfortran.dg/same_name_2.f90: New test.
PR fortran/29232
* gfortran.dg/host_assoc_types_1.f90: New test.
PR fortran/29364
* gfortran.dg/missing_derived_type_1.f90: New test.
* gfortran.dg/implicit_actual.f90: Comment out USE GLOBAL.
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
*** 635,641 ****
accessible names. */
if (sym->attr.flavor != 0
&& sym->attr.proc != 0
! && sym->formal)
gfc_error_now ("Procedure '%s' at %C is already defined at %L",
name, &sym->declared_at);
--- 635,642 ----
accessible names. */
if (sym->attr.flavor != 0
&& sym->attr.proc != 0
! && (sym->attr.subroutine || sym->attr.function)
! && sym->attr.if_source != IFSRC_UNKNOWN)
gfc_error_now ("Procedure '%s' at %C is already defined at %L",
name, &sym->declared_at);
Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c (revision 117628)
--- gcc/fortran/resolve.c (working copy)
*************** resolve_fl_variable (gfc_symbol *sym, in
*** 5384,5389 ****
--- 5384,5407 ----
return FAILURE;
}
+ /* Check to see if a derived type is blocked from being host associated
+ by the presence of another class I symbol in the same namespace.
+ 14.6.1.3 of the standard and the discussion on comp.lang.fortran. */
+ if (sym->ts.type == BT_DERIVED && sym->ns != sym->ts.derived->ns)
+ {
+ gfc_symbol *s;
+ gfc_find_symbol (sym->ts.derived->name, sym->ns, 0, &s);
+ if (s && (s->attr.flavor != FL_DERIVED
+ || !gfc_compare_derived_types (s, sym->ts.derived)))
+ {
+ gfc_error ("The type %s cannot be host associated at %L because "
+ "it is blocked by an incompatible object of the same "
+ "name at %L", sym->ts.derived->name, &sym->declared_at,
+ &s->declared_at);
+ return FAILURE;
+ }
+ }
+
/* 4th constraint in section 11.3: "If an object of a type for which
component-initialization is specified (R429) appears in the
specification-part of a module and does not have the ALLOCATABLE
*************** resolve_fl_derived (gfc_symbol *sym)
*** 5577,5582 ****
--- 5595,5609 ----
}
}
+ if (c->ts.type == BT_DERIVED && c->pointer
+ && c->ts.derived->components == NULL)
+ {
+ gfc_error ("The pointer component '%s' of '%s' at %L is a type "
+ "that has not been declared", c->name, sym->name,
+ &c->loc);
+ return FAILURE;
+ }
+
if (c->pointer || c->allocatable || c->as == NULL)
continue;
Index: gcc/testsuite/gfortran.dg/same_name_2.f90
===================================================================
*** gcc/testsuite/gfortran.dg/same_name_2.f90 (revision 0)
--- gcc/testsuite/gfortran.dg/same_name_2.f90 (revision 0)
***************
*** 0 ****
--- 1,16 ----
+ ! ( dg-do compile }
+ ! Tests the fix for PR27701, in which two same name procedures
+ ! were not diagnosed if they had no arguments.
+ !
+ ! Contributed by Arjen Markus <arjen.markus@wldelft.nl>
+ !
+ module aha
+ contains
+ subroutine aa ! { dg-error "Procedure" }
+ write(*,*) 'AA'
+ end subroutine aa
+ subroutine aa ! { dg-error "is already defined" }
+ write(*,*) 'BB'
+ end subroutine aa
+ end module
+ ! { dg-final { cleanup-modules "aha" } }
Index: gcc/testsuite/gfortran.dg/host_assoc_types_1.f90
===================================================================
*** gcc/testsuite/gfortran.dg/host_assoc_types_1.f90 (revision 0)
--- gcc/testsuite/gfortran.dg/host_assoc_types_1.f90 (revision 0)
***************
*** 0 ****
--- 1,18 ----
+ ! { dg-do compile }
+ ! Tests the fix for PR29232, in which the invalid code below was not
+ ! diagnosed.
+ !
+ ! Contributed by Tobias Burnus <tobias.burnus@physik.fu-berlin.de>
+ !
+ MODULE test
+ TYPE vertex
+ INTEGER :: k
+ END TYPE vertex
+ CONTAINS
+ SUBROUTINE S1()
+ TYPE(vertex) :: a ! { dg-error "cannot be host associated" }
+ vertex : DO i=1,2 ! { dg-error "incompatible object of the same name" }
+ ENDDO vertex
+ END SUBROUTINE
+ END MODULE test
+ ! { dg-final { cleanup-modules "test" } }
Index: gcc/testsuite/gfortran.dg/missing_derived_type_1.f90
===================================================================
*** gcc/testsuite/gfortran.dg/missing_derived_type_1.f90 (revision 0)
--- gcc/testsuite/gfortran.dg/missing_derived_type_1.f90 (revision 0)
***************
*** 0 ****
--- 1,14 ----
+ ! { dg-do compile }
+ ! Tests the fix for PR29364, in which the the absence of the derived type
+ ! 'nonexist' was not diagnosed.
+ !
+ ! Contributed by Tobias Burnus <tobias.burnus@physik.fu-berlin.de>
+ !
+ module test
+ implicit none
+ type epot_t
+ integer :: c
+ type(nonexist),pointer :: l ! { dg-error "has not been declared" }
+ end type epot_t
+ end module test
+ ! { dg-final { cleanup-modules "test" } }
2006-10-12 Paul Thomas <pault@gcc.gnu.org>
PR fortran/27701
* decl.c (get_proc_name): Replace the detection of a declared
procedure by the presence of a formal argument list by the
attributes of the symbol and the presence of an explicit
interface.
PR fortran/29232
* resolve.c (resolve_fl_variable): See if the host association
of a derived type is blocked by the presence of another type I
object in the current namespace.
PR fortran/29364
* resolve.c (resolve_fl_derived): Check for the presence of
the derived type for a derived type component.
2006-10-12 Paul Thomas <pault@gcc.gnu.org>
PR fortran/27701
* gfortran.dg/same_name_2.f90: New test.
PR fortran/29232
* gfortran.dg/host_assoc_types_1.f90: New test.
PR fortran/29364
* gfortran.dg/missing_derived_type_1.f90: New test.
* gfortran.dg/implicit_actual.f90: Comment out USE GLOBAL.