public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/111123] Warning about "used uninitialized" member shown or hidden randomly
Date: Thu, 24 Aug 2023 07:36:04 +0000	[thread overview]
Message-ID: <bug-111123-4-1TYAAo7aTt@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-111123-4@http.gcc.gnu.org/bugzilla/>

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org
             Blocks|                            |24639

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
The interesting thing is that enabling the middle-end diagnostic to trigger
shows we emit duplicate diagnostics:

struct Camera {
    float clip_area;
    float border = 10.f;
    [[gnu::noinline]] Camera() : clip_area(border) { }
};

Camera foo()
{
  Camera c;
  return c;
}

emits

t.C: In constructor 'Camera::Camera()':
t.C:4:44: warning: member 'Camera::border' is used uninitialized
[-Wuninitialized]
    4 |     [[gnu::noinline]] Camera() : clip_area(border) { }
      |                                            ^~~~~~
t.C: In constructor 'Camera::Camera()':
t.C:4:44: warning: '*this.Camera::border' is used uninitialized
[-Wuninitialize]
    4 |     [[gnu::noinline]] Camera() : clip_area(border) { }
      |                                            ^~~~~~

the first is from the C++ FE find_uninit_fields diagnostic which for some
reason doesn't work for the testcase in the description, possibly
the initializer list(?) isn't handled?  The early uninit IL is

  <bb 2> :
  MEM[(struct __as_base  &)this_6(D)] ={v} {CLOBBER};
  _1 = &this_6(D)->clip_area;
  std::allocator<Camera::P2d>::allocator (&D.26049);
  _2 = this_6(D)->border;
  D.26047[0].x = _2;
  _3 = this_6(D)->border;
  D.26047[0].y = _3;
  D.27007._M_array = &D.26047;
  D.27007._M_len = 1;
  std::vector<Camera::P2d>::vector (_1, D.27007, &D.26049);

the call to std::allocator<Camera::P2d>::allocator is thought to clobber
*this and thus possibly initialize 'border' here.

I'm testing a middle-end fix here - Marek, can you see whether it's possible
to detect this in the frontend?  The middle-end will require optimization.
The duplicate diagnostic might also be interesting to look at, but that
might already be reported separately?


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639
[Bug 24639] [meta-bug] bug to track all Wuninitialized issues

  parent reply	other threads:[~2023-08-24  7:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-23 19:57 [Bug c++/111123] New: " agriff at tin dot it
2023-08-23 20:12 ` [Bug c++/111123] " agriff at tin dot it
2023-08-24  6:52 ` rguenth at gcc dot gnu.org
2023-08-24  7:14 ` rguenth at gcc dot gnu.org
2023-08-24  7:36 ` rguenth at gcc dot gnu.org [this message]
2023-08-24 13:11 ` cvs-commit at gcc dot gnu.org
2023-08-24 13:13 ` 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-111123-4-1TYAAo7aTt@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).