https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121384
Bug ID: 121384
Summary: Wrongly initialized associate array descriptor when
the target is wrapped in parenthesis
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: mikael at gcc dot gnu.org
Target Milestone: ---
Testcase:
program test
implicit none
type :: t
integer :: i,j
end type
type(t) :: a(5)
a = [ t(2,3), t(5,7), t(11,13), t(17,19), t(23,29) ]
associate (x => (a%i))
! print *, rank(x)
if (rank(x) /= 1) error stop 11
! print *, shape(x)
if (any(shape(x) /= [5])) error stop 12
! print *, x
if (any(x /= [2,5,11,17,23])) error stop 13
end associate
associate (x => (a%j))
! print *, rank(x)
if (rank(x) /= 1) error stop 21
! print *, shape(x)
if (any(shape(x) /= [5])) error stop 22
! print *, x
if (any(x /= [3,7,13,19,29])) error stop 23
end associate
end program
When executed, this gives:
ERROR STOP 12
The initialization of 'x' in the dump shows:
...
parm.15.span = 8;
parm.15.dtype = {.elem_len=8, .version=0, .rank=1, .type=5};
parm.15.dim[0].lbound = 1;
parm.15.dim[0].ubound = 5;
parm.15.dim[0].stride = 1;
parm.15.data = (void *) &a[0];
parm.15.offset = -1;
x.dim[0].ubound = x.dim[0].ubound + (1 - x.dim[0].lbound);
x.offset = x.offset - (1 - x.dim[0].lbound) * x.dim[0].stride;
x.dim[0].lbound = 1;
...
so the only field that is correctly initialized is the lbound. Oops.
If the wrapping parenthesis are removed, the program executes successfully,
and the initialization in the dump becomes:
...
x.span = 8;
x.dtype = {.elem_len=4, .version=0, .rank=1, .type=1};
x.dim[0].lbound = 1;
x.dim[0].ubound = 5;
x.dim[0].stride = 1;
x.data = (void * restrict) &a[0].i;
x.offset = -1;
x.dim[0].ubound = x.dim[0].ubound + (1 - x.dim[0].lbound);
x.offset = x.offset - (1 - x.dim[0].lbound) * x.dim[0].stride;
x.dim[0].lbound = 1;
...