public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/66459] bogus warning 'w.offset' may be used uninitialized in this function [-Wmaybe-uninitialized] caused by loop invariant motion (LIM)
Date: Tue, 30 Aug 2022 08:54:37 +0000	[thread overview]
Message-ID: <bug-66459-4-M3YQpnxGi5@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-66459-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2019-02-03 00:00:00         |2022-8-30
            Summary|bogus warning 'w.offset'    |bogus warning 'w.offset'
                   |may be used uninitialized   |may be used uninitialized
                   |in this function            |in this function
                   |[-Wmaybe-uninitialized]     |[-Wmaybe-uninitialized]
                   |                            |caused by loop invariant
                   |                            |motion (LIM)

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
what we warn about in the end is the path when l == 0 && n > 0.  that's also
visible in the initial gfortran IL:

  try
    {
      w.data = 0B;
      w.dtype = {.elem_len=4, .rank=2, .type=1};
      if (*l)
        {
...
        }
      L.1:;
      {
        integer(kind=4) D.4258;

        D.4258 = *n;
        i = 1;
        while (1)
          {
            {
              logical(kind=4) D.4261;

              D.4261 = i > D.4258;
              if (D.4261) goto L.3;
              {
                integer(kind=4) D.4262;

                D.4262 = *m;
                j = 1;
                while (1)
                  {
                    {
                      logical(kind=4) D.4265;

                      D.4265 = j > D.4262;
                      if (D.4265) goto L.5;
                      if ((integer(kind=4)[0:] * restrict) w.data != 0B)
                        {
                          (*(integer(kind=4)[0:] * restrict) w.data)[(w.offset
+ (integer(kind=8)) i * w.dim[1].stride) + (integer(kind=8)) j] = 0;
                        }
                      L.6:;
                      L.4:;
                      j = j + 1;
                    }
                  }
                L.5:;
              }
              L.2:;
              i = i + 1;
            }
          }
        L.3:;

the n > 0 check is simplified from D.4258 = *n; i = 1; D.4261 = i > D.4258;
There's some extra guard, m > j, but that's not related so what uninit
analysis would need to see is the w.data != 0 guard but as Manu said, the
LIM pass hoists the loop invariant uses out of this conditional.

IIRC there's a related bug somewhere for LIM exposing uninitialized uses
to code paths that are not known to execute but here it's not trivial to
see the uninitializedness.

The bogus diagnostic goes away with -fno-tree-loop-im (but you usually do
not want to do that for performance reasons).  At -O3 we unswitch on
w.data != 0 but LIM already moved the access then.  One old idea is to
make sure to disable diagnostics on stmts we move for the sake of
introducing false negatives ...

  parent reply	other threads:[~2022-08-30  8:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-08 11:02 [Bug fortran/66459] New: bogus warning 'w.offset' may be used uninitialized in this function [-Wmaybe-uninitialized] mario-baumann at web dot de
2015-06-08 14:46 ` [Bug fortran/66459] " mikael at gcc dot gnu.org
2022-08-30  8:54 ` rguenth at gcc dot gnu.org [this message]
2023-07-11 16:27 ` [Bug tree-optimization/66459] bogus warning 'w.offset' may be used uninitialized in this function [-Wmaybe-uninitialized] caused by loop invariant motion (LIM) pinskia 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-66459-4-M3YQpnxGi5@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: link
Be 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).