[Bug fortran/99711] Crash when reading an allocated character array in namelist
sgk at troutmask dot apl.washington.edu
gcc-bugzilla@gcc.gnu.org
Wed Mar 24 05:45:24 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99711
--- Comment #10 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Wed, Mar 24, 2021 at 05:35:31AM +0000, sgk at troutmask dot
apl.washington.edu wrote:
>
> What does -ftree-dump-original show? I wonder if gfortran is doing a
> re-allocation on assignment when it shouldn't.
>
Nope. It looks like a counting problem. Here's a modified
testcase.
program allocnml
implicit none
character(len=:), dimension(:), allocatable :: cbulist_ru
integer :: iluseg
namelist /nam_bu_ru/ cbulist_ru
allocate( character(len=10) :: cbulist_ru(4) )
cbulist_ru = 'abc'
print *, size(cbulist_ru), len(cbulist_ru(1))
open(newunit=iluseg, file='list.nml', status='old')
read(unit=iluseg, nml=nam_bu_ru)
print *, size(cbulist_ru), len(cbulist_ru(1))
print *, cbulist_ru
print *, '>'//cbulist_ru(1)//'<'
print *, '>'//cbulist_ru(2)//'<'
print *, '>'//cbulist_ru(3)//'<'
print *, '>'//cbulist_ru(4)//'<'
close(unit=iluseg)
end program allocnml
I get
% gfcx -o z -O a.f90 && ./z
4 10
4 10
VTURB abc abc abc
>VTURB <
>abc <
>abc <
>abc <
which suggests that during the READ, the individual array
elements aren't assigned. That is, the array index is
never incremented from 1 to 4.
More information about the Gcc-bugs
mailing list