On Sat, Feb 10, 2024 at 06:00:42PM -0800, Steve Kargl wrote: > All, consider this simple code: > > module foo > contains > subroutine bar > character(len=:), allocatable :: s(:) > call bah(s) > end subroutine bar > end module foo > > If one compiles with -fdump-tree-original, one see (with some pruning) > > void bar () > { > integer(kind=8) .s; > struct array01_character(kind=1) s; > > The above two lines seem to be ok. > > bitsizetype D.4319; > sizetype D.4320; > > try > { > D.4319 = (bitsizetype) (sizetype) NON_LVALUE_EXPR <.s> * 8; > D.4320 = (sizetype) NON_LVALUE_EXPR <.s>; > s.data = 0B; > s.dtype = {.elem_len=(unsigned long) .s, .version=0, .rank=1, > .type=6}; > bah ((character(kind=1)[0:][1:.s] * restrict) s.data, .s); > } > > This is bad. .s is undefined. I've trace this to trans-array.cc:11531
I have created PR113883 with the patch suggested by Mikael and a testcase. I have bootstrapped and regression tested the result. Could I ask someone to commit it? https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113883 * trans-array.cc (gfc_trans_deferred_array): Set length of an unallocated character entity to zero to prevent reference to undefined variable. * testsuite/gfortran.dg/allocatable_length.f90: New test. -- Steve