public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/107274] New: Incorrect -Wuninitialized on indexed initialization
@ 2022-10-15 22:15 keegan at undefinedbehaviour dot org
  2022-10-15 22:19 ` [Bug tree-optimization/107274] " pinskia at gcc dot gnu.org
  2022-10-17  8:00 ` rguenth at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: keegan at undefinedbehaviour dot org @ 2022-10-15 22:15 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107274
           Summary: Incorrect -Wuninitialized on indexed initialization
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: keegan at undefinedbehaviour dot org
  Target Milestone: ---

Given:

void
example(unsigned long val)
{
        unsigned char b[4];

        b[0] = val;
        b[1] = val >> 8;
        b[2] = val >> 16;
        b[3] = val >> 24;

        val = *(unsigned long *)b;
}

GCC 12.2 issues the following (incorrect) diagnostic:

issue.c: In function 'example':
issue.c:11:13: warning: 'b' is used uninitialized [-Wuninitialized]
   11 |         val = *(unsigned long *)b;
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~
issue.c:4:23: note: 'b' declared here
    4 |         unsigned char b[4];
      |                       ^

Instead this code is correct in that it initializes all fields of "b". It
appears the cast indirection is what is causing the issue, because I cannot get
the diagnostic to be issued for other uses.

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

end of thread, other threads:[~2022-10-17  8:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-15 22:15 [Bug tree-optimization/107274] New: Incorrect -Wuninitialized on indexed initialization keegan at undefinedbehaviour dot org
2022-10-15 22:19 ` [Bug tree-optimization/107274] " pinskia at gcc dot gnu.org
2022-10-17  8:00 ` 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).