public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "federico.perini at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/107157] New: Weird out-of-bounds error with multiple move_alloc's
Date: Wed, 05 Oct 2022 14:14:15 +0000	[thread overview]
Message-ID: <bug-107157-4@http.gcc.gnu.org/bugzilla/> (raw)

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

                 reply	other threads:[~2022-10-05 14:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-107157-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).