[Bug fortran/107157] New: Weird out-of-bounds error with multiple move_alloc's

federico.perini at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Oct 5 14:14:15 GMT 2022


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


More information about the Gcc-bugs mailing list