public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/78391] g++ (any version) at O0 (for O1, O2, O3 is ok) doesn't warn when class members are used uninitialized.
       [not found] <bug-78391-4@http.gcc.gnu.org/bugzilla/>
@ 2021-04-01  0:38 ` msebor at gcc dot gnu.org
  2021-04-01  0:46 ` [Bug c++/78391] " msebor at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-01  0:38 UTC (permalink / raw)
  To: gcc-bugs

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;

}

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

* [Bug c++/78391] g++ (any version) at O0 (for O1, O2, O3 is ok) doesn't warn when class members are used uninitialized.
       [not found] <bug-78391-4@http.gcc.gnu.org/bugzilla/>
  2021-04-01  0:38 ` [Bug middle-end/78391] g++ (any version) at O0 (for O1, O2, O3 is ok) doesn't warn when class members are used uninitialized msebor at gcc dot gnu.org
@ 2021-04-01  0:46 ` msebor at gcc dot gnu.org
  2021-04-02 16:49 ` [Bug middle-end/78391] " msebor at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-01  0:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|middle-end                  |c++
           Severity|enhancement                 |normal

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
So the missing warning seems like it might be due to a bug in the C++ front
end.

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

* [Bug middle-end/78391] g++ (any version) at O0 (for O1, O2, O3 is ok) doesn't warn when class members are used uninitialized.
       [not found] <bug-78391-4@http.gcc.gnu.org/bugzilla/>
  2021-04-01  0:38 ` [Bug middle-end/78391] g++ (any version) at O0 (for O1, O2, O3 is ok) doesn't warn when class members are used uninitialized msebor at gcc dot gnu.org
  2021-04-01  0:46 ` [Bug c++/78391] " msebor at gcc dot gnu.org
@ 2021-04-02 16:49 ` msebor at gcc dot gnu.org
  2021-04-02 16:51 ` msebor at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-02 16:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=19808
             Status|NEW                         |ASSIGNED
          Component|c++                         |middle-end

--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
In bug 19808 comment #38 Jason explains why the CLOBBER isn't present in the
constructor, so that's not a bug.  In light of that, I'm not sure the request
can be implemented without introducing what are strictly speaking false
positives like those Clang suffers from.  In the test case below, the global a
is implicitly zeroed out first and then its members are explicitly assigned, so
there is no uninitialized read.

At the same time, I suspect the result of this initialization is probably not
going to be what the author intended, and so warning on it regardless might
actually be useful (admittedly, issuing -Wuninitialized in this case would be a
bit misleading).  So with that, -Wuninitialized or -Wmaybe-uninitialized in the
middle end could be probably enhanced to detect this pattern of intialization
dependencies.  Marek submitted a C++ patch for a subset of pr19808 last
November but I'm not sure it handled this case.  The patch was also not
approved as Jason's preference was to detect these things in the middle end. 
So let me reassign this back to the middle end and try to remember to get to it
for GCC 12.

$ cat t.C && clang -S t.C
struct A { int x = w; int w = 10; };

A a;
t.C:1:20: warning: field 'w' is uninitialized when used here [-Wuninitialized]
struct A { int x = w; int w = 10; };
                   ^
t.C:3:3: note: in implicit default constructor for 'A' first required here
A a;
  ^
t.C:1:8: note: during field initialization in the implicit default constructor
struct A { int x = w; int w = 10; };
       ^
1 warning generated.

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

* [Bug middle-end/78391] g++ (any version) at O0 (for O1, O2, O3 is ok) doesn't warn when class members are used uninitialized.
       [not found] <bug-78391-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-02 16:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Martin Sebor <msebor at gcc dot gnu.org> ---
Patch for pr19808:
https://gcc.gnu.org/pipermail/gcc-patches/2020-November/559162.html

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

* [Bug middle-end/78391] g++ (any version) at O0 (for O1, O2, O3 is ok) doesn't warn when class members are used uninitialized.
       [not found] <bug-78391-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: egallager at gcc dot gnu.org @ 2021-11-19 16:20 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |egallager at gcc dot gnu.org

--- Comment #8 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #7)
> Patch for pr19808:
> https://gcc.gnu.org/pipermail/gcc-patches/2020-November/559162.html

That's fixed now.

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

* [Bug middle-end/78391] g++ (any version) at O0 (for O1, O2, O3 is ok) doesn't warn when class members are used uninitialized.
       [not found] <bug-78391-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  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
  7 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-01-26 17:32 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #9 from Martin Sebor <msebor at gcc dot gnu.org> ---
This has been improved in GCC 12 but GCC still doesn't diagnose the original
test case at -O0.  It seems that it should be able to, either in the C++ front
end or even in the middle end.  I'm not working on this anymore.

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

* [Bug middle-end/78391] g++ (any version) at O0 (for O1, O2, O3 is ok) doesn't warn when class members are used uninitialized.
       [not found] <bug-78391-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  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
  7 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-05-06  8:29 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.0                        |12.2

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 12.1 is being released, retargeting bugs to GCC 12.2.

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

* [Bug middle-end/78391] g++ (any version) at O0 (for O1, O2, O3 is ok) doesn't warn when class members are used uninitialized.
       [not found] <bug-78391-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2022-05-06  8:29 ` jakub at gcc dot gnu.org
@ 2023-05-08 12:21 ` rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-05-08 12:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.3                        |12.4

--- Comment #12 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 12.3 is being released, retargeting bugs to GCC 12.4.

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

end of thread, other threads:[~2023-05-08 12:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-78391-4@http.gcc.gnu.org/bugzilla/>
2021-04-01  0:38 ` [Bug middle-end/78391] g++ (any version) at O0 (for O1, O2, O3 is ok) doesn't warn when class members are used uninitialized msebor at gcc dot gnu.org
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

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