public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/104060] New: -Wmaybe-uninitialized false alarm on address of local array
@ 2022-01-17  3:41 eggert at cs dot ucla.edu
  2022-01-17  3:49 ` [Bug tree-optimization/104060] [11/12 Regression] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: eggert at cs dot ucla.edu @ 2022-01-17  3:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104060
           Summary: -Wmaybe-uninitialized false alarm on address of local
                    array
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at cs dot ucla.edu
  Target Milestone: ---

Created attachment 52209
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52209&action=edit
compile with 'gcc -Wuninitialized' to see the false alarm

I ran into this problem when compiling an experimental version of GNU coreutils
with gcc 11.2.1 20211203 (Red Hat 11.2.1-7), x86-64.

This is a regression, since gcc 8.5.0 20210514 (Red Hat 8.5.0-4) does not have
the problem.

Compile the attached program with 'gcc -Wuninitialized -S
false-alarm-uninit.c'. There should be no output, but GCC outputs the
following. The diagnostic is incorrect, as bin_buffer_unaligned is an array
that is never read from or written to. Apparently GCC is getting confused
because the array's address is taken (but that address is never dereferenced).

false-alarm-uninit.c: In function ‘digest_check’:
false-alarm-uninit.c:13:31: warning: ‘bin_buffer_unaligned’ may be used
uninitialized [-Wmaybe-uninitialized]
   13 |   unsigned char *bin_buffer = ptr_align (bin_buffer_unaligned, 1024);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
false-alarm-uninit.c:2:1: note: by argument 1 of type ‘const void *’ to
‘ptr_align’ declared here
    2 | ptr_align (void const *ptr, unsigned long alignment)
      | ^~~~~~~~~
false-alarm-uninit.c:12:17: note: ‘bin_buffer_unaligned’ declared here
   12 |   unsigned char bin_buffer_unaligned[10000];
      |                 ^~~~~~~~~~~~~~~~~~~~

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

* [Bug tree-optimization/104060] [11/12 Regression] -Wmaybe-uninitialized false alarm on address of local array
  2022-01-17  3:41 [Bug tree-optimization/104060] New: -Wmaybe-uninitialized false alarm on address of local array eggert at cs dot ucla.edu
@ 2022-01-17  3:49 ` pinskia at gcc dot gnu.org
  2022-01-17  8:45 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-17  3:49 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-01-17
      Known to work|                            |10.3.0
            Summary|-Wmaybe-uninitialized false |[11/12 Regression]
                   |alarm on address of local   |-Wmaybe-uninitialized false
                   |array                       |alarm on address of local
                   |                            |array
      Known to fail|                            |11.1.0
           Keywords|                            |diagnostic
   Target Milestone|---                         |11.3

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed reduced further:
void *ptr_align (void const *ptr, unsigned long alignment);

int j (void)
{
  unsigned char j[10000];
  unsigned char *k = ptr_align (j, 1024);
  return !k;
}

The warning is suspect to make sure you have accessed something inside j before
the call to ptr_align but it looks like the warning just produces false
positive 100% of the time in this testcase and there is no way for the warning
to be shut up correctly..
There is no way for GCC to know what ptr_align does, GCC thinks it reads from
the first argument but it does not.

Note my recommendation to how to fix this is we should just revert this warning
which was added for GCC 11 and close the original bug which asks about this
warning as won't fix.

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

* [Bug tree-optimization/104060] [11/12 Regression] -Wmaybe-uninitialized false alarm on address of local array
  2022-01-17  3:41 [Bug tree-optimization/104060] New: -Wmaybe-uninitialized false alarm on address of local array eggert at cs dot ucla.edu
  2022-01-17  3:49 ` [Bug tree-optimization/104060] [11/12 Regression] " pinskia at gcc dot gnu.org
@ 2022-01-17  8:45 ` rguenth at gcc dot gnu.org
  2022-04-21  7:51 ` rguenth at gcc dot gnu.org
  2023-05-29 10:06 ` [Bug tree-optimization/104060] [11/12/13/14 " jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-17  8:45 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
                 CC|                            |hubicka at gcc dot gnu.org,
                   |                            |msebor at gcc dot gnu.org,
                   |                            |rguenth at gcc dot gnu.org

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note we can eventually use modref info in the "wrong way" to query whether the
argument is dereferenced.  Note it can only alswer the question whether it
may be dereferenced or whether it kills (via stores) a specific range based on
it, both are not an exact match here since modref will conservatively say
the argument is dereferenced.

But I agree with Andrew - with the above we could make the warning only trigger
for local functions GCC saw the body for (or with LTO bodies analyzed during
IPA but now in another LTRANS unit).  That should eventually reduce the number
of false positives.

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

* [Bug tree-optimization/104060] [11/12 Regression] -Wmaybe-uninitialized false alarm on address of local array
  2022-01-17  3:41 [Bug tree-optimization/104060] New: -Wmaybe-uninitialized false alarm on address of local array eggert at cs dot ucla.edu
  2022-01-17  3:49 ` [Bug tree-optimization/104060] [11/12 Regression] " pinskia at gcc dot gnu.org
  2022-01-17  8:45 ` rguenth at gcc dot gnu.org
@ 2022-04-21  7:51 ` rguenth at gcc dot gnu.org
  2023-05-29 10:06 ` [Bug tree-optimization/104060] [11/12/13/14 " jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-21  7:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.3                        |11.4

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 11.3 is being released, retargeting bugs to GCC 11.4.

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

* [Bug tree-optimization/104060] [11/12/13/14 Regression] -Wmaybe-uninitialized false alarm on address of local array
  2022-01-17  3:41 [Bug tree-optimization/104060] New: -Wmaybe-uninitialized false alarm on address of local array eggert at cs dot ucla.edu
                   ` (2 preceding siblings ...)
  2022-04-21  7:51 ` rguenth at gcc dot gnu.org
@ 2023-05-29 10:06 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-05-29 10:06 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.4                        |11.5

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 11.4 is being released, retargeting bugs to GCC 11.5.

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

end of thread, other threads:[~2023-05-29 10:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-17  3:41 [Bug tree-optimization/104060] New: -Wmaybe-uninitialized false alarm on address of local array eggert at cs dot ucla.edu
2022-01-17  3:49 ` [Bug tree-optimization/104060] [11/12 Regression] " pinskia at gcc dot gnu.org
2022-01-17  8:45 ` rguenth at gcc dot gnu.org
2022-04-21  7:51 ` rguenth at gcc dot gnu.org
2023-05-29 10:06 ` [Bug tree-optimization/104060] [11/12/13/14 " jakub 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).