ptype on deferred-length character arrays return empty(?) result

2024-10-28 Thread Kazuyoshi Furutaka
Dear gfortran experts...

The attached program runs OK, but `ptype`ing using gdb
on the deferred-length character array returns empty(?)
result, as the following (the results for integer and
real arrays are correct ):

(gdb) ptype intarr
type = integer(kind=4), allocatable (8)
(gdb) ptype realarr
type = real(kind=8), allocatable (8)
(gdb) ptype chararr
type = Type 
End Type 

Is this a bug?

Kazuyoshi
--
Kazuyoshi Furutaka
furut...@jb3.so-net.ne.jp
program arrays
  parameter(num=8)
  integer, allocatable :: intarr(:)
  real*8,  allocatable :: realarr(:)
  character(len=:), allocatable :: chararr(:)

  allocate(intarr(num))
  allocate(realarr(num))
  allocate(character(len=6) :: chararr(num))

  intarr(1)=9
  realarr(1)=9.0
  chararr(1)="ahoaho"
  print *, intarr(1)
  print *, realarr(1)
  print *, chararr(1)
end program arrays


Re: ptype on deferred-length character arrays return empty(?) result

2024-10-28 Thread Steve Kargl
On Mon, Oct 28, 2024 at 06:00:18PM +0900, Kazuyoshi Furutaka wrote:
> Dear gfortran experts...
> 
> The attached program runs OK, but `ptype`ing using gdb
> on the deferred-length character array returns empty(?)
> result, as the following (the results for integer and
> real arrays are correct ):
> 
> (gdb) ptype intarr
> type = integer(kind=4), allocatable (8)
> (gdb) ptype realarr
> type = real(kind=8), allocatable (8)
> (gdb) ptype chararr
> type = Type 
> End Type 
> 
> Is this a bug?
> 

Likely, yes.  Not sure if it's a GCC or GDB bug.  File a bug report 
in gcc's bugzilla.

Dynamic allocation of a scalar deferred-length variable works.

  program arrays
character(len=:), allocatable :: chararr
chararr="ahoaho"
print *, chararr
  end program arrays

Breakpoint 1, arrays () at a.f90:4
4 chararr="ahoaho"
(gdb) n
5 print *, chararr
(gdb) p chararr
$1 = (PTR TO -> ( character*(*) )) 0x201008020
(gdb) p *chararr
$2 = 'ahoaho'

Static memory works.

  program arrays
character(len=6) :: chararr(2)
chararr="ahoaho"
print *, chararr
  end program arrays
Breakpoint 1, arrays () at a.f90:18
18chararr="ahoaho"
(gdb) n
19print *, chararr
(gdb) p chararr
$1 = ('ahoaho', 'ahoaho')
(gdb) p &chararr
$2 = (PTR TO -> ( character*6 (2) )) 0x7fffe614

Dynamic allocation of an array of fixed length strings works.

  program arrays
character(len=6), allocatable :: chararr(:)
allocate(chararr(2))
chararr="ahoaho"
print *, chararr
  end program arrays

Breakpoint 1, arrays () at a.f90:32
32chararr="ahoaho"
(gdb) n
33print *, chararr
(gdb) p chararr
$1 = ('ahoaho', 'ahoaho')
(gdb) p &chararr
$2 = (PTR TO -> ( character*6, allocatable (2) )) 0x201016000

Your testcase of allocation of an array of deferred-length string strings.

  program arrays
character(len=:), allocatable :: chararr(:)
allocate(character(len=6) :: chararr(2))
chararr="ahoaho"
print *, chararr
  end program arrays

Breakpoint 1, arrays () at a.f90:53
53chararr="ahoaho"
(gdb) n
54print *, chararr
(gdb) p chararr
$1 = 
(gdb) p &chararr
$2 = (PTR TO -> ( Type  )) 0x7fffe5b0


-- 
Steve