https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70842
Bug ID: 70842 Summary: internal compiler error with character members within a polymorphic pointer Product: gcc Version: 5.1.0 Status: UNCONFIRMED Keywords: ice-on-valid-code Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: nathanael.huebbe at informatik dot uni-hamburg.de Target Milestone: --- There is a problem with character members of derived types when using polymorphic pointers, which triggers an ICE. It seems as if gfortran looses track of the length of `character` members when performing a downcast from a limited polymorphic type. The bug can be reproduced with this little code snippet: $ cat mo_compiler_test.f90 module foo TYPE, ABSTRACT :: t_Intermediate END TYPE t_Intermediate type, extends(t_Intermediate) :: t_Foo character(:), allocatable :: string end type t_Foo contains subroutine bar(me) class(t_Intermediate), target :: me select type(me) type is(t_Foo) print*, len(me%string) end select end subroutine bar end module foo $ gfortran -c -o mo_compiler_test.o mo_compiler_test.f90 f951: internal compiler error: in gfc_add_component_ref, at fortran/class.c:245 Please submit a full bug report, with preprocessed source if appropriate. See <http://gcc.gnu.org/bugs.html> for instructions. I have been able to reproduce this bug with gfortran versions 4.9.3, 5.1.0, 5.3.0, up to the current master in the git-svn mirror (commit a80f3f45b016). The bug is not present in versions up to 4.9.2. A git-bisect on the git-svn mirror revealed commit 53ec6b3f003a to be the first bad commit. It is interesting to note that this bug is not triggered when the `select type()` argument is an unlimited polymorphic pointer, even if that unlimited polymorphic pointer is just an alias for a limited polymorphic variable. See the comments in the attached code for details on this.