[Bug fortran/108581] New: wrong assignment on two-rank array with deferred-length characters
saitofuyuki at jamstec dot go.jp
gcc-bugzilla@gcc.gnu.org
Sat Jan 28 12:03:05 GMT 2023
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.
More information about the Gcc-bugs
mailing list