public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/100886] New: Variable character pointer within a Fortran derived type can't determine the shape(mold) of the target
@ 2021-06-02 20:53 thomas.robinson at noaa dot gov
  2021-08-02 14:17 ` [Bug fortran/100886] " thomas.robinson at noaa dot gov
  0 siblings, 1 reply; 2+ messages in thread
From: thomas.robinson at noaa dot gov @ 2021-06-02 20:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100886

            Bug ID: 100886
           Summary: Variable character pointer within a Fortran derived
                    type can't determine the shape(mold) of the target
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thomas.robinson at noaa dot gov
  Target Milestone: ---

A character pointer within a Fortran DDT can't determine the shape(mold) of a
variable length allocatable target character array

Desired behavior: DDT pointer behaves like a non-DDT pointer and properly
determines shape(mold) of the target and points to it

Here is some sample code:

program char_ptr_test

implicit none

character(len=:), dimension(:), allocatable, target:: input_nml_file

character(len=:), dimension(:), pointer:: copy_input_nml_file => null()

type init_type
  character(len=:), dimension(:), pointer:: input_nml_file => null()
end type init_type

type(init_type):: Init
integer:: i
character(len=6):: arg
logical:: gnu=.false.


!--- parse command line
 call get_command_argument(1, arg)
 if (len_trim(arg) > 0) print *, trim(arg)


!--- set up input_nml_file and output the result
 call init_input()
 do i = 1,size(input_nml_file)
   print *, 'Main input_nml_file is: "',input_nml_file(i),'"'
 enddo


!--- plain pointer  -  works as expected
 print *, NEW_LINE('a'),'plain pointer'
 copy_input_nml_file => input_nml_file
 do i = 1,size(copy_input_nml_file)
   print *, 'copy_input_nml_file is: "',copy_input_nml_file(i),'"'
 enddo
 nullify(copy_input_nml_file)


!--- pointer within a DDT  -  fails
!--- point to input_nml_file elements (:)
 print *,  NEW_LINE('a'),'pointer within fortran ddt @ elements (:)'
 Init%input_nml_file => input_nml_file(:)
 do i = 1,size(Init%input_nml_file)
   print *, 'Init%input_nml_file is: "',Init%input_nml_file(i),'"'
 enddo


!--- pointer within a DDT  -  fails
!--- point to input_nml_file as whole
 print *,  NEW_LINE('a'),'pointer within fortran ddt @ whole entity'
 Init%input_nml_file => input_nml_file
 do i = 1,size(Init%input_nml_file)
   print *, 'Init%input_nml_file is: "',Init%input_nml_file(i),'"'
 enddo
 nullify(Init%input_nml_file)


!--- pointer within a DDT  -  works
!--- point to input_nml_file elements (:)
!--- allocate/deallocate to get shape
 print *,  NEW_LINE('a'),'pointer within fortran ddt with shape settings @
elements(:)'
 allocate(Init%input_nml_file, mold=input_nml_file)
 deallocate(Init%input_nml_file)
 Init%input_nml_file => input_nml_file(:)
 do i = 1,size(Init%input_nml_file)
   print *, 'Init%input_nml_file is: "',Init%input_nml_file(i),'"'
 enddo
 nullify(Init%input_nml_file)


!--- pointer within a DDT  -  fails with segfault
!--- point to input_nml_file as whole
!--- allocate/deallocate to get shape
 print *,  NEW_LINE('a'),'pointer within fortran ddt w/ shape settings @ whole
entity'
 allocate(Init%input_nml_file, mold=input_nml_file)
 deallocate(Init%input_nml_file)
 Init%input_nml_file => input_nml_file
 do i = 1,size(Init%input_nml_file)
   print *, 'Init%input_nml_file is: "',Init%input_nml_file(i),'"'
 enddo
 nullify(Init%input_nml_file)

contains

  subroutine init_input()
    allocate(character(len=10)::input_nml_file(7))
    input_nml_file(1) = 'New York  '
    input_nml_file(2) = 'London    '
    input_nml_file(3) = 'Paris     '
    input_nml_file(4) = 'Munich    '
    input_nml_file(5) = 'Everybody '
    input_nml_file(6) = 'talk about'
    input_nml_file(7) = 'Pop Muzik '
  end subroutine init_input

end program char_ptr_test


The behavior is different between 9.3 and 10.2, but the same for 10.2 to 12.0
(at least for the versions that I have available).  Please let me know if
there's any other information you need

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug fortran/100886] Variable character pointer within a Fortran derived type can't determine the shape(mold) of the target
  2021-06-02 20:53 [Bug fortran/100886] New: Variable character pointer within a Fortran derived type can't determine the shape(mold) of the target thomas.robinson at noaa dot gov
@ 2021-08-02 14:17 ` thomas.robinson at noaa dot gov
  0 siblings, 0 replies; 2+ messages in thread
From: thomas.robinson at noaa dot gov @ 2021-08-02 14:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100886

--- Comment #1 from Tom Robinson <thomas.robinson at noaa dot gov> ---
Has anyone had a chance to look at this and confirm it?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-02 14:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02 20:53 [Bug fortran/100886] New: Variable character pointer within a Fortran derived type can't determine the shape(mold) of the target thomas.robinson at noaa dot gov
2021-08-02 14:17 ` [Bug fortran/100886] " thomas.robinson at noaa dot gov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).