From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E01593858C50; Thu, 9 Feb 2023 06:11:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E01593858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675923113; bh=VO2Q/jj8n6cCQbC949woeklv4Fm7nil/Jj4ED65LtO4=; h=From:To:Subject:Date:From; b=TlKoGxI8o7ubFA07KPDs91R8o5k2o4gI+OJKjxs26tpVi0LgXbiRuPdbbr/MsUQtP SFLME+g4aI/nkAoQc+cu+bfiLepKzCkM9EOKGxKuG99DYoMjiq+8o9DpcOK1+kkGw5 fqni9O1jEzQ89KDDPXRpo29sbkCvmcOZbezNmE4I= From: "rimvydas.jas at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rimvydas.jas at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108735 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 =3D 1 lev =3D max(min(abs(lev),99),2) ! [2,99] do j=3Di, lev, +1 if (j=3D=3Di) then w =3D 2 else r =3D w endif w =3D r + 1 enddo do j=3Dlev, i, -1 if (j=3D=3Dlev) then z =3D 2 else p =3D z endif z =3D 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 =3D 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 =3D 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=3D=3Dlev) then" branch in first iteration is not considered in initialization analysis while still being store optimized out. Changing (j=3D=3Dlev) to (j=3D=3Dlev-1) does not promote diagnostic to -Wun= initialized. Moreover both do loops could be fully optimized down to: lev =3D max(min(abs(lev),99),2) r =3D r + 1*lev - 1 p =3D p + 1*lev - 1=