Bug 35184 - ICE in gfc_conv_array_index_offset
ICE in gfc_conv_array_index_offset
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.3.0
: P3 normal
: ---
Assigned To: Jerry DeLisle
: ice-on-valid-code
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2008-02-13 18:07 UTC by Maik Beckmann
Modified: 2008-03-15 17:21 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.1.3 4.2.2 4.3.0
Last reconfirmed: 2008-03-15 16:25:57


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maik Beckmann 2008-02-13 18:07:35 UTC
The following code triggers an ICE with gcc-4.3-20080208
<foo.f90>
MODULE foo

  TYPE, PUBLIC :: bar
    PRIVATE
      REAL :: value
  END TYPE bar

  INTERFACE ASSIGNMENT (=)
    MODULE PROCEDURE assign_bar
  END INTERFACE ASSIGNMENT (=)

CONTAINS

  ELEMENTAL SUBROUTINE assign_bar (to, from)
    TYPE(bar), INTENT(OUT) :: to
    TYPE(bar), INTENT(IN) :: from
    to%value= from%value
  END SUBROUTINE

  SUBROUTINE my_sub (in, out)
    IMPLICIT NONE
    TYPE(bar), DIMENSION(:,:), POINTER :: in
    TYPE(bar), DIMENSION(:,:), POINTER :: out

    ALLOCATE( out(1:42, 1:42) )
    out(1, 1:42) = in(1, 1:42)

  END SUBROUTINE

END MODULE foo
</foo.f90>

/home/maik/workspace/gcc/gcc-4.3-20080208/stage/bin/gfortran-4.3  -o CMakeFiles/mylib.dir/foo.f90.o  -I/home/maik/workspace/Debug_maik/Debug   -c /home/maik/workspace/Debug_maik/foo.f90
/home/maik/workspace/Debug_maik/foo.f90: In function 'my_sub':
/home/maik/workspace/Debug_maik/foo.f90:25: internal compiler error: in gfc_conv_array_index_offset, at fortran/trans-array.c:2201
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
make[2]: *** [CMakeFiles/mylib.dir/foo.f90.o] Error 1
make[2]: Leaving directory `/home/maik/workspace/Debug_maik/Debug'
make[1]: *** [CMakeFiles/mylib.dir/all] Error 2
make[1]: Leaving directory `/home/maik/workspace/Debug_maik/Debug'
make: *** [all] Error 2


If ELEMENTAL is omitted or replaced by PURE it compiles fine.

 -- Maik
Comment 1 Daniel Franke 2008-02-13 20:25:10 UTC
Confirmed.

Seems to be related to ELEMENTAL and IN probalby not having a proper array descriptor. If my_sub is written as:

  SUBROUTINE my_sub (in, out)
    TYPE(bar), DIMENSION(42, 42) :: in, out
    out(1, 1:42) = in(1, 1:42)            ! ELEMENTAL SUBROUTINE ASSIGN_BAR
  END SUBROUTINE

no ICE occurs. Same if the subroutine ASSIGN_BAR is called directly using the pointers from the original example, i.e.:

  SUBROUTINE my_sub (in, out)
    TYPE(bar), DIMENSION(:,:), POINTER :: in
    TYPE(bar), DIMENSION(:,:), POINTER :: out
    ALLOCATE(out(1:42, 1:42))
    CALL assign_bar(out(1, 1:42), in(1, 1:42))
  END SUBROUTINE

The latter probably doesn't make use of the ELEMENTALness of ASSIGN_BAR.
Comment 2 Jerry DeLisle 2008-03-15 16:25:57 UTC
Removing this assert on this argument being passed in seems to resolve this issue.  I wonder if this was a leftover from a debugging session.

Index: trans-array.c
===================================================================
--- trans-array.c       (revision 133203)
+++ trans-array.c       (working copy)
@@ -2209,7 +2209,6 @@ gfc_conv_array_index_offset (gfc_se * se
       switch (ar->dimen_type[dim])
        {
        case DIMEN_ELEMENT:
-         gcc_assert (i == -1);
          /* Elemental dimension.  */
          gcc_assert (info->subscript[dim]
                      && info->subscript[dim]->type == GFC_SS_SCALAR);
Comment 3 Jerry DeLisle 2008-03-15 16:46:03 UTC
Subject: Bug 35184

Author: jvdelisle
Date: Sat Mar 15 16:45:12 2008
New Revision: 133252

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133252
Log:
2008-03-15  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/35184
	* trans-array.c (gfc_conv_array_index_offset): Remove unnecessary
	assert.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-array.c

Comment 4 Jerry DeLisle 2008-03-15 16:53:50 UTC
Subject: Bug 35184

Author: jvdelisle
Date: Sat Mar 15 16:53:05 2008
New Revision: 133253

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133253
Log:
2008-03-15  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR testsuite/35184
	gfortran.dg/elemental_subroutine_6.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/elemental_subroutine_6.f90
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 5 Jerry DeLisle 2008-03-15 16:54:39 UTC
Closing. Fixed on 4.4
Comment 6 Maik Beckmann 2008-03-15 17:21:02 UTC
(In reply to comment #5)
> Closing. Fixed on 4.4
> 

Jerry, many thanks for fixing this!

Since this patch is very minor I hope it will be applied to 4.3 before 4.3.1 is out (building gcc on windows isn't fun).

Best,
 -- Maik  


Comment 7 Jerry DeLisle 2008-05-18 00:33:22 UTC
Subject: Bug 35184

Author: jvdelisle
Date: Sun May 18 00:32:22 2008
New Revision: 135492

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135492
Log:
2008-05-17  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

        Backport from mainline:
        PR fortran/35184
        * trans-array.c (gfc_conv_array_index_offset): Remove
        unnecessary assert.

Modified:
    branches/gcc-4_3-branch/gcc/fortran/ChangeLog
    branches/gcc-4_3-branch/gcc/fortran/trans-array.c