public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/108581] New: wrong assignment on two-rank array with deferred-length characters
@ 2023-01-28 12:03 saitofuyuki at jamstec dot go.jp
  2023-01-28 12:08 ` [Bug fortran/108581] " saitofuyuki at jamstec dot go.jp
  2023-03-28  9:07 ` pault at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: saitofuyuki at jamstec dot go.jp @ 2023-01-28 12:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108581
           Summary: wrong assignment on two-rank array with
                    deferred-length characters
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: saitofuyuki at jamstec dot go.jp
  Target Milestone: ---

When a two-rank array with deferred-length characters is allocated,
reference of array sections fails at non-first elements.

Following is a minimum example to demonstlate it.
I tried several size on the second rank of the array (ymax).
All of the reference of a(:, ymin+1:) are failed.
Also, I tried several combination of the size of the first rank (xmin,
xmax), which all fail.

When with -O2 optimization, assignment seems to be already wrong.
gfortran-12.2.0, 11.3.0, 10.4.0, all show the same outputs.

----------------------------------------------------------------------
program dtest
  implicit none

  integer,parameter :: xmin = 0, xmax = 0
  integer,parameter :: ymin = 0, ymax = 1
  integer,parameter :: l = 2

  character(len=:),pointer     :: a(:, :) => NULL()

  integer x, y

  allocate(character(len=l)::a(xmin:xmax, ymin:ymax))

  a(:,:) = ' '
  a(xmin:xmax, ymin) = 'A.'
  a(xmin:xmax, ymax) = 'B.'

  do y = ymin, ymax
     write(*, *) '(1) ', y,  (a(x, y), x = xmin, xmax)
     write(*, *) '(2) ', y,  a(xmin:xmax, y)
     write(*, *) '(3) ', y,  a(:, y)
  enddo

  stop
end program dtest
----------------------------------------------------------------------
# expected outputs
 (1)            0 A.
 (2)            0 A.
 (3)            0 A.
 (1)            1 B.
 (2)            1 B.
 (3)            1 B.
----------------------------------------------------------------------
# outputs (-O0)
 (1)            0 A.
 (2)            0 A.
 (3)            0 A.
 (1)            1 B.
 (2)            1 A.
 (3)            1 A.
----------------------------------------------------------------------
# outputs (-O2)  even worse
 (1)            0 A.
 (2)            0 A.
 (3)            0 A.
 (1)            1 A.
 (2)            1 A.
 (3)            1 A.
----------------------------------------------------------------------

There are some similar reported bugs relating to deferred length
characters.  As far as I searched, however, all of them are reports on
derived types to have deferred-length characters.
What I found is not, so I just reported as a new bug.

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

end of thread, other threads:[~2023-03-28  9:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-28 12:03 [Bug fortran/108581] New: wrong assignment on two-rank array with deferred-length characters saitofuyuki at jamstec dot go.jp
2023-01-28 12:08 ` [Bug fortran/108581] " saitofuyuki at jamstec dot go.jp
2023-03-28  9:07 ` pault at gcc dot gnu.org

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