Bug 19546 - Internal subroutine setting function return value gives internal compiler error
Summary: Internal subroutine setting function return value gives internal compiler error
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.2.0
Assignee: Paul Thomas
URL:
Keywords: ice-on-valid-code
: 23962 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-01-20 15:35 UTC by Neil Martinsen-Burrell
Modified: 2006-03-09 00:35 UTC (History)
4 users (show)

See Also:
Host: powerpc-apple-darwin7.7.0
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-01-27 20:36:22


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Neil Martinsen-Burrell 2005-01-20 15:35:31 UTC
With gcc 4.0.0 20050119 
on powerpc-apple-darwin7.7.0 (Dual G5 mac running Mac OS X 10.3.7) 
and GCC configured with: /Users/nburrell/Desktop/gcc-4.0-cvs/gcc/configure --with-mpfr=/Users/
nburrell/usr --with-gmp=/Users/nburrell/usr --prefix=/Users/nburrell/usr --enable-
languages=c,f95

running the command gfortran -Wall -v -save-temps test_gfortran.f90 gives the following output:

nburrell@braeburn[~/isis_home/research/pvsim/test]$ gfortran -Wall -v -save-temps test_gfortran.f90
Driving: gfortran -Wall -v -save-temps test_gfortran.f90 -lgfortranbegin -lgfortran -shared-libgcc
Using built-in specs.
Configured with: /Users/nburrell/Desktop/gcc-4.0-cvs/gcc/configure --with-mpfr=/Users/nburrell/
usr --with-gmp=/Users/nburrell/usr --prefix=/Users/nburrell/usr --enable-languages=c,f95
Thread model: posix
gcc version 4.0.0 20050119 (experimental)
 /Users/nburrell/usr/libexec/gcc/powerpc-apple-darwin7.7.0/4.0.0/f951 test_gfortran.f90 -fPIC 
-quiet -dumpbase test_gfortran.f90 -auxbase test_gfortran -Wall -version -o test_gfortran.s
GNU F95 version 4.0.0 20050119 (experimental) (powerpc-apple-darwin7.7.0)
        compiled by GNU C version 4.0.0 20050118 (experimental).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
test_gfortran.f90: In function 'set_value':
test_gfortran.f90:15: internal compiler error: in gfc_conv_variable, at fortran/trans-expr.c:317
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

where test_gfortran.f90 has the following contents:

    MODULE random_standard_normal_mod

      IMPLICIT NONE

    CONTAINS

      FUNCTION random_standard_normal()
        IMPLICIT NONE

        REAL :: y
        REAL :: random_standard_normal
        
        y = 4.

        CALL set_value
        RETURN

      CONTAINS

        SUBROUTINE set_value

          IMPLICIT NONE

          random_standard_normal = y
        END SUBROUTINE set_value
      END FUNCTION random_standard_normal
    END MODULE random_standard_normal_mod
Comment 1 Andrew Pinski 2005-01-20 15:42:32 UTC
Confirmed.
Comment 2 Francois-Xavier Coudert 2005-06-06 10:22:21 UTC
Shorter testcase:

function f
  integer :: f
  contains
    subroutine sub
      f = 1
    end subroutine sub
end function f
Comment 3 Andrew Pinski 2005-09-19 15:14:16 UTC
*** Bug 23962 has been marked as a duplicate of this bug. ***
Comment 4 Tobias Schlüter 2006-02-08 15:14:14 UTC
Corrected testcase:
function f()
  integer :: f
  contains
    subroutine sub
      f = 1
    end subroutine sub
end function f

The ICE is now at:
t.f90:4: internal compiler error: in gfc_conv_variable, at fortran/trans-expr.c:354
Comment 5 Paul Thomas 2006-02-12 13:34:29 UTC
A patch is on its way in the next 48 hours - I have it working with no regressions; it needs tidying up and a full set of testcases writing.

Paul
Comment 6 Paul Thomas 2006-02-14 23:11:39 UTC
(In reply to comment #5)
> A patch is on its way in the next 48 hours - I have it working with no
> regressions; it needs tidying up and a full set of testcases writing.

"Tidying up" proved to be a bit bloody once I latched onto entries.... *sigh*
The patch has been submitted a few minutes ago.

Paul
Comment 7 Paul Thomas 2006-03-06 22:56:42 UTC
Subject: Bug 19546

Author: pault
Date: Mon Mar  6 22:56:39 2006
New Revision: 111793

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

	PR fortran/26107
	* resolve.c (resolve_function): Add name after test for pureness.

	PR fortran/19546
	* trans-expr.c (gfc_conv_variable): Detect reference to parent result,
	store current_function_decl, replace with parent, whilst calls are
	made to gfc_get_fake_result_decl, and restore afterwards. Signal this
	to gfc_get_fake_result_decl with a new argument, parent_flag.
	* trans-stmt.c (gfc_trans_return): gfc_get_fake_result_decl 2nd arg
	is set to zero.
	* trans.h: Add parent_flag to gfc_get_fake_result_decl prototype.
	* trans-decl.c (gfc_get_fake_result_decl): On parent_flag, being set,
	add decl to parent function. Replace refs to current_fake_result_decl
	with refs to this_result_decl.
	(gfc_generate_function_code): Null parent_fake_result_decl before the
	translation of code for contained procedures. Set parent_flag to zero
	in call to gfc_get_fake_result_decl.
	* trans-intrinsic.c (gfc_conv_intrinsic_len): The same.

2006-03-06  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/26107
	* pure_dummy_length_1.f90: New test.

	PR fortran/19546
	* gfortran.dg/parent_result_ref_1.f90: New test.
	* gfortran.dg/parent_result_ref_2.f90: New test.
	* gfortran.dg/parent_result_ref_3.f90: New test.
	* gfortran.dg/parent_result_ref_4.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/parent_result_ref_1.f90
    trunk/gcc/testsuite/gfortran.dg/parent_result_ref_2.f90
    trunk/gcc/testsuite/gfortran.dg/parent_result_ref_3.f90   (with props)
    trunk/gcc/testsuite/gfortran.dg/parent_result_ref_4.f90
    trunk/gcc/testsuite/gfortran.dg/pure_dummy_length_1.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/fortran/trans-openmp.c
    trunk/gcc/fortran/trans-stmt.c
    trunk/gcc/fortran/trans.h
    trunk/gcc/testsuite/ChangeLog

Propchange: trunk/gcc/testsuite/gfortran.dg/parent_result_ref_3.f90
            ('svn:executable' added)


Comment 8 Paul Thomas 2006-03-06 23:21:35 UTC
This will only be fixed on 4.2.  The 4.1 and 4.2 trees have diverged so much in gfc_get_fake_result_decl that it will be a lot of work to bring it up to the point where it will take the patch for this PR.

Paul