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/65244] Bogus -Wmaybe-uninitialized warning with posix_memalign() and -Og
Date: Wed, 31 Mar 2021 19:05:05 +0000	[thread overview]
Message-ID: <bug-65244-4-d0wE3kE0YP@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-65244-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2015-02-27 00:00:00         |2021-3-31
      Known to fail|                            |10.2.0, 11.0, 4.9.4, 5.5.0,
                   |                            |6.4.0, 7.2.0, 8.3.0, 9.1.0
      Known to work|4.8.2, 5.0                  |
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #15 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning with -Og disappeared with r212559 but still comes back on trunk
with -Og -ftree-bit-ccp.  With that, as the comment in gimple-low.c says, a
call to posix_memalign() is lowered into:

    void *tem;
     res = posix_memalign (&tem, align, size);
     if (res == 0)
       ptr = __builtin_assume_aligned (tem, align);

and at -Og it looks like the two conditionals don't get cleaned up as nicely as
at -O1 and lead to an IL that the warning is designed to trigger on.  This
could be handled by the warning but unless this can come up with other
(especially non-builtin) functions it may not be worth the trouble.

$ cat pr65244.c && gcc -Og -S -Wall -ftree-bit-ccp
-fdump-tree-uninit=/dev/stdout pr65244.c
void exit(int __status) __attribute__ ((__noreturn__));
int posix_memalign(void **__memptr, __SIZE_TYPE__ __alignment, __SIZE_TYPE__
__size);

void *f(void) {
    void *ptr;

    if (posix_memalign(&ptr, 16, 256) != 0)
        exit(1);

    return ptr;
}

;; Function f (f, funcdef_no=0, decl_uid=1949, cgraph_uid=1, symbol_order=0)

pr65244.c: In function ‘f’:
pr65244.c:10:12: warning: ‘ptr’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
   10 |     return ptr;
      |            ^~~
pr65244.c:5:11: note: ‘ptr’ was declared here
    5 |     void *ptr;
      |           ^~~
void * f ()
{
  void * D.1957;
  void * ptr;
  int _1;
  void * _6;

  <bb 2> [local count: 1073741824]:
  _1 = posix_memalign (&D.1957, 16, 256);
  if (_1 == 0)
    goto <bb 3>; [50.00%]
  else
    goto <bb 7>; [50.00%]

  <bb 7> [local count: 536870912]:
  goto <bb 4>; [100.00%]

  <bb 3> [local count: 536870913]:
  _6 = D.1957;

  <bb 4> [local count: 1073741824]:
  # ptr_2 = PHI <ptr_5(D)(7), _6(3)>
  if (_1 != 0)
    goto <bb 5>; [0.04%]
  else
    goto <bb 6>; [99.96%]

  <bb 5> [local count: 429496]:
  exit (1);

  <bb 6> [local count: 1073312329]:
  return ptr_2;

}

  parent reply	other threads:[~2021-03-31 19:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-27 18:51 [Bug c/65244] New: " ulfalizer at gmail dot com
2015-02-27 19:10 ` [Bug c/65244] " ulfalizer at gmail dot com
2015-02-27 21:02 ` manu at gcc dot gnu.org
2015-02-27 21:24 ` ulfalizer at gmail dot com
2015-02-27 21:48 ` manu at gcc dot gnu.org
2015-02-27 22:02 ` ulfalizer at gmail dot com
2015-02-27 22:07 ` howarth at bromo dot med.uc.edu
2015-02-27 23:04 ` ulfalizer at gmail dot com
2015-02-27 23:21 ` pinskia at gcc dot gnu.org
2015-02-28  1:24 ` manu at gcc dot gnu.org
2021-03-31 19:05 ` msebor at gcc dot gnu.org [this message]
2022-08-30  8:27 ` [Bug tree-optimization/65244] " rguenth at gcc dot gnu.org
2022-08-31  9:07 ` rguenth at gcc dot gnu.org
2022-08-31 11:04 ` cvs-commit at gcc dot gnu.org
2022-08-31 11:04 ` 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-65244-4-d0wE3kE0YP@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).