public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/84078] false positive for -Wmaybe-uninitialized with __asm__
Date: Mon, 05 Apr 2021 17:10:29 +0000	[thread overview]
Message-ID: <bug-84078-4-1RZwIsJ2sk@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-84078-4@http.gcc.gnu.org/bugzilla/>

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |10.2.0, 11.0, 4.1.0, 4.8.4,
                   |                            |4.9.4, 5.5.0, 6.4.0, 7.2.0,
                   |                            |8.3.0, 9.1.0
           Keywords|                            |missed-optimization
   Last reconfirmed|2018-01-29 00:00:00         |2021-4-5
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Reconfirmed with GCC 11 and -O1/-O2 and the slightly reduced test case below. 
I don't see anything in the IL that could be used to prove the uninitialized
variable isn't used: a_3 is uninitialized when b_6 != 0 || x == 0, and a_3 is
used when b_2 == 0 && c_9 == 0.  The two predicates aren't mutually exclusive
so the warning triggers.

$ cat pr84078.c && gcc -O2  -S -Wall -fdump-tree-uninit=/dev/stdout pr84078.c
int x, z;

int f (void);

void g (int b)
{
  int a;

  if (!b)
    {
      if (x)
        a = x;
      else
        b = 1;
    }

  {
    int c;
    __asm __volatile("" : "=r" (c));
    if (c)
      f ();
  }

  if (b)
    return;

  z = a;
}

;; Function g (g, funcdef_no=0, decl_uid=1947, cgraph_uid=1, symbol_order=2)

[AFTER NORMALIZATION -- [DEF]:
 (.NOT.) b_6(D) == 0


[AFTER NORMALIZATION -- [DEF]:
a_3 = PHI <a_7(D)(10), x.0_1(11), a_7(D)(4)>
is guarded by :

x.0_1 != 0 (.AND.) b_6(D) == 0


[AFTER NORMALIZATION -- [USE]:
z = a_3;
is guarded by :

 (.NOT.) b_2 != 0


pr84078.c: In function ‘g’:
pr84078.c:27:5: warning: ‘a’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
   27 |   z = a;
      |   ~~^~~
pr84078.c:7:7: note: ‘a’ was declared here
    7 |   int a;
      |       ^
void g (int b)
{
  int c;
  int a;
  int x.0_1;

  <bb 2> [local count: 1073741824]:
  if (b_6(D) == 0)
    goto <bb 3>; [50.00%]
  else
    goto <bb 10>; [50.00%]

  <bb 10> [local count: 536870912]:
  goto <bb 5>; [100.00%]

  <bb 3> [local count: 536870913]:
  x.0_1 = x;
  if (x.0_1 != 0)
    goto <bb 11>; [50.00%]
  else
    goto <bb 4>; [50.00%]

  <bb 11> [local count: 268435457]:
  goto <bb 5>; [100.00%]

  <bb 4> [local count: 268435457]:

  <bb 5> [local count: 1073741824]:
  # b_2 = PHI <b_6(D)(10), 0(11), 1(4)>
  # a_3 = PHI <a_7(D)(10), x.0_1(11), a_7(D)(4)>
  __asm__ __volatile__("" : "=r" c_9);
  if (c_9 != 0)
    goto <bb 6>; [33.00%]
  else
    goto <bb 12>; [67.00%]

  <bb 12> [local count: 719407024]:
  goto <bb 7>; [100.00%]

  <bb 6> [local count: 354334800]:
  f ();

  <bb 7> [local count: 1073741824]:
  if (b_2 != 0)
    goto <bb 13>; [34.00%]
  else
    goto <bb 8>; [66.00%]

  <bb 13> [local count: 365072224]:
  goto <bb 9>; [100.00%]

  <bb 8> [local count: 708669601]:
  z = a_3;

  <bb 9> [local count: 1073741824]:
  return;

}

       reply	other threads:[~2021-04-05 17:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-84078-4@http.gcc.gnu.org/bugzilla/>
2021-04-05 17:10 ` msebor at gcc dot gnu.org [this message]
2022-11-20  4:16 ` law at gcc dot gnu.org
2022-11-28 22:35 ` 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-84078-4-1RZwIsJ2sk@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).