Bug 57284 - [OOP] ICE with find_array_spec for polymorphic arrays
Summary: [OOP] ICE with find_array_spec for polymorphic arrays
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2013-05-15 10:11 UTC by Lorenz Hüdepohl
Modified: 2016-06-23 18:37 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-05-15 00:00:00


Attachments
Minimal test case (144 bytes, text/x-fortran)
2013-05-15 10:11 UTC, Lorenz Hüdepohl
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lorenz Hüdepohl 2013-05-15 10:11:36 UTC
Created attachment 30119 [details]
Minimal test case

I get an ICE for the following (valid?) minimal test-case involving a size() intrinsic for a class() dummy argument:

> cat minimal.f90
module testmod
  type type_t
  end type type_t
  contains
  function foo(a, b) result(add)
    class(type_t), intent(in) :: a(:), b(size(a))
    type(type_t) :: add(size(a))
  end function
end module testmod
program p
  use testmod
end program
>
> ~/sys/bin/gfortran minimal.f90 
minimal.f90:10.9:

program p
         1
Internal Error at (1):
find_array_spec(): unused as(1)
>
> ~/sys/bin/gfortran --version
GNU Fortran (GCC) 4.9.0 20130514 (experimental)
Copyright (C) 2013 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING


Here, ~/sys/bin/gfortran is a self-compiled gfortran from yesterday's trunk, the ICE also happens with the gfortran 4.7.2 supplied with openSUSE:


> gfortran --version
GNU Fortran (SUSE Linux) 4.7.2 20130108 [gcc-4_7-branch revision 195012]
Copyright (C) 2012 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING

> gfortran minimal.f90 
minimal.f90:10.9:

program p
         1
Internal Error at (1):
find_array_spec(): unused as(1)
Comment 1 Lorenz Hüdepohl 2013-05-15 10:19:20 UTC
Might be related to Bug #57285
Comment 2 Tobias Burnus 2013-05-15 13:22:37 UTC
The problem is that the expression is (internally):
   a->REF_COMPONENT("_data")->REF_ARRAY(full array)

In find_array_spec, the code firsts gets the array as:
   as = CLASS_DATA (e->symtree->n.sym)->as;

And then it walks the refs. Result:
   a->(full array)->_data->(full array)

But having two full arrays is invalid! Hence, it fails.

(find_array_spec doesn't see that the two arrays refs are identical.)
Comment 3 Lorenz Hüdepohl 2015-02-09 15:18:04 UTC
Any progress on this one? 4.9.2 still produces the error:

> ~/sys/stow/gcc-4.9.2/bin/gfortran --version
GNU Fortran (GCC) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING

> ~/sys/stow/gcc-4.9.2/bin/gfortran minimal.f90
minimal.f90:10.9:

program p
         1
Internal Error at (1):
find_array_spec(): unused as(1)
Comment 4 Gerhard Steinmetz 2016-02-04 18:16:38 UTC
As known, causative is the class declaration of "a", when using size(a).
Some variants, replacing "class" with "type" :


$ cat z2.f90
module m
  type t
  end type
contains
  function foo(a, b) result(add)
    class(t), intent(in) :: a(:)
    type(t), intent(in) :: b(size(a))
    type(t) :: add(size(a))
  end function
end module

program p
  use m
end program


$ gfortran-6 -c z2.f90
f951: internal compiler error: find_array_spec(): unused as(1)

---

$ cat z3.f90
module m
  type t
  end type
contains
  function foo(a, b) result(add)
    type(t), intent(in) :: a(:)
    class(t), intent(in) :: b(size(a))
    type(t) :: add(size(a))
  end function
end module

program p
  use m
end program


$ gfortran-6 -c z3.f90
# ok

---

$ cat z4.f90
module m
  type t
  end type
contains
  function foo(a, b) result(add)
    type(t), intent(in) :: a(:)
    type(t), intent(in) :: b(size(a))
    type(t) :: add(size(a))
  end function
end module

program p
  use m
end program


$ gfortran-6 -c z4.f90
# ok
Comment 5 Holysword 2016-05-23 13:38:23 UTC
Is there any progress concerning this bug? I'm trying GCC-5.3.

Please, notice that this also happens when the said class is a polymorphic class (that is, the CLASS(*) declaration).

This particular bug renders gfortran practically unusable for my application.
Comment 6 Dominique d'Humieres 2016-05-23 13:48:12 UTC
> Is there any progress concerning this bug? I'm trying GCC-5.3.

Usual answer: what did you do to fix it?
Comment 7 Gerhard Steinmetz 2016-06-23 18:37:07 UTC
Compiles if "size" is replaced with synonym "product(shape)".


$ cat z5.f90
module m
  type t
  end type
contains
  function foo(a, b) result(add)
    class(t), intent(in) :: a(:)
    class(t), intent(in) :: b(product(shape(a)))
    type(t) :: add(product(shape(a)))
  end function
end module

program p
  use m
end program

$ gfortran-6 -g -O0 -fcheck=all z5.f90



$ cat z6.f90
module m
  type t
  end type
contains
  function foo(a, b) result(add)
    class(*), intent(in) :: a(:)
    class(*), intent(in) :: b(product(shape(a)))
    type(t) :: add(product(shape(a)))
  end function
end module

program p
  use m
end program

$ gfortran-6 -g -O0 -fcheck=all z6.f90



Remark:
This workaround may or may not work for production codes, it depends.