public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/102070] New: missing warning initializing aggregate member with itself
@ 2021-08-25 22:14 msebor at gcc dot gnu.org
  0 siblings, 0 replies; only message in thread
From: msebor at gcc dot gnu.org @ 2021-08-25 22:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102070
           Summary: missing warning initializing aggregate member with
                    itself
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

This is the C "subset" of pr97931.  The test case shows that GCC diagnoses
assigning an uninitialized member of an aggregate to itself but it fails to
warn when the same happens as part of an initializer.

$ cat z.c && gcc -S -Wall -Winit-self -fdump-tree-original=/dev/stdout z.c
struct S { int i, j; };

void f (void*);

void ga (void)
{
  int a[2];
  a[0] = a[0];               // -Wuninitialized (good)
  f (a);
}

void gs (void)
{
  struct S s;
  s.i = s.i;                 // -Wuninitialized (good)
  f (&s);
}

void ha (void)
{
  int a[2] = { [0] = a[0] }; // missing warning
  f (a);
}

void hs (void)
{
  struct S s = { s.i };      // missing warning
  f (&s);
}

;; Function ga (null)
;; enabled by -tree-original


{
  int a[2];

    int a[2];
  a[0] = a[0];
  f ((void *) &a);
}


;; Function gs (null)
;; enabled by -tree-original


{
  struct S s;

    struct S s;
  s.i = s.i;
  f ((void *) &s);
}


;; Function ha (null)
;; enabled by -tree-original


{
  int a[2] = {a[0]};

    int a[2] = {a[0]};
  f ((void *) &a);
}


;; Function hs (null)
;; enabled by -tree-original


{
  struct S s = {.i=s.i};

    struct S s = {.i=s.i};
  f ((void *) &s);
}

z.c: In function ‘ga’:
z.c:8:11: warning: ‘a’ is used uninitialized [-Wuninitialized]
    8 |   a[0] = a[0];               // -Wuninitialized (good)
      |          ~^~~
z.c:7:7: note: ‘a’ declared here
    7 |   int a[2];
      |       ^
z.c: In function ‘gs’:
z.c:15:10: warning: ‘s.i’ is used uninitialized [-Wuninitialized]
   15 |   s.i = s.i;                 // -Wuninitialized (good)
      |         ~^~
z.c:14:12: note: ‘s’ declared here
   14 |   struct S s;
      |            ^

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-25 22:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-25 22:14 [Bug c/102070] New: missing warning initializing aggregate member with itself 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).