public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/108889] New: [12/13 Regression] (Re)Allocate in assignment shows used uninitialized memory warning with -Wall if LHS is unallocated
@ 2023-02-22 18:04 burnus at gcc dot gnu.org
  2023-02-22 19:30 ` [Bug fortran/108889] " kargl at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2023-02-22 18:04 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/108889] [12/13 Regression] (Re)Allocate in assignment shows used uninitialized memory warning with -Wall if LHS is unallocated
  2023-02-22 18:04 [Bug fortran/108889] New: [12/13 Regression] (Re)Allocate in assignment shows used uninitialized memory warning with -Wall if LHS is unallocated burnus at gcc dot gnu.org
@ 2023-02-22 19:30 ` kargl at gcc dot gnu.org
  2023-02-22 19:35 ` kargl at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: kargl at gcc dot gnu.org @ 2023-02-22 19:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108889

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org

--- Comment #1 from kargl at gcc dot gnu.org ---
This is likely a duplicate of
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106089

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/108889] [12/13 Regression] (Re)Allocate in assignment shows used uninitialized memory warning with -Wall if LHS is unallocated
  2023-02-22 18:04 [Bug fortran/108889] New: [12/13 Regression] (Re)Allocate in assignment shows used uninitialized memory warning with -Wall if LHS is unallocated burnus at gcc dot gnu.org
  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
  3 siblings, 0 replies; 5+ messages in thread
From: kargl at gcc dot gnu.org @ 2023-02-22 19:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108889

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |106089
           Keywords|diagnostic                  |

--- Comment #2 from kargl at gcc dot gnu.org ---
Remove diagnostic keyword.  This has nothing to do with diagnostics.  It flat
out a bug.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106089
[Bug 106089] false positives with -Wuninitialized for allocation on assignment

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/108889] [12/13 Regression] (Re)Allocate in assignment shows used uninitialized memory warning with -Wall if LHS is unallocated
  2023-02-22 18:04 [Bug fortran/108889] New: [12/13 Regression] (Re)Allocate in assignment shows used uninitialized memory warning with -Wall if LHS is unallocated burnus at gcc dot gnu.org
  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
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-02-23  8:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108889

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
           Priority|P3                          |P4
   Target Milestone|---                         |12.3

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug fortran/108889] [12/13/14 Regression] (Re)Allocate in assignment shows used uninitialized memory warning with -Wall if LHS is unallocated
  2023-02-22 18:04 [Bug fortran/108889] New: [12/13 Regression] (Re)Allocate in assignment shows used uninitialized memory warning with -Wall if LHS is unallocated burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-02-23  8:37 ` rguenth at gcc dot gnu.org
@ 2023-05-08 12:26 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-05-08 12:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108889

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.3                        |12.4

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 12.3 is being released, retargeting bugs to GCC 12.4.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-05-08 12:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-22 18:04 [Bug fortran/108889] New: [12/13 Regression] (Re)Allocate in assignment shows used uninitialized memory warning with -Wall if LHS is unallocated burnus at gcc dot gnu.org
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

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).