public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/95072] New: -Warray-bounds false positive with flexible array bounds (regression from GCC 9)
@ 2020-05-12  0:04 eggert at cs dot ucla.edu
  2020-05-12  0:29 ` [Bug middle-end/95072] " msebor at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: eggert at cs dot ucla.edu @ 2020-05-12  0:04 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95072
           Summary: -Warray-bounds false positive with flexible array
                    bounds (regression from GCC 9)
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at cs dot ucla.edu
  Target Milestone: ---

Created attachment 48514
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48514&action=edit
Test program illustrating the -Warray-bounds=2 false alarm

I ran into several false alarms when building GNU Emacs master with GCC 10.1.0
x86-64, which I compiled from source under RHEL 7.7. To reproduce one of them,
compile the attached file xx3.i (a drastic simplification of the Emacs
original) with:

gcc -S -Warray-bounds=2 -O2 xx3.i

The output I get is:

xx3.i: In function 'set_frame_menubar':
xx3.i:17:5: warning: 'memcpy' offset 3 from the object at 'menu_bar_vector' is
\
out of the bounds of referenced subobject 'contents' with type 'union Lisp_X
*[\
]' at offset 3 [-Warray-bounds]
   17 |     memcpy (previous_items,
      |     ^~~~~~~~~~~~~~~~~~~~~~~
   18 |      ((struct Lisp_Vector *) ((char *) menu_bar_vector - 5))->contents,
      |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   19 |      previous_menu_items_used);
      |      ~~~~~~~~~~~~~~~~~~~~~~~~~
xx3.i:9:17: note: subobject 'contents' declared here
    9 |     Lisp_Object contents[];
      |                 ^~~~~~~~

In the Emacs original, menu_bar_vector is a tagged pointer; subtracting 5 gives
you the true pointer to the struct. Somehow the subtraction of 5 confuses GCC
and it incorrectly claims that the flexible array member has an upper bound of
at most 3.

I do not observe the problem with GCC 9.3.0 on the same platform.

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

end of thread, other threads:[~2024-03-10 21:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-12  0:04 [Bug middle-end/95072] New: -Warray-bounds false positive with flexible array bounds (regression from GCC 9) eggert at cs dot ucla.edu
2020-05-12  0:29 ` [Bug middle-end/95072] " msebor at gcc dot gnu.org
2020-05-12  7:07 ` [Bug middle-end/95072] [10/11 Regression] " rguenth at gcc dot gnu.org
2020-07-23  6:51 ` rguenth at gcc dot gnu.org
2021-04-08 12:02 ` rguenth at gcc dot gnu.org
2022-03-17 19:50 ` [Bug middle-end/95072] [10/11/12 " msebor at gcc dot gnu.org
2022-06-28 10:40 ` [Bug middle-end/95072] [10/11/12/13 " jakub at gcc dot gnu.org
2023-07-07 10:37 ` [Bug middle-end/95072] [11/12/13/14 " rguenth at gcc dot gnu.org
2024-03-10 21:52 ` [Bug middle-end/95072] [11/12/13 " law 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).