public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/97931] New: missing -Wuninitialized initializing an aggregate member with itself
@ 2020-11-20 23:11 msebor at gcc dot gnu.org
  2020-11-23  7:31 ` [Bug middle-end/97931] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-11-20 23:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97931
           Summary: missing -Wuninitialized initializing an aggregate
                    member with itself
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Quoting from my reply to
https://gcc.gnu.org/pipermail/gcc-patches/2020-November/559626.html:

> Martin, I notice that the middle-end warning doesn't currently catch this:
> 
> struct B { int i,j; };
> 
> struct A
> {
>    B b;
>    A(): b({b.i}) { }
> };
> 
> A a;
> 
> It does warn if B only has one member; adding the second wrongly 
> silences the warning.

The GIMPLE for A's ctor looks like this:

A::A (struct A * const this)
{
   *this = {CLOBBER};
   {
     this->b = {};
     _1 = this->b.i;
     this->b.i = _1;
   }
}

so the b member is cleared first before it's read from and there's
nothing to warn about.  This happens for C structs too:

void f (void*);

struct A { int i, j; };

void g (void)
{
   struct A a = { a.i };
   f (&a);
}

The uninitialized read is in the original dump (below) so the zero
initialization happens in the gimplifier and could be diagnosed
there.

;; enabled by -tree-original


{
   struct A a = {.i=a.i};

     struct A a = {.i=a.i};
   f ((void *) &a);
}

Martin

PS I think the C++ original dump (below) shows the same problem
despite the Unknown trees that obscure it:

;; Function A::A() (null)
;; enabled by -tree-original


<<cleanup_point <<< Unknown tree: expr_stmt
   *(struct A *) this = {CLOBBER} >>>>>;
{
   <<cleanup_point <<< Unknown tree: expr_stmt
   (void) (((struct A *) this)->b = TARGET_EXPR <D.2389, {.i=((struct A 
*) this)->b.i}>) >>>>>;
}

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

* [Bug middle-end/97931] missing -Wuninitialized initializing an aggregate member with itself
  2020-11-20 23:11 [Bug middle-end/97931] New: missing -Wuninitialized initializing an aggregate member with itself msebor at gcc dot gnu.org
@ 2020-11-23  7:31 ` rguenth at gcc dot gnu.org
  2020-11-24  0:09 ` egallager at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-11-23  7:31 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unknown                     |11.0

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Probably because the FE emits a CONSTRUCTOR node were missing elements are
implicitely zero in GENERIC semantics, unless CONSTRUCTOR_NO_CLEARING is set.

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

* [Bug middle-end/97931] missing -Wuninitialized initializing an aggregate member with itself
  2020-11-20 23:11 [Bug middle-end/97931] New: missing -Wuninitialized initializing an aggregate member with itself msebor at gcc dot gnu.org
  2020-11-23  7:31 ` [Bug middle-end/97931] " rguenth at gcc dot gnu.org
@ 2020-11-24  0:09 ` egallager at gcc dot gnu.org
  2020-11-24 23:11 ` msebor at gcc dot gnu.org
  2021-08-25 22:05 ` [Bug c++/97931] " msebor at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: egallager at gcc dot gnu.org @ 2020-11-24  0:09 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> ---
Shouldn't this go under -Winit-self?

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

* [Bug middle-end/97931] missing -Wuninitialized initializing an aggregate member with itself
  2020-11-20 23:11 [Bug middle-end/97931] New: missing -Wuninitialized initializing an aggregate member with itself msebor at gcc dot gnu.org
  2020-11-23  7:31 ` [Bug middle-end/97931] " rguenth at gcc dot gnu.org
  2020-11-24  0:09 ` egallager at gcc dot gnu.org
@ 2020-11-24 23:11 ` msebor at gcc dot gnu.org
  2021-08-25 22:05 ` [Bug c++/97931] " msebor at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-11-24 23:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
-Winit-self isn't enabled by -Wall in C (to accommodate the 'int i = i;' hack)
so unless that changes I'd rather see it in -Wuninitialized (which is in -Wall
in all C languages).

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

* [Bug c++/97931] missing -Wuninitialized initializing an aggregate member with itself
  2020-11-20 23:11 [Bug middle-end/97931] New: missing -Wuninitialized initializing an aggregate member with itself msebor at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2020-11-24 23:11 ` msebor at gcc dot gnu.org
@ 2021-08-25 22:05 ` msebor at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-08-25 22:05 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|middle-end                  |c++
   Last reconfirmed|                            |2021-08-25
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
There's nothing the middle end can do to warn because the front end emits code
to zero-initialize the struct/class first and only then to use the value of the
zero-initialized member to [re]initialize it.  The detection needs to happen in
the front ends (both C and C++).

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

end of thread, other threads:[~2021-08-25 22:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20 23:11 [Bug middle-end/97931] New: missing -Wuninitialized initializing an aggregate member with itself msebor at gcc dot gnu.org
2020-11-23  7:31 ` [Bug middle-end/97931] " rguenth at gcc dot gnu.org
2020-11-24  0:09 ` egallager at gcc dot gnu.org
2020-11-24 23:11 ` msebor at gcc dot gnu.org
2021-08-25 22:05 ` [Bug c++/97931] " msebor 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).