public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/110877] New: Incorrect copy of allocatable component in polymorphic assignment from array dummy argument
@ 2023-08-02 17:37 townsend at astro dot wisc.edu
  0 siblings, 0 replies; only message in thread
From: townsend at astro dot wisc.edu @ 2023-08-02 17:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110877
           Summary: Incorrect copy of allocatable component in polymorphic
                    assignment from array dummy argument
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: townsend at astro dot wisc.edu
  Target Milestone: ---

I've run into a problem that's demonstrated by the following code:

--
module avs_m

   type :: foo_t
   end type foo_t

   type, extends(foo_t) :: bar_t
      real, allocatable :: a
   end type bar_t

end module avs_m

program assign_vs_source

   use avs_m

   implicit none

   class(foo_t), allocatable :: foo(:)

   allocate(bar_t::foo(1))
   select type(foo)
   class is (bar_t)
      allocate(foo(1)%a)
   end select

   call check_assign(foo)

contains

   subroutine check_assign(f)

      class(foo_t), intent(in)  :: f(:)
      class(foo_t), allocatable :: g(:)

      g = f

      select type(g)
      class is (bar_t)
         print *,'is allocated?', allocated(g(1)%a)
      end select

      deallocate(g)
      allocate(g, SOURCE=f)

      select type(g)
      class is (bar_t)
         print *,'is allocated?', allocated(g(1)%a)
      end select

   end subroutine check_assign

end program assign_vs_source
--

Expected output is 

 is allocated? T
 is allocated? T

but instead I get (gfortran 13.1.0, MacOS 13.4 x86_64):

 is allocated? F
 is allocated? T

It seems that the polymorphic assignment g=f is not correctly allocating the %a
component -- but the sourced allocation is. The problem seems to go away if (1)
I use scalars for foo, f and g, or (2) if I move the code from the check_assign
subroutine to the main program.

cheers,

Rich

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-02 17:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-02 17:37 [Bug fortran/110877] New: Incorrect copy of allocatable component in polymorphic assignment from array dummy argument townsend at astro dot wisc.edu

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).