From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2734F3858005; Wed, 22 Feb 2023 18:04:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2734F3858005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677089047; bh=e4rso3I+2lkc5M1/q8xxzrjNPUxmnAQwl8UDCByjxnI=; h=From:To:Subject:Date:From; b=cCHgNaXIvt/iaosj+XUoLMjjqhWPAvJDUolq36iNJ8smNYZ8ieAAlR8mF33Hl+Uz+ /596ot0TdGeKgKMi7V6SHc+kee4lfUdsjM0LRtjtdwL9rSNUjpLaS7p48cHbPgY094 LNfZlUdIzZKgJkCMC7mH4zdsWVi19LDqv23W9R2E= From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/108889] New: [12/13 Regression] (Re)Allocate in assignment shows used uninitialized memory warning with -Wall if LHS is unallocated Date: Wed, 22 Feb 2023 18:04:06 +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: diagnostic, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org 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 keywords 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=3D108889 Bug ID: 108889 Summary: [12/13 Regression] (Re)Allocate in assignment shows used uninitialized memory warning with -Wall if LHS is unallocated Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: diagnostic, wrong-code Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: burnus at gcc dot gnu.org Target Milestone: --- The following testcase shows the following -Wall warnings: Warning: =E2=80=98reference.offset=E2=80=99 is used uninitialized [-Wuninit= ialized] Warning: =E2=80=98reference.dim[0].lbound=E2=80=99 is used uninitialized [-= Wuninitialized] Warning: =E2=80=98reference.dim[0].ubound=E2=80=99 may be used uninitialized [-Wmaybe-uninitialized] The warning (but not the issue) is new since GCC 12. The dump shows: D.4310 =3D reference.offset; D.4311 =3D reference.dim[0].lbound; D.4312 =3D reference.dim[0].ubound; D.4313 =3D D.4311 - D.4307; // D.4307 =3D single.var.dim[0].lbound But all expressions are actually re-evaluated later: D.4317 =3D (real(kind=3D4)[0:] * restrict) reference.data =3D=3D 0B; if (D.4317) goto L.4; ... L.4:; ... reference.dim[0].lbound =3D single.var.dim... reference.offset =3D -NON_LVALUE_EXPR ; D.4310 =3D reference.offset; D.4313 =3D reference.dim[0].lbound - D.4307; ... L.5:; /// If the shape was correct, there is a jump to here / L.5 while (1) { if (S.2 > D.4308) goto L.6; (*D.4309)[(S.2 + D.4313) + D.4310] =3D (*D.4305)[S.2 + D.4306]; Thus, D.4313 + D.4310 needs to be evaluated in the no-(re)alloc case and in= the needs-to-be allocated case. Thus, the produced code is fine at the end =E2=80=93 even though there was uninitialized memory in between. =E2=80=94 But this should be fixed, also t= o silence the warning. * * *=20 ! Testcase: Compile with -Wall program main implicit none type :: struct real, allocatable :: var(:) end type struct type(struct) :: single real, allocatable :: reference(:) single%var =3D [1,2,3,4,5] reference =3D single%var if (size(reference) /=3D size(single%var)) stop 1 if (lbound(reference, 1) /=3D 1) stop 3 if (any (reference /=3D single%var)) stop 3 end=