public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/108735] New: Wrong line reported on -Wmaybe-uninitialized false positive at -O2 and missing optimizations
@ 2023-02-09 6:11 rimvydas.jas at gmail dot com
0 siblings, 0 replies; only message in thread
From: rimvydas.jas at gmail dot com @ 2023-02-09 6:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108735
Bug ID: 108735
Summary: Wrong line reported on -Wmaybe-uninitialized false
positive at -O2 and missing optimizations
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: rimvydas.jas at gmail dot com
Target Milestone: ---
Reduced testcase:
$ cat ilev.f90
subroutine foo(lev,p,r)
implicit none
integer :: lev,i,j
integer :: p,r,z,w
i = 1
lev = max(min(abs(lev),99),2) ! [2,99]
do j=i, lev, +1
if (j==i) then
w = 2
else
r = w
endif
w = r + 1
enddo
do j=lev, i, -1
if (j==lev) then
z = 2
else
p = z
endif
z = p + 1 ! this is comment
enddo
if (loc(p)>loc(r)) continue ! suppress unused
if (loc(z)>loc(w)) continue ! suppress unused
end subroutine
$ gfortran -Wall -Wextra -O2 -c ilev.f90
ilev.f90:21:29:
21 | z = p + 1 ! this is comment
| ^
Warning: 'z' may be used uninitialized [-Wmaybe-uninitialized]
ilev.f90:4:16:
4 | integer :: p,r,z,w
| ^
note: 'z' was declared here
$ gfortran -Wall -Wextra -O1 -c ilev.f90
ilev.f90:19:9:
19 | p = z
| ^
Warning: 'z' may be used uninitialized [-Wmaybe-uninitialized]
ilev.f90:4:16:
4 | integer :: p,r,z,w
| ^
note: 'z' was declared here
The -O2 and above points to wrong line (also end of the comment).
Comparison of -fdump-tree-optimized of first do loop shows that second loop
gets pessimized, the "if (j==lev) then" branch in first iteration is not
considered in initialization analysis while still being store optimized out.
Changing (j==lev) to (j==lev-1) does not promote diagnostic to -Wuninitialized.
Moreover both do loops could be fully optimized down to:
lev = max(min(abs(lev),99),2)
r = r + 1*lev - 1
p = p + 1*lev - 1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-02-09 6:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-09 6:11 [Bug fortran/108735] New: Wrong line reported on -Wmaybe-uninitialized false positive at -O2 and missing optimizations rimvydas.jas at gmail dot com
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).