Bug 48800 - [4.6/4.7 Regression] ICE with non-allocatable/pointer deferred-shape array
Summary: [4.6/4.7 Regression] ICE with non-allocatable/pointer deferred-shape array
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2011-04-28 08:35 UTC by Tobias Burnus
Modified: 2011-04-30 16:24 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-04-29 05:41:59


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2011-04-28 08:35:30 UTC
Reported by Daniel Carrera at
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/74905e43fe144fdd#


The ICE - and thus the 4.6/4.7 regression - is due to -frealloc-lhs; with -fno-realloc-lhs, the program compiles with 4.4, 4.5, 4.6 and 4.7 without any diagnostic. It also compiles with pgf95 10.1-0.


However, the program is invalid - and all my attempts to generate an ICE for a valid program failed. The invalidity is properly diagnosed by ifort 11.1, openf95 4.2.3 and pathf95 3.2.99.

The program is invalid because in
             pure function dr(t, r_)
                 real :: dr(:)
"dr" is deferred-shaped but is neither allocatable nor a pointer.


gfortran 4.6 and 4.7 fail with:

test.f90: In function ‘runge_kutta_step’:
test.f90:16:0: internal compiler error: in fold_binary_loc, at fold-const.c:9304



     pure function runge_kutta_step(t, r_, dr, h) result(res)
         real, intent(in) :: t, r_(:), h
         real, dimension(:), allocatable :: k1, k2, k3, k4, res
         integer :: N

         interface
             pure function dr(t, r_)
                 real, intent(in) :: t, r_(:)
                 real :: dr(4)
             end function
         end interface

         N = size(r_)
         allocate(k1(N),k2(N),k3(N),k4(N),res(N))

         k1 = dr(t, r_)
         k2 = dr(t + h/2, r_ + k1*h/2)
         k3 = dr(t + h/2, r_ + k2*h/2)
         k4 = dr(t + h  , r_ + k3*h)

         res = r_ + (k1 + 2*k2 + 2*k3 + k4) * h/6
     end function
Comment 1 Tobias Burnus 2011-04-28 12:03:42 UTC
(In reply to comment #0)
>                  real :: dr(4)

s/dr(4)/dr(:)/ to reproduce the ICE.


If one places a break point in resolve_fl_var_and_proc, one sees that for sym->name == "dr", the type is: sym->as->type == AS_ASSUMED_SHAPE -- rather than the expected AS_DEFERRED_SHAPE. If it had the latter, a proper error message would have been printed.

My impression is that the problem occurs because "dr" is also a dummy argument; the change from AS_DEFERRED_SHAPE to AS_ASSUMED_SHAPE is done at resolve_formal_arglist for dummy arguments. Maybe one should check for attr.flavor != FL_PROCEDURE before doing the change.
Comment 2 Tobias Burnus 2011-04-29 05:41:59 UTC
Patch: http://gcc.gnu.org/ml/fortran/2011-04/msg00296.html
Comment 3 Tobias Burnus 2011-04-29 16:50:00 UTC
Author: burnus
Date: Fri Apr 29 16:49:53 2011
New Revision: 173175

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173175
Log:
2011-04-29  Tobias Burnus  <burnus@net-b.de>

        PR fortran/48810
        * resolve.c (resolve_typebound_generic_call): Don't check access
        flags of the specific function.

        PR fortran/48800
        * resolve.c (resolve_formal_arglist): Don't change AS_DEFERRED
        to AS_ASSUMED_SHAPE for function results.
        (resolve_fl_var_and_proc): Print also for function results with
        AS_DEFERRED an error, if they are not a pointer or allocatable.
        (resolve_types): Make sure arguments of procedures in interface
        blocks are resolved.

2011-04-29  Tobias Burnus  <burnus@net-b.de>

        PR fortran/48810
        * gfortran.dg/typebound_proc_22.f90: New.

        PR fortran/48800
        * gfortran.dg/interface_36.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/interface_36.f90
    trunk/gcc/testsuite/gfortran.dg/typebound_proc_22.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Tobias Burnus 2011-04-29 21:26:10 UTC
Author: burnus
Date: Fri Apr 29 21:26:07 2011
New Revision: 173191

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173191
Log:
2011-04-29  Tobias Burnus  <burnus@net-b.de>

        PR fortran/48810
        * resolve.c (resolve_typebound_generic_call): Don't check access
        flags of the specific function.

        PR fortran/48800
        * resolve.c (resolve_formal_arglist): Don't change AS_DEFERRED
        to AS_ASSUMED_SHAPE for function results.
        (resolve_fl_var_and_proc): Print also for function results with
        AS_DEFERRED an error, if they are not a pointer or allocatable.
        (resolve_types): Make sure arguments of procedures in interface
        blocks are resolved.

2011-04-29  Tobias Burnus  <burnus@net-b.de>

        PR fortran/48810
        * gfortran.dg/typebound_proc_22.f90: New.

        PR fortran/48800
        * gfortran.dg/interface_36.f90: New.


Added:
    branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/interface_36.f90
    branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/typebound_proc_22.f90
Modified:
    branches/gcc-4_6-branch/gcc/fortran/ChangeLog
    branches/gcc-4_6-branch/gcc/fortran/resolve.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 5 Tobias Burnus 2011-04-29 21:26:31 UTC
FIXED
Comment 6 Tobias Burnus 2011-04-30 15:54:52 UTC
Author: burnus
Date: Sat Apr 30 15:54:49 2011
New Revision: 173219

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173219
Log:
2011-04-30  Tobias Burnus  <burnus@net-b.de>

        PR fortran/48800
        * decl.c (gfc_match_import): Don't try to find the
        symbol if already found.

2011-04-30  Tobias Burnus  <burnus@net-b.de>

        PR fortran/48800
        * gfortran.dg/interface_37.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/interface_37.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 7 Tobias Burnus 2011-04-30 16:24:59 UTC
(In reply to comment #6)
> New Revision: 173219
> URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173219

Wrong bug number; that was for PR 48821.