public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/96312] New: Reallocation on assignment uses undefined variables
@ 2020-07-24 16:47 tkoenig at gcc dot gnu.org
2020-07-24 16:55 ` [Bug fortran/96312] " tkoenig at gcc dot gnu.org
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2020-07-24 16:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96312
Bug ID: 96312
Summary: Reallocation on assignment uses undefined variables
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: tkoenig at gcc dot gnu.org
Target Milestone: ---
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77504#c19 .
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/96312] Reallocation on assignment uses undefined variables
2020-07-24 16:47 [Bug fortran/96312] New: Reallocation on assignment uses undefined variables tkoenig at gcc dot gnu.org
@ 2020-07-24 16:55 ` tkoenig at gcc dot gnu.org
2020-07-24 17:35 ` [Bug fortran/96312] [10/11 Regression] " tkoenig at gcc dot gnu.org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2020-07-24 16:55 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/96312] [10/11 Regression] Reallocation on assignment uses undefined variables
2020-07-24 16:47 [Bug fortran/96312] New: Reallocation on assignment uses undefined variables tkoenig at gcc dot gnu.org
2020-07-24 16:55 ` [Bug fortran/96312] " tkoenig at gcc dot gnu.org
@ 2020-07-24 17:35 ` tkoenig at gcc dot gnu.org
2020-07-24 17:35 ` tkoenig at gcc dot gnu.org
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2020-07-24 17:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96312
Thomas Koenig <tkoenig at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Reallocation on assignment |[10/11 Regression]
|uses undefined variables |Reallocation on assignment
| |uses undefined variables
Target Milestone|--- |9.4
--- Comment #2 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
$ ~/Gcc/9-bin/gcc/f951 -quiet -O -Wall modc.f90
$ ~/Gcc/10-bin/gcc/f951 -quiet -O -Wall modc.f90
modc.f90:9:0:
9 | tmp = matmul(transpose(arr), oarr)
|
Warning: 'tmp.dim[0].lbound' is used uninitialized in this function
[-Wuninitialized]
modc.f90:9:0: Warning: 'tmp.dim[0].ubound' is used uninitialized in this
function [-Wuninitialized]
$ ~/Gcc/trunk-bin/gcc/f951 -quiet -O -Wall modc.f90
modc.f90:9:0:
9 | tmp = matmul(transpose(arr), oarr)
|
Warning: 'tmp.dim[0].lbound' is used uninitialized [-Wuninitialized]
modc.f90:7:44:
7 | real, allocatable, dimension(:) :: tmp
| ^
note: 'tmp' declared here
modc.f90:9:0:
9 | tmp = matmul(transpose(arr), oarr)
|
Warning: 'tmp.dim[0].ubound' is used uninitialized [-Wuninitialized]
modc.f90:7:44:
7 | real, allocatable, dimension(:) :: tmp
| ^
note: 'tmp' declared here
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/96312] [10/11 Regression] Reallocation on assignment uses undefined variables
2020-07-24 16:47 [Bug fortran/96312] New: Reallocation on assignment uses undefined variables tkoenig at gcc dot gnu.org
2020-07-24 16:55 ` [Bug fortran/96312] " tkoenig at gcc dot gnu.org
2020-07-24 17:35 ` [Bug fortran/96312] [10/11 Regression] " tkoenig at gcc dot gnu.org
@ 2020-07-24 17:35 ` tkoenig at gcc dot gnu.org
2020-07-24 17:51 ` tkoenig at gcc dot gnu.org
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2020-07-24 17:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96312
Thomas Koenig <tkoenig at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|9.4 |10.3
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/96312] [10/11 Regression] Reallocation on assignment uses undefined variables
2020-07-24 16:47 [Bug fortran/96312] New: Reallocation on assignment uses undefined variables tkoenig at gcc dot gnu.org
` (2 preceding siblings ...)
2020-07-24 17:35 ` tkoenig at gcc dot gnu.org
@ 2020-07-24 17:51 ` tkoenig at gcc dot gnu.org
2020-07-24 18:18 ` dominiq at lps dot ens.fr
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2020-07-24 17:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96312
--- Comment #3 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
Let's see what bisection brings.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/96312] [10/11 Regression] Reallocation on assignment uses undefined variables
2020-07-24 16:47 [Bug fortran/96312] New: Reallocation on assignment uses undefined variables tkoenig at gcc dot gnu.org
` (3 preceding siblings ...)
2020-07-24 17:51 ` tkoenig at gcc dot gnu.org
@ 2020-07-24 18:18 ` dominiq at lps dot ens.fr
2020-07-25 8:59 ` tkoenig at gcc dot gnu.org
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: dominiq at lps dot ens.fr @ 2020-07-24 18:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96312
Dominique d'Humieres <dominiq at lps dot ens.fr> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Priority|P3 |P4
Status|UNCONFIRMED |NEW
Last reconfirmed| |2020-07-24
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/96312] [10/11 Regression] Reallocation on assignment uses undefined variables
2020-07-24 16:47 [Bug fortran/96312] New: Reallocation on assignment uses undefined variables tkoenig at gcc dot gnu.org
` (4 preceding siblings ...)
2020-07-24 18:18 ` dominiq at lps dot ens.fr
@ 2020-07-25 8:59 ` tkoenig at gcc dot gnu.org
2020-07-25 9:18 ` tkoenig at gcc dot gnu.org
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2020-07-25 8:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96312
Thomas Koenig <tkoenig at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rguenther at suse dot de
--- Comment #4 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
Bisection points towards
2092f134b7180cd2542cff93bd8a876b3e59a77b is the first bad commit
commit 2092f134b7180cd2542cff93bd8a876b3e59a77b
Author: Richard Biener <rguenther@suse.de>
Date: Wed May 15 12:57:32 2019 +0000
tree-into-ssa.c (pass_build_ssa::execute): Run update_address_taken before
going into SSA.
2019-05-15 Richard Biener <rguenther@suse.de>
* tree-into-ssa.c (pass_build_ssa::execute): Run
update_address_taken before going into SSA.
From-SVN: r271209
I tested this (in the bisect script) for the occurrence of the
warning with
$HOME/trunk-bin/gcc/f951 -quiet moda.f90
$HOME/trunk-bin/gcc/f951 -quiet -Wall -O3 modc.f90 -Werror
so it is likely that this patch just started issuing a warning
for a pre-existing bug in the front end.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/96312] [10/11 Regression] Reallocation on assignment uses undefined variables
2020-07-24 16:47 [Bug fortran/96312] New: Reallocation on assignment uses undefined variables tkoenig at gcc dot gnu.org
` (5 preceding siblings ...)
2020-07-25 8:59 ` tkoenig at gcc dot gnu.org
@ 2020-07-25 9:18 ` tkoenig at gcc dot gnu.org
2020-08-08 15:01 ` pault at gcc dot gnu.org
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2020-07-25 9:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96312
--- Comment #5 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
(In reply to Thomas Koenig from comment #4)
> so it is likely that this patch just started issuing a warning
> for a pre-existing bug in the front end.
That is indeed the case. Grepping for tmp in the modc.f90 dump yields
struct array01_real(kind=4) tmp;
tmp.data = 0B;
tmp.dtype = {.elem_len=4, .rank=1, .type=3};
D.2309 = tmp;
D.2310 = (real(kind=4)[0:] * restrict) tmp.data == 0B;
__builtin_free ((void *) tmp.data);
tmp.data = D.2309.data;
D.2311 = ((tmp.dim[0].lbound - D.2309.dim[0].lbound) -
tmp.dim[0].ubound) + D.2309.dim[0].ubound != 0;
D.2313 = D.2312 ? 1 : tmp.dim[0].lbound;
tmp.dim[0].lbound = D.2313;
tmp.dim[0].ubound = D.2309.dim[0].ubound + D.2313;
tmp.dim[0].stride = 1;
tmp.offset = D.2314;
D.2343 = (real(kind=4)[0:] * restrict) tmp.data;
D.2344 = tmp.offset;
D.2345 = tmp.dim[0].lbound;
D.2346 = tmp.dim[0].ubound;
if ((real(kind=4)[0:] * restrict) tmp.data != 0B)
__builtin_free ((void *) tmp.data);
(real(kind=4)[0:] * restrict) tmp.data = 0B;
so there is no way that tmp.dim[0].lbound would have gotten
a value - previous version just didn't see it.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/96312] [10/11 Regression] Reallocation on assignment uses undefined variables
2020-07-24 16:47 [Bug fortran/96312] New: Reallocation on assignment uses undefined variables tkoenig at gcc dot gnu.org
` (6 preceding siblings ...)
2020-07-25 9:18 ` tkoenig at gcc dot gnu.org
@ 2020-08-08 15:01 ` pault at gcc dot gnu.org
2020-08-10 5:22 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pault at gcc dot gnu.org @ 2020-08-08 15:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96312
Paul Thomas <pault at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |pault at gcc dot gnu.org
CC| |pault at gcc dot gnu.org
--- Comment #6 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 49031
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49031&action=edit
Patch for the PR
This is quite straightforward. The patch makes sure that references to the
bounds only occur if the lhs is allocated on arrival at offending statement.
It even regtests OK :-)
Paul
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/96312] [10/11 Regression] Reallocation on assignment uses undefined variables
2020-07-24 16:47 [Bug fortran/96312] New: Reallocation on assignment uses undefined variables tkoenig at gcc dot gnu.org
` (7 preceding siblings ...)
2020-08-08 15:01 ` pault at gcc dot gnu.org
@ 2020-08-10 5:22 ` cvs-commit at gcc dot gnu.org
2020-08-11 7:53 ` cvs-commit at gcc dot gnu.org
2020-08-11 8:04 ` pault at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-08-10 5:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96312
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Paul Thomas <pault@gcc.gnu.org>:
https://gcc.gnu.org/g:abb276d0eca218e62e5ed50babf12ff544250759
commit r11-2625-gabb276d0eca218e62e5ed50babf12ff544250759
Author: Paul Thomas <pault@gcc.gnu.org>
Date: Mon Aug 10 06:22:22 2020 +0100
This patch fixes PR96312. Cures a used uninitialized warning.
2020-08-10 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/96312
* trans-expr.c (fcncall_realloc_result): Only compare shapes if
lhs was allocated..
gcc/testsuite/
PR fortran/96312
* gfortran.dg/pr96312.f90: New test.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/96312] [10/11 Regression] Reallocation on assignment uses undefined variables
2020-07-24 16:47 [Bug fortran/96312] New: Reallocation on assignment uses undefined variables tkoenig at gcc dot gnu.org
` (8 preceding siblings ...)
2020-08-10 5:22 ` cvs-commit at gcc dot gnu.org
@ 2020-08-11 7:53 ` cvs-commit at gcc dot gnu.org
2020-08-11 8:04 ` pault at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-08-11 7:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96312
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Thomas Kथà¤nig
<tkoenig@gcc.gnu.org>:
https://gcc.gnu.org/g:9040b14da7070f30af6d2814097fb7ea1a91707d
commit r10-8603-g9040b14da7070f30af6d2814097fb7ea1a91707d
Author: Paul Thomas <pault@gcc.gnu.org>
Date: Mon Aug 10 06:22:22 2020 +0100
This patch fixes PR96312. Cures a used uninitialized warning.
2020-08-10 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/96312
* trans-expr.c (fcncall_realloc_result): Only compare shapes if
lhs was allocated..
gcc/testsuite/
PR fortran/96312
* gfortran.dg/pr96312.f90: New test.
(cherry picked from commit abb276d0eca218e62e5ed50babf12ff544250759)
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug fortran/96312] [10/11 Regression] Reallocation on assignment uses undefined variables
2020-07-24 16:47 [Bug fortran/96312] New: Reallocation on assignment uses undefined variables tkoenig at gcc dot gnu.org
` (9 preceding siblings ...)
2020-08-11 7:53 ` cvs-commit at gcc dot gnu.org
@ 2020-08-11 8:04 ` pault at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: pault at gcc dot gnu.org @ 2020-08-11 8:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96312
Paul Thomas <pault at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|NEW |RESOLVED
--- Comment #9 from Paul Thomas <pault at gcc dot gnu.org> ---
Thanks for the backport, Thomas.
Fixed on both branches.
Paul
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2020-08-11 8:04 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-24 16:47 [Bug fortran/96312] New: Reallocation on assignment uses undefined variables tkoenig at gcc dot gnu.org
2020-07-24 16:55 ` [Bug fortran/96312] " tkoenig at gcc dot gnu.org
2020-07-24 17:35 ` [Bug fortran/96312] [10/11 Regression] " tkoenig at gcc dot gnu.org
2020-07-24 17:35 ` tkoenig at gcc dot gnu.org
2020-07-24 17:51 ` tkoenig at gcc dot gnu.org
2020-07-24 18:18 ` dominiq at lps dot ens.fr
2020-07-25 8:59 ` tkoenig at gcc dot gnu.org
2020-07-25 9:18 ` tkoenig at gcc dot gnu.org
2020-08-08 15:01 ` pault at gcc dot gnu.org
2020-08-10 5:22 ` cvs-commit at gcc dot gnu.org
2020-08-11 7:53 ` cvs-commit at gcc dot gnu.org
2020-08-11 8:04 ` 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).