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/78391] g++ (any version) at O0 (for O1, O2, O3 is ok) doesn't warn when class members are used uninitialized.
Date: Thu, 01 Apr 2021 00:38:16 +0000	[thread overview]
Message-ID: <bug-78391-4-enOUObRWfB@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-78391-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |10.2.0, 11.0, 7.3.0, 8.3.0,
                   |                            |9.2.0
                 CC|                            |msebor at gcc dot gnu.org
   Last reconfirmed|2016-11-17 00:00:00         |2021-3-31

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
Reconfirmed with GCC 11.

GCC does issue -Wuninitialized without optimization on an equivalent test case
with an explicit ctor.  The difference between the two ctors is that B's has a
clobber:

$ cat pr78391.C && PRED_DUMP=euninit gcc -S -Wall pr78391.C
struct A { int x = w; int w = 10; };

int f ()
{
  A a;
  return a.x;
}

struct B { int x, w; B (): x(w), w (10) { } };

int g ()
{
  B b;
  return b.x;
}

void A::A (struct A * const this)
{
  int _1;

  <bb 2> :
  # VUSE <.MEM_2(D)>           <<< no clobber
  _1 = this_3(D)->w;           <<< -Wuninitialized
  # .MEM_4 = VDEF <.MEM_2(D)>
  this_3(D)->x = _1;
  # .MEM_5 = VDEF <.MEM_4>
  this_3(D)->w = 10;
  # VUSE <.MEM_5>
  return;

}


int f ()
{
  struct A a;
  int D.2439;
  int _3;

  <bb 2> :
  # .MEM_2 = VDEF <.MEM_1(D)>
  A::A (&a);
  # VUSE <.MEM_2>
  _3 = a.x;
  # .MEM_4 = VDEF <.MEM_2>
  a ={v} {CLOBBER};

  <bb 3> :
<L1>:
  # VUSE <.MEM_4>
  return _3;

}


void B::B (struct B * const this)
{
  int _1;

  <bb 2> :
  # .MEM_4 = VDEF <.MEM_2(D)>
  *this_3(D) ={v} {CLOBBER};   <<< clobber here
  # VUSE <.MEM_4>
  _1 = this_3(D)->w;           <<< -Wuninitialized
  # .MEM_5 = VDEF <.MEM_4>
  this_3(D)->x = _1;
  # .MEM_6 = VDEF <.MEM_5>
  this_3(D)->w = 10;
  # VUSE <.MEM_6>
  return;

}


pr78391.C: In constructor ‘B::B()’:
pr78391.C:9:30: warning: ‘*this.B::w’ is used uninitialized [-Wuninitialized]
    9 | struct B { int x, w; B (): x(w), w (10) { } };
      |                              ^
int g ()
{
  struct B b;
  int D.2442;
  int _3;

  <bb 2> :
  # .MEM_2 = VDEF <.MEM_1(D)>
  B::B (&b);
  # VUSE <.MEM_2>
  _3 = b.x;
  # .MEM_4 = VDEF <.MEM_2>
  b ={v} {CLOBBER};

  <bb 3> :
<L1>:
  # VUSE <.MEM_4>
  return _3;

}

       reply	other threads:[~2021-04-01  0:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-78391-4@http.gcc.gnu.org/bugzilla/>
2021-04-01  0:38 ` msebor at gcc dot gnu.org [this message]
2021-04-01  0:46 ` [Bug c++/78391] " msebor at gcc dot gnu.org
2021-04-02 16:49 ` [Bug middle-end/78391] " msebor at gcc dot gnu.org
2021-04-02 16:51 ` msebor at gcc dot gnu.org
2021-11-19 16:20 ` egallager at gcc dot gnu.org
2022-01-26 17:32 ` msebor at gcc dot gnu.org
2022-05-06  8:29 ` jakub at gcc dot gnu.org
2023-05-08 12:21 ` rguenth at gcc dot gnu.org
2024-06-20  8:55 ` 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-78391-4-enOUObRWfB@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).