[Bug fortran/96312] Reallocation on assignment uses undefined variables
tkoenig at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Jul 24 16:55:34 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96312
Thomas Koenig <tkoenig at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=77504
CC| |dev-zero at gentoo dot org
--- Comment #1 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
Slightly sanitized test case from the originating PR, by Tiziano Müller:
$ cat moda.f90
module moda
contains
PURE SUBROUTINE funca(arr, sz)
REAL, ALLOCATABLE, DIMENSION(:, :), INTENT(OUT) :: arr
integer, intent(in) :: sz
allocate(arr(sz, sz))
arr(:, :) = 0.
END SUBROUTINE
end module
$ cat modb.f90
module modc
use moda, only: funca
contains
PURE SUBROUTINE funcb(oarr)
REAL, DIMENSION(:), INTENT(OUT) :: oarr
REAL, ALLOCATABLE, DIMENSION(:, :) :: arr
real, allocatable, dimension(:) :: tmp
CALL funca(arr, ubound(oarr, 1))
tmp = matmul(transpose(arr),oarr)
oarr = tmp*1.
END SUBROUTINE funcb
end module
Compiled with -O1 -Wall, this yields
$ gfortran -Wall -O1 -c moda.f90 modb.f90
modb.f90:8:0:
8 | oarr = MATMUL(TRANSPOSE(arr), oarr)*1.
|
Warning: '__var_1_matmul.dim[0].lbound' is used uninitialized in this function
[-Wuninitialized]
modb.f90:8:0: Warning: '__var_1_matmul.dim[0].ubound' is used uninitialized in
this function [-Wuninitialized]
Front-end optimization introduces an extra assignment statement here,
this version also shows the warning:
$ cat modc.f90
module modc
use moda, only: funca
contains
PURE SUBROUTINE funcb(oarr)
REAL, DIMENSION(:), INTENT(OUT) :: oarr
REAL, ALLOCATABLE, DIMENSION(:, :) :: arr
real, allocatable, dimension(:) :: tmp
CALL funca(arr, ubound(oarr, 1))
tmp = matmul(transpose(arr), oarr)
oarr = tmp*1.
END SUBROUTINE funcb
end module
The warning seems to be correct:
$ grep __var_1_matmul modb.f90.004t.original
struct array01_real(kind=4) __var_1_matmul;
__var_1_matmul.data = 0B;
__var_1_matmul.dtype = {.elem_len=4, .rank=1, .type=3};
D.3969 = __var_1_matmul;
D.3970 = (real(kind=4)[0:] * restrict) __var_1_matmul.data == 0B;
__builtin_free ((void *) __var_1_matmul.data);
__var_1_matmul.data = D.3969.data;
D.3971 = ((__var_1_matmul.dim[0].lbound - D.3969.dim[0].lbound) -
__var_1_matmul.dim[0].ubound) + D.3969.dim[0].ubound != 0;
D.3973 = D.3972 ? 1 : __var_1_matmul.dim[0].lbound;
__var_1_matmul.dim[0].lbound = D.3973;
__var_1_matmul.dim[0].ubound = D.3969.dim[0].ubound + D.3973;
__var_1_matmul.dim[0].stride = 1;
__var_1_matmul.offset = D.3974;
D.4003 = (real(kind=4)[0:] * restrict) __var_1_matmul.data;
D.4004 = __var_1_matmul.offset;
D.4005 = __var_1_matmul.dim[0].lbound;
D.4006 = __var_1_matmul.dim[0].ubound;
if ((real(kind=4)[0:] * restrict) __var_1_matmul.data != 0B)
__builtin_free ((void *) __var_1_matmul.data);
(real(kind=4)[0:] * restrict) __var_1_matmul.data = 0B;
So, something seems to be wrong with reallocation on assignment here.
More information about the Gcc-bugs
mailing list