This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch, fortran] PR20880 - Failure to detect procedures encompassing own interface
- From: Paul Thomas <paulthomas2 at wanadoo dot fr>
- To: erik dot edelmann at iki dot fi
- Cc: Fortran List <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 22 Nov 2006 10:21:00 +0100
- Subject: Re: [Patch, fortran] PR20880 - Failure to detect procedures encompassing own interface
- References: <4562BCC3.2090705@wanadoo.fr> <20061121222938.GA13593@localhost.dsl.inet.fi>
erik,
I hate being the bringer of bad news, but this patch doesn't reg.test
cleanly for me on trunk (r119061) on Gentoo Linux/x86; I get
That's alright - we have the patches reviewed for a reason :-)
gfortran.dg/assumed_charlen_function_1.f90 -O (internal compiler error)
gfortran.dg/func_derived_3.f90 -O2 (internal compiler error)
are still fine for me on a tree that was updated last night. I would be
grateful if you would let me have either the appropriate section of the
regtest log and/or a gdb session for these two testcases. The patch is
sufficiently innocuous that I am astonished that there is an
installation difference.
FAIL: gfortran.dg/interface_3.f90
This is my fault - I posted the penultimate version of the patch; the
error next to the function reference was missing. I have attached the
"real" version.
Many thanks
Paul
Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c (revision 119077)
--- gcc/fortran/resolve.c (working copy)
*************** static try
*** 5522,5532 ****
--- 5522,5541 ----
resolve_fl_procedure (gfc_symbol *sym, int mp_flag)
{
gfc_formal_arglist *arg;
+ gfc_symtree *st;
if (sym->attr.function
&& resolve_fl_var_and_proc (sym, mp_flag) == FAILURE)
return FAILURE;
+ st = gfc_find_symtree (gfc_current_ns->sym_root, sym->name);
+ if (st && st->ambiguous && !sym->attr.generic)
+ {
+ gfc_error ("Procedure %s at %L is ambiguous",
+ sym->name, &sym->declared_at);
+ return FAILURE;
+ }
+
if (sym->ts.type == BT_CHARACTER)
{
gfc_charlen *cl = sym->ts.cl;
Index: gcc/fortran/symbol.c
===================================================================
*** gcc/fortran/symbol.c (revision 119075)
--- gcc/fortran/symbol.c (working copy)
*************** gfc_add_explicit_interface (gfc_symbol *
*** 1168,1173 ****
--- 1168,1184 ----
return FAILURE;
}
+ if (current_interface.ns
+ && current_interface.ns->proc_name
+ && current_interface.ns->proc_name->name
+ && strcmp (current_interface.ns->proc_name->name, sym->name) == 0)
+ {
+ gfc_error ("'%s' at %L is the name of the enclosing procedure",
+ sym->name, where);
+ /* Return success so that redundant knock-on errors do not occur. */
+ return SUCCESS;
+ }
+
sym->formal = formal;
sym->attr.if_source = source;
Index: gcc/testsuite/gfortran.dg/interface_3.f90
===================================================================
*** gcc/testsuite/gfortran.dg/interface_3.f90 (revision 0)
--- gcc/testsuite/gfortran.dg/interface_3.f90 (revision 0)
***************
*** 0 ****
--- 1,45 ----
+ ! { dg-do compile }
+ ! Tests the fix for PR20880, which was due to failure to the failure
+ ! to detect the USE association of a nameless interface for a
+ ! procedure with the same name as the encompassing scope.
+ !
+ ! Contributed by
+ !
+ module test_mod
+ interface
+ subroutine my_sub (a)
+ real a
+ end subroutine
+ end interface
+ interface
+ function my_fun (a)
+ real a, my_fun
+ end function
+ end interface
+ end module
+
+ ! This is the original PR
+ subroutine my_sub (a) ! { dg-error "is ambiguous" }
+ use test_mod
+ real a
+ print *, a
+ end subroutine
+
+ integer function my_fun (a) ! { dg-error "is ambiguous" }
+ use test_mod
+ real a
+ print *, a
+ my_fun = 1 ! { dg-error "ambiguous reference" }
+ end function
+
+ ! This was found whilst investigating => segfault
+ subroutine thy_sub (a)
+ interface
+ subroutine thy_sub (a) ! { dg-error "enclosing procedure" }
+ real a
+ end subroutine
+ end interface
+ real a
+ print *, a
+ end subroutine
+ ! { dg-final { cleanup-modules "test_mod" } }