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/95818] wrong "used uninitialized" warning
Date: Tue, 23 Jun 2020 00:21:45 +0000	[thread overview]
Message-ID: <bug-95818-4-yE7qgvoI97@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-95818-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end
         Resolution|---                         |INVALID
                 CC|                            |msebor at gcc dot gnu.org
             Status|WAITING                     |RESOLVED

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
This instance of the warning looks familiar but I can't reproduce it with my
build of the kernel.  The code in the test case isn't valid (it triggers both
-Wstrict-aliasing and -Wuninitialized), and I don't think it's safe either. 
Only the leading 48 bits of the struct are initialized (by GCC; the program
initializes just 35 bits) but the access is to the full 64 bits.  Clearing the
whole struct by calling memset avoids the -Wuninitialized.

A small test case that reproduces both warnings is below.

$ cat z.c && gcc -O2 -S -Wall -fdump-tree-uninit=/dev/stdout z.c
struct S
{
  int a;
  short i: 1;
};

void f (long);

void g (void)
{
  struct S s;
  s.a = 0;
  s.i = 1;
  f (*(long*)&s);
}
z.c: In function ‘g’:
z.c:14:7: warning: dereferencing type-punned pointer will break strict-aliasing
rules [-Wstrict-aliasing]
   14 |   f (*(long*)&s);
      |       ^~~~~~~~~
z.c:14:3: warning: ‘s’ is used uninitialized [-Wuninitialized]
   14 |   f (*(long*)&s);
      |   ^~~~~~~~~~~~~~
z.c:11:12: note: ‘s’ declared here
   11 |   struct S s;
      |            ^

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

g ()
{
  struct S s;
  long int _1;

  <bb 2> [local count: 1073741824]:
  s.a = 0;
  s.i = -1;
  _1 = MEM[(long int *)&s];
  f (_1); [tail call]
  s ={v} {CLOBBER};
  return;

}

  parent reply	other threads:[~2020-06-23  0:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-22 12:53 [Bug c/95818] New: " ferruh.yigit at intel dot com
2020-06-22 13:00 ` [Bug c/95818] " rguenth at gcc dot gnu.org
2020-06-22 15:11 ` ferruh.yigit at intel dot com
2020-06-22 19:29 ` glisse at gcc dot gnu.org
2020-06-22 23:55 ` ferruh.yigit at intel dot com
2020-06-22 23:59 ` ferruh.yigit at intel dot com
2020-06-23  0:21 ` msebor at gcc dot gnu.org [this message]
2020-06-23  0:35 ` [Bug middle-end/95818] " ferruh.yigit at intel dot com
2020-06-23  1:58 ` 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-95818-4-yE7qgvoI97@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).