public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rimvydas.jas at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/108735] New: Wrong line reported on -Wmaybe-uninitialized false positive at -O2 and missing optimizations Date: Thu, 09 Feb 2023 06:11:53 +0000 [thread overview] Message-ID: <bug-108735-4@http.gcc.gnu.org/bugzilla/> (raw) 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
reply other threads:[~2023-02-09 6:11 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-108735-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).