This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, fortran] Fix PR 30235
- From: Brooks Moses <brooks dot moses at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: fortran at gcc dot gnu dot org
- Date: Sun, 17 Dec 2006 11:08:36 -0800
- Subject: [patch, fortran] Fix PR 30235
In interface.c, when compare_actual_formal() has finished checking all
of the actual arguments, it then loops through any remaining formal
arguments to confirm that they are all optional. When doing this, it
looks at f->sym->attr.optional. However, if the formal argument is an
alternate return, then f->sym is NULL, and this causes a segfault ICE.
The attached patch adds a check for this, approximately copied from the
checks a bit earlier in the function when compare_actual_formal() is
checking actual arguments against formal ones.
The testcase is derived from the example program that I attached to the
PR when I filed it.
--------------------------------------------------------------
2006-12-17 Brooks Moses <brooks.moses@codesourcery.com>
PR 30235
* interface.c (compare_actual_formal): check for
alternate returns when iterating over non-present
arguments.
--------------------------------------------------------------
2006-12-17 Brooks Moses <brooks.moses@codesourcery.com>
PR 30235
* gfortran.dg/altreturn_2.f90: new test.
--------------------------------------------------------------
Tested on i686_pc_linux_gnu; everything works, except that without the
interface.c patch the failures on the new test don't seem to cycle
through the -O1, O2, etc. flags like they should; instead I only get this:
FAIL: gfortran.dg/altreturn_2.f90 -O (internal compiler error)
FAIL: gfortran.dg/altreturn_2.f90 -O (test for errors, line 3)
FAIL: gfortran.dg/altreturn_2.f90 -O (test for excess errors)
Any idea what I'm missing?
Ok for trunk, once I fix that testsuite problem?
Should this be backported to 4.2 (and, if so, on what sort of timeschedule)?
- Brooks
Index: fortran/interface.c
===================================================================
--- fortran/interface.c (revision 119980)
+++ fortran/interface.c (working copy)
@@ -1446,6 +1446,13 @@
{
if (new[i] != NULL)
continue;
+ if (f->sym == NULL)
+ {
+ if (where)
+ gfc_error ("Missing alternate return spec in subroutine call at %L",
+ where);
+ return 0;
+ }
if (!f->sym->attr.optional)
{
if (where)
Index: testsuite/gfortran.dg/altreturn_2.f90
===================================================================
--- testsuite/gfortran.dg/altreturn_2.f90 (revision 0)
+++ testsuite/gfortran.dg/altreturn_2.f90 (revision 0)
@@ -0,0 +1,8 @@
+! { dg-do compile }
+ program altreturn_2
+ call foo() ! { dg-error "Missing alternate return" }
+ contains
+ subroutine foo(*)
+ return
+ end subroutine
+ end program