public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-108889-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108889 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: ‘reference.offset’ is used uninitialized [-Wuninitialized] Warning: ‘reference.dim[0].lbound’ is used uninitialized [-Wuninitialized] Warning: ‘reference.dim[0].ubound’ may be used uninitialized [-Wmaybe-uninitialized] The warning (but not the issue) is new since GCC 12. The dump shows: D.4310 = reference.offset; D.4311 = reference.dim[0].lbound; D.4312 = reference.dim[0].ubound; D.4313 = D.4311 - D.4307; // D.4307 = single.var.dim[0].lbound But all expressions are actually re-evaluated later: D.4317 = (real(kind=4)[0:] * restrict) reference.data == 0B; if (D.4317) goto L.4; ... L.4:; ... reference.dim[0].lbound = single.var.dim... reference.offset = -NON_LVALUE_EXPR <reference.dim[0].lbound>; D.4310 = reference.offset; D.4313 = 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] = (*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 – even though there was uninitialized memory in between. — But this should be fixed, also to silence the warning. * * * ! Testcase: Compile with -Wall program main implicit none type :: struct real, allocatable :: var(:) end type struct type(struct) :: single real, allocatable :: reference(:) single%var = [1,2,3,4,5] reference = single%var if (size(reference) /= size(single%var)) stop 1 if (lbound(reference, 1) /= 1) stop 3 if (any (reference /= single%var)) stop 3 end
next reply other threads:[~2023-02-22 18:04 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-02-22 18:04 burnus at gcc dot gnu.org [this message] 2023-02-22 19:30 ` [Bug fortran/108889] " kargl at gcc dot gnu.org 2023-02-22 19:35 ` kargl at gcc dot gnu.org 2023-02-23 8:37 ` rguenth at gcc dot gnu.org 2023-05-08 12:26 ` [Bug fortran/108889] [12/13/14 " rguenth at gcc dot gnu.org
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-108889-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).