public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/107157] New: Weird out-of-bounds error with multiple move_alloc's
@ 2022-10-05 14:14 federico.perini at gmail dot com
  0 siblings, 0 replies; only message in thread
From: federico.perini at gmail dot com @ 2022-10-05 14:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107157
           Summary: Weird out-of-bounds error with multiple move_alloc's
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: federico.perini at gmail dot com
  Target Milestone: ---

I'm in trouble reducing this problem to a minimum viable example, so I'm asking
for help - I have a nested derived type that contains allocatable components,
like: 

type :: string
  character(len=1), allocatable :: t(:)
end type string

type :: data_point
   type(string) :: name
   real(real64), allocatable :: data(:)
end type data_point

type :: data_set
   type(data_point), allocatable :: data(:)
end type data_set

Now, I read in type(data_set) from several input files, and I grow that using a
move_alloc, this way: 

subroutine read_dataset(this,fileName)
   class(data_set), intent(inout) :: this
   character(*), intent(in) :: fileName

   type(data_point), allocatable :: tmp(:)
   type(data_point) :: this_file

   [...]
   read_data: do

      n = n+1

      ! Read one
      call this_file%read(blabla)

      ! Extend & copy
      allocate(tmp(n))
      if (n>1) tmp(1:n-1) = this%data(1:n-1)
               tmp(n)     = this_file
      call move_alloc(from=tmp,to=this%data)

   end do read_data

end subroutine

Starting from n>=2, after the routine exits, I have this error: 

```
Fortran runtime error: Index '1' of dimension 1 of array '_F.DA0' outside of
expected range (0:0)
```

- the error points to the end line of the module ("end module blabla")
- I have no structures with that '_F.DA0' name, nor I can find anything like
that in a text search in the .mod file (after unzipping it)
- No error if move_alloc is called at most once

I would like to reduce the problem to a simpler case I can post but I haven't
been able to reproduce this so I'm asking for help: 
is there any compiler flags I can turn on to produce more output and/or
understand better what's going on? 

Thank you in advance, 
Federico

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

only message in thread, other threads:[~2022-10-05 14:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-05 14:14 [Bug fortran/107157] New: Weird out-of-bounds error with multiple move_alloc's federico.perini at gmail dot com

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