Bug 30236 - [4.1 only]alternate-return subroutine in generic interface causes ice/segfault
Summary: [4.1 only]alternate-return subroutine in generic interface causes ice/segfault
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.2.0
Assignee: Paul Thomas
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2006-12-17 06:13 UTC by Brooks Moses
Modified: 2007-01-10 19:00 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-12-17 14:23:03


Attachments
Patch for PR (201 bytes, patch)
2006-12-17 15:46 UTC, Paul Thomas
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brooks Moses 2006-12-17 06:13:02 UTC
The following code contains a generic interface which has two procedures, one with an alternate return and one without.  This causes a segfault ICE.  If either of the "module procedure" lines are commented out, however, the program compiles.

Note, however, that adding an alternate return argument to the "with" subroutine does not prevent the ICE.

I believe that this is valid code, as I have (unfortunately) not found any prohibition in the standard against procedures with alternate returns in generic interfaces.

-----------------------------------------------------------------------

debian-gfortran:~/test> cat arswitch.f90
module arswitch
  implicit none
  interface gen
    module procedure with
    module procedure without
  end interface
contains
  subroutine with(i,*)
    integer i
    if (i>0) then
      return 1
    else
      return
    end if
  end subroutine
  subroutine without()
    return
  end subroutine
end module

program test
  use arswitch
  implicit none
end
debian-gfortran:~/test> ../bin-trunk/bin/gfortran arswitch.f90 -o arswitch
arswitch.f90:0: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

debian-gfortran:~/test> ../bin-trunk/bin/gfortran --version
GNU Fortran 95 (GCC) 4.3.0 20061128 (experimental)
Copyright (C) 2006 Free Software Foundation, Inc.
Comment 1 Paul Thomas 2006-12-17 14:23:03 UTC
Brooks,

The standard has no problem with this, as you surmise.

The first segfault is in count_types_test, where an attempt is made to use the non-existent formal symbol. This should be asy to fix - it's a matter of perspiration rather than inspiration.  I'll give it a go tonight, since I am into an INTERFACE bee....

Thanks

Paul
Comment 2 Paul Thomas 2006-12-17 15:46:44 UTC
Created attachment 12821 [details]
Patch for PR

This produces code that works correctly and is halfway through a regtest.

I'll do the submit tonight.

Paul
Comment 3 patchapp@dberlin.org 2006-12-18 07:10:20 UTC
Subject: Bug number PR30236

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-12/msg01254.html
Comment 4 Paul Thomas 2006-12-19 17:02:36 UTC
Subject: Bug 30236

Author: pault
Date: Tue Dec 19 17:02:20 2006
New Revision: 120052

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=120052
Log:
2006-12-19  Paul Thomas <pault@gcc.gnu.org>

	PR fortran/30236
	* interface.c (compare_interfaces): Handle NULL symbols.
	(count_types_test): Count NULL symbols, which correspond to
	alternate returns.

	(check_interface1): Change final argument from int to bool
	in the function and all references.

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

	PR fortran/30236
	* gfortran.dg/altreturn_3.f90: New test.

	* gfortran.dg/char_result_12.f90: Fix comment typos.

Added:
    trunk/gcc/testsuite/gfortran.dg/altreturn_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/interface.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/char_result_12.f90

Comment 5 Paul Thomas 2006-12-19 17:06:21 UTC
Brooks,

I did as you suggested to altreturn_3.f90. I added a couple of tests to make sure that the alternate returns were indeed threading their way through the programme by selection on the correct values.  That sounds convoluted - take a look at what I did!

Paul
Comment 6 Paul Thomas 2006-12-31 15:00:51 UTC
Subject: Bug 30236

Author: pault
Date: Sun Dec 31 15:00:18 2006
New Revision: 120298

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=120298
Log:
2006-12-31  Paul Thomas <pault@gcc.gnu.org>

	BACKPORTS from 4.3

	PR fortran/30202
	* trans-array.c (gfc_conv_function_call): Use parmse.expr for
	the nullifying of intent(out) arguments rather than the backend
	declaration.

	PR fortran/30190
	* trans-array.c (gfc_conv_array_ref): Remove gfc_evaluate_now
	from the -fbounds-check branch.

	PR fortran/29992
	* interface.c (check_sym_interfaces): Module procedures in a
	generic must be use associated or contained in the module.
	* decl.c (gfc_match_modproc): Set attribute mod_proc.
	* gfortran.h (symbol_attribute): Add mod_proc atribute.

	PR fortran/30081
	* resolve.c (resolve_generic_f, resolve_generic_s): Use
	gfc_intrinsic_name to find out if the function is intrinsic
	because it does not have to be a generic intrinsic to be
	overloaded.

	PR fortran/30236
	* interface.c (compare_interfaces): Handle NULL symbols.
	(count_types_test): Count NULL symbols, which correspond to
	alternate returns.

	(check_interface1): Change final argument from int to bool
	in the function and all references.

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

	BACKPORTS from 4.3

	PR fortran/30202
	* gfortran.dg/alloc_comp_basics_3.f90: New test.

	PR fortran/30190
	* gfortran.dg/bounds_check_5.f90: New test.

	PR fortran/29992
	* gfortran.dg/generic_9.f90: New test.

	PR fortran/30081
	* gfortran.dg/generic_10.f90: New test.

	PR fortran/30236
	* gfortran.dg/altreturn_3.f90: New test.

	* gfortran.dg/char_result_12.f90: Fix comment typos.


Added:
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/alloc_comp_basics_3.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/bounds_check_5.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/generic_10.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/generic_9.f90
Modified:
    branches/gcc-4_2-branch/gcc/fortran/ChangeLog
    branches/gcc-4_2-branch/gcc/fortran/decl.c
    branches/gcc-4_2-branch/gcc/fortran/gfortran.h
    branches/gcc-4_2-branch/gcc/fortran/interface.c
    branches/gcc-4_2-branch/gcc/fortran/resolve.c
    branches/gcc-4_2-branch/gcc/fortran/trans-array.c
    branches/gcc-4_2-branch/gcc/fortran/trans-expr.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog

Comment 7 Paul Thomas 2006-12-31 15:19:40 UTC
Fixed on trunk and 4.2

Paul