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

* [Bug tree-optimization/107274] Incorrect -Wuninitialized on indexed initialization
  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 ` pinskia at gcc dot gnu.org
  2022-10-17  8:00 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-15 22:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Strict aliasing issue. Store is via char but load is via long to a char array.

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

* [Bug tree-optimization/107274] Incorrect -Wuninitialized on indexed initialization
  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
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-10-17  8:00 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |24639
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
No, the issue is that you are accessing 8 bytes on the read and thus the
padding you access that way is not initialized.  Use *(unsigned int)b and the
diagnostic goes away.

[internally GCC doesn't consider an indirect load of size 8 ever aliasing
a store to a 4 byte object - otherwise we wouldn't diagnose a partial
uninit value -- like

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

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

        val = *(unsigned long *)b;
}

which isn't diagnosed]


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