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 tree-optimization/90710] Bogus Wmaybe-uninitialized caused by __builtin_expect when compiled with -Og
Date: Tue, 06 Apr 2021 23:13:51 +0000	[thread overview]
Message-ID: <bug-90710-4-wIWdLhKW8c@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-90710-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2019-06-02 00:00:00         |2021-4-6
      Known to fail|                            |10.2.1, 11.0, 9.3.0
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
Reconfirmed with GCC 11.  My enhanced version of trunk under test prints:

pr90710.c: In function ‘testFunction’:
pr90710.c:22:17: warning: ‘value’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
   22 |                 printf("My if() causes -Wmaybe-uninitialized for my use
of `value': %d\n",value);
      |                
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pr90710.c:17:22: note: when ‘x == 0’
   17 |         unsigned int value;
      |                      ^~~~~
pr90710.c:17:22: note: used when ‘_11 = PHI <0(3), 1(9)> != 0’
pr90710.c:17:22: note: ‘value’ was declared here


The IL the warning sees (annotated with my comments) is below.  The predicate
that guards the possibly uninitialized use is (was_ok_8 != 0 && was_ok_8 == 0),
which the warning should be able to determine is false.  It doesn't because, as
a result of the __builtin_expect() intrinsic which converts the first argument
to long int, the assignment 'was_ok_8 = (int) _11' in bb 4 involves a
conversion that the warning code doesn't handle.  Changing the type of the
variables to long avoids the warning.

__attribute__((noinline))
void testFunction ()
{
  int was_ok;
  unsigned int value;
  volatile unsigned int x;
  unsigned int x.0_1;
  long int _2;
  unsigned int _11;

  <bb 2> [local count: 1073741824]:
  # .MEM_7 = VDEF <.MEM_6(D)>
  x ={v} 1;
  # VUSE <.MEM_7>
  x.0_1 ={v} x;
  if (x.0_1 == 0)
    goto <bb 3>; [34.00%]
  else
    goto <bb 9>; [66.00%]

  <bb 9> [local count: 708669600]:
  goto <bb 4>; [100.00%]

  <bb 3> [local count: 365072224]:

  <bb 4> [local count: 1073741824]:
  # _11 = PHI <0(3), 1(9)>
  # value_12 = PHI <value_13(D)(3), x.0_1(9)>
  was_ok_8 = (int) _11;            <<< int to long conversion gets in the way
  if (was_ok_8 != 0)
    goto <bb 5>; [33.00%]
  else
    goto <bb 10>; [67.00%]          <<< was_ok_8 == 0

  <bb 10> [local count: 719407024]:
  goto <bb 6>; [100.00%]

  <bb 5> [local count: 354334800]:
  # .MEM_9 = VDEF <.MEM_7>
  printf ("My if() compiles fine: %d\n", value_12);

  <bb 6> [local count: 1073741824]:
  # .MEM_4 = PHI <.MEM_7(10), .MEM_9(5)>
  _2 = (long int) was_ok_8;
  if (_2 != 0)
    goto <bb 7>; [90.00%]           <<< was_ok_8 != 0
  else
    goto <bb 11>; [10.00%]

  <bb 11> [local count: 107374184]:
  goto <bb 8>; [100.00%]

  <bb 7> [local count: 966367641]:
  ## value_12 used when was_ok_8 != 0 AND was_ok_8 == 0   <<< must be false
  # .MEM_10 = VDEF <.MEM_4>
  printf ("My if() causes -Wmaybe-uninitialized for my use of `value\': %d\n",
value_12);

  <bb 8> [local count: 1073741824]:
  # .MEM_5 = PHI <.MEM_4(11), .MEM_10(7)>
  # VUSE <.MEM_5>
  return;

}

       reply	other threads:[~2021-04-06 23:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-90710-4@http.gcc.gnu.org/bugzilla/>
2021-04-06 23:13 ` msebor at gcc dot gnu.org [this message]
2021-04-06 23:16 ` msebor 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-90710-4-wIWdLhKW8c@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).