https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89352
Bug ID: 89352
Summary: Deferred length character array pointer error with
gfortran
Product: gcc
Version: 8.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: clange001 at gmail dot com
Target Milestone: ---
I have two deferred length character arrays in gfortran. I allocate one of
them, and then point the other one to it. The pointer variable has the correct
array size, but not the correct character length. The program terminates with
an error when trying to access the information in the pointer.
I see that there may be related bugs that have been fixed
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51976), but this one is present
now in version 8.
I'm testing this with:
GNU Fortran (MacPorts gcc8 8.2.0_2) 8.2.0
and also
GNU Fortran (MacPorts gcc8 8.2.0_3) 8.2.0
The code below works fine with Intel Fortran on Windows.
program test
implicit none
character(len=:), pointer, dimension(:) :: charvara
character(len=:), pointer, dimension(:) :: charvara_ptr
allocate(character(len=10) :: charvara(3))
charvara(:) = '0123456789'
print *, 'len(charvara) = ', len(charvara)
print *, 'size(charvara) = ', size(charvara)
print *, 'charvara = ', charvara
charvara_ptr => charvara
print *, 'associated = ', associated(charvara_ptr, charvara)
print *, 'len(charvara_ptr) = ', len(charvara_ptr)
print *, 'size(charvara_ptr) = ', size(charvara_ptr)
print *, 'charvara_ptr = ', charvara_ptr
print *, 'end'
end program test
I would expect the length, size, and contents of charvara_ptr to be the same as
charvara, but instead I get the following:
len(charvara) = 10
size(charvara) =3
charvara = 012345678901234567890123456789
associated = T
len(charvara_ptr) = 1708412736
size(charvara_ptr) =3
test(71321,0x7fff9e47c380) malloc: *** mach_vm_map(size=140734901800960)
failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Operating system error: Cannot allocate memory
Memory allocation failure in xrealloc
Error termination. Backtrace:
#0 0x10bb11f8f
#1 0x10bb127fd
#2 0x10bb12987
#3 0x10bb119f9
#4 0x10bbc8950
#5 0x10bbbf147
#6 0x10bbc4b61
#7 0x10bbc7cd8
#8 0x10bbc877e
#9 0x10bb0ccab
#10 0x10bb0cd6e