https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106731
kargl at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |kargl at gcc dot gnu.org --- Comment #3 from kargl at gcc dot gnu.org --- (In reply to federico from comment #0) > A derived type that has user-defined I/O causes ICE on all gfortran versions > 7 to 12.1.0, whenever it's being used as an automatic object. > > The error is at > > > 63 | type(t) :: automatic(n) > | 1 > internal compiler error: in gfc_trans_auto_array_allocation, at > fortran/trans-array.cc:6617 > > This does not happen if the derived type is allocated. > > Here's the simplest example: > > module causes_ice > implicit none > > type :: t > real(8) :: x > contains > procedure, private :: write_formatted > generic :: write(formatted) => write_formatted > end type t > > contains > > subroutine write_formatted(this, unit, iotype, v_list, iostat, iomsg) > class(t), intent(in) :: this > integer, intent(in) :: unit > character(*), intent(in) :: iotype > integer, intent(in) :: v_list(:) > integer, intent(out) :: iostat > character(*), intent(inout) :: iomsg > write(unit, '(a)', iostat=iostat, iomsg=iomsg) 'dummy' > end subroutine write_formatted > > end module causes_ice > > module use_t > use causes_ice > implicit none > > public :: automatic_alloc > > contains > > subroutine automatic_alloc(n) > integer, intent(in) :: n > > ! Automatic array: ICE! > type(t) :: automatic(n) > > ! Allocatable: works > type(t), allocatable :: alloc(:) > allocate(alloc(n)) > > ! Do anything > print *, 'n=',n,automatic(n)%x > > end subroutine automatic_alloc > > end module use_t > > program test > use use_t > call automatic_alloc(1) > end program test > > I could find other DTIO-related bugs, but none seemed related with the > allocation type. You're hitting an assert() in trans-array.cc. It's unclear to me why the assert() is there. If it is commented out, the code compiles and executes. % git diff gcc/fortran/trans-array.cc | cat diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 05134952db4..c5916aeee53 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -6614,7 +6614,7 @@ gfc_trans_auto_array_allocation (tree decl, gfc_symbol * sym, type = TREE_TYPE (type); gcc_assert (!sym->attr.use_assoc); - gcc_assert (!TREE_STATIC (decl)); +// gcc_assert (!TREE_STATIC (decl)); gcc_assert (!sym->module); if (sym->ts.type == BT_CHARACTER