This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[Patch, fortran] PR30476 - [Regression 4.2, 4.3] Via other module imported generic interface rejected
- From: Paul Thomas <paulthomas2 at wanadoo dot fr>
- To: Tobias Burnus <burnus at net-b dot de>, Fortran List <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 16 Jan 2007 15:47:25 +0100
- Subject: [Patch, fortran] PR30476 - [Regression 4.2, 4.3] Via other module imported generic interface rejected
:ADDPATCH fortran:
This one I could do with like a hole in the head but since I caused it,
I had better fix it :-)
The offending patch is that for PR29975, in which a generic interface
that is being read is ambiguous if there is already a symbol of the same
name that is not a generic interface. This permits fusing of generic
interfaces but disallows a generic interface to be ambiguous with
another type of object. It turns out that this test should have also
checked that the symbol and the generic interface come from different
modules. This then exposed the fact that the module name was not
getting written to the generic interface field in the originating module
file, for reasons that are not apparent to me at all. The attached
patch plugs both these holes. The testcase is the originator's.
Since this patch further restricts the range of applicability of this
ambiguity, I am certain that it is "safer" than the original. For this
reason, I propose to apply it immediately after review to trunk and 4.2,
since the PR does represent a serious regression on both.
Regtested on Cygwin_NT/amd64 - OK for trunk and 4.2?
Paul
2007-01-16 Paul Thomas <pault@gcc.gnu.org>
PR fortran/30476
* module.c (load_generic_interfaces): Make the marking of the
symbol as ambiguous conditional on the module names being
different.
(write_generic): Ensure that the generic interface has a
non-NULL module field.
2007-01-16 Paul Thomas <pault@gcc.gnu.org>
PR fortran/30476
* gfortran.dg/generic_12.f90: New test.
Index: gcc/fortran/module.c
===================================================================
*** gcc/fortran/module.c (revision 120789)
--- gcc/fortran/module.c (working copy)
*************** load_generic_interfaces (void)
*** 3097,3105 ****
gfc_symtree *st;
p = p ? p : name;
st = gfc_find_symtree (gfc_current_ns->sym_root, p);
! st->ambiguous = sym->attr.generic ? 0 : 1;
}
-
if (i == 1)
{
mio_interface_rest (&sym->generic);
--- 3097,3106 ----
gfc_symtree *st;
p = p ? p : name;
st = gfc_find_symtree (gfc_current_ns->sym_root, p);
! if (module && sym->module
! && strcmp(module, sym->module) != 0)
! st->ambiguous = sym->attr.generic ? 0 : 1;
}
if (i == 1)
{
mio_interface_rest (&sym->generic);
*************** write_generic (gfc_symbol * sym)
*** 3748,3753 ****
--- 3749,3757 ----
|| !gfc_check_access (sym->attr.access, sym->ns->default_access))
return;
+ if (sym->module == NULL)
+ sym->module = gfc_get_string (module_name);
+
mio_symbol_interface (&sym->name, &sym->module, &sym->generic);
}
Index: gcc/testsuite/gfortran.dg/generic_12.f90
===================================================================
*** gcc/testsuite/gfortran.dg/generic_12.f90 (revision 0)
--- gcc/testsuite/gfortran.dg/generic_12.f90 (revision 0)
***************
*** 0 ****
--- 1,32 ----
+ ! { dg-do compile }
+ ! Test the fix for PR30476 in which the generic interface hello
+ ! was found incorrectly to be ambiguous.
+ !
+ !Contributed by Tobias Burnus <burnus@gcc.gnu.org>
+ !
+ SUBROUTINE hello_x(dum)
+ IMPLICIT NONE
+ INTEGER :: dum
+ WRITE(0,*) "Hello world: ", dum
+ END SUBROUTINE hello_x
+
+ MODULE interfaces
+ IMPLICIT NONE
+ INTERFACE hello
+ SUBROUTINE hello_x(dum)
+ IMPLICIT NONE
+ INTEGER :: dum
+ END SUBROUTINE hello_x
+ END INTERFACE
+ END MODULE interfaces
+
+ MODULE global_module
+ USE interfaces
+ END MODULE global_module
+
+ PROGRAM main
+ USE global_module
+ IMPLICIT NONE
+ CALL hello(10)
+ END PROGRAM main
+ ! { dg-final { cleanup-modules "interfaces global_module" } }