public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111123] New: Warning about "used uninitialized" member shown or hidden randomly
@ 2023-08-23 19:57 agriff at tin dot it
  2023-08-23 20:12 ` [Bug c++/111123] " agriff at tin dot it
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: agriff at tin dot it @ 2023-08-23 19:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111123
           Summary: Warning about "used uninitialized" member shown or
                    hidden randomly
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: agriff at tin dot it
  Target Milestone: ---

This code should warning (with -Wall) about the use of `border` that is
uninitialized

    #include <stdio.h>
    #include <vector>

    struct Camera {
        struct P2d {
            float x, y;
        };
        std::vector<P2d> clip_area;
        float border = 10.f;
        int z = 3;
        Camera() : clip_area({{border, border},
                              {1-border, border},
                              {1-border, 1-border},
                              {border, 1-border}})
        { }
    };

    int main() {
        Camera c;
        printf("%.18g\n", c.clip_area[0].x);
    }

However does so only if member `z` is present; commenting out the line `int z =
3;` silences the warning.

This show/hide of the warning happens also pseudo-randomly in other cases
(while I was trying to get the minimum code showing the problem I found many
cases in which removing even an executable statement in the body of a method
triggered the behavior change).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/111123] Warning about "used uninitialized" member shown or hidden randomly
  2023-08-23 19:57 [Bug c++/111123] New: Warning about "used uninitialized" member shown or hidden randomly agriff at tin dot it
@ 2023-08-23 20:12 ` agriff at tin dot it
  2023-08-24  6:52 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: agriff at tin dot it @ 2023-08-23 20:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrea Griffini <agriff at tin dot it> ---
Forgot to say that -O3 is needed to see the warning (this is however expected)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/111123] Warning about "used uninitialized" member shown or hidden randomly
  2023-08-23 19:57 [Bug c++/111123] New: Warning about "used uninitialized" member shown or hidden randomly 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
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-08-24  6:52 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-08-24
             Status|UNCONFIRMED                 |ASSIGNED
           Keywords|                            |diagnostic
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
There's a change in inlining when z is removed.  We then have the separate CTOR

void Camera::Camera (struct Camera * const this)
{
...
 <bb 2> [local count: 1073741824]:
  _2 = *this_6(D).border;
  _3 = 1.0e+0 - _2;
  _68 = {_2, _2, _3, _2};

and fno CLOBBER of *this_6(D) at its start at the time we do late uninit
diagnostics.  That's because we remove those indirect clobbers too early.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/111123] Warning about "used uninitialized" member shown or hidden randomly
  2023-08-23 19:57 [Bug c++/111123] New: Warning about "used uninitialized" member shown or hidden randomly 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
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-08-24  7:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Adding [[gnu::noinline]] to Camera::Camera will never warn.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/111123] Warning about "used uninitialized" member shown or hidden randomly
  2023-08-23 19:57 [Bug c++/111123] New: Warning about "used uninitialized" member shown or hidden randomly agriff at tin dot it
                   ` (2 preceding siblings ...)
  2023-08-24  7:14 ` rguenth at gcc dot gnu.org
@ 2023-08-24  7:36 ` rguenth at gcc dot gnu.org
  2023-08-24 13:11 ` cvs-commit at gcc dot gnu.org
  2023-08-24 13:13 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-08-24  7:36 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/111123] Warning about "used uninitialized" member shown or hidden randomly
  2023-08-23 19:57 [Bug c++/111123] New: Warning about "used uninitialized" member shown or hidden randomly agriff at tin dot it
                   ` (3 preceding siblings ...)
  2023-08-24  7:36 ` rguenth at gcc dot gnu.org
@ 2023-08-24 13:11 ` cvs-commit at gcc dot gnu.org
  2023-08-24 13:13 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-08-24 13:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:abf915193fbf725bb359e6936e10dcc282eb94cc

commit r14-3460-gabf915193fbf725bb359e6936e10dcc282eb94cc
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Aug 24 09:32:54 2023 +0200

    tree-optimization/111123 - indirect clobbers thrown away too early

    The testcase in the PR shows that late uninit diagnostic relies
    on indirect clobbers in CTORs but we throw those away in the fab
    pass which is too early.  The reasoning was they were supposed
    to keep SSA names live but that's no longer the case since DCE
    doesn't treat them as keeping SSA uses live.

    The following instead removes them before out-of-SSA coalescing
    which is the thing that's still affected by them.

            PR tree-optimization/111123
            * tree-ssa-ccp.cc (pass_fold_builtins::execute): Do not
            remove indirect clobbers here ...
            * tree-outof-ssa.cc (rewrite_out_of_ssa): ... but here.
            (remove_indirect_clobbers): New function.

            * g++.dg/warn/Wuninitialized-pr111123-1.C: New testcase.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/111123] Warning about "used uninitialized" member shown or hidden randomly
  2023-08-23 19:57 [Bug c++/111123] New: Warning about "used uninitialized" member shown or hidden randomly agriff at tin dot it
                   ` (4 preceding siblings ...)
  2023-08-24 13:11 ` cvs-commit at gcc dot gnu.org
@ 2023-08-24 13:13 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-08-24 13:13 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|rguenth at gcc dot gnu.org         |unassigned at gcc dot gnu.org
             Status|ASSIGNED                    |NEW

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
middle-end part are fixed, so with optimization we should diagnose this more
consistently now.  Leaving open for -O0 and the C++ FE issue.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-08-24 13:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-23 19:57 [Bug c++/111123] New: Warning about "used uninitialized" member shown or hidden randomly 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
2023-08-24 13:11 ` cvs-commit at gcc dot gnu.org
2023-08-24 13:13 ` rguenth at gcc dot gnu.org

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).