public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/114029] New: -Warray-bounds does not warn for global arrays
@ 2024-02-21 12:13 dangelog at gmail dot com
  2024-02-21 17:28 ` [Bug middle-end/114029] " pinskia at gcc dot gnu.org
  2024-02-21 17:37 ` [Bug c/114029] -Warray-bounds does not warn for const " pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: dangelog at gmail dot com @ 2024-02-21 12:13 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114029
           Summary: -Warray-bounds does not warn for global arrays
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dangelog at gmail dot com
  Target Milestone: ---

Testcase https://gcc.godbolt.org/z/n3zPPE7bq


const int test[]={1, 2, 3};

int main()
{
    return test[3];
}



GCC doesn't warn under -O2 -Wall. It does emit a -Warray-bounds warning if the
`test` array is moved inside `main`; but why not warning for a global variable?

For comparison, Clang always warns (even without any optimization/warning
flag).

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

* [Bug middle-end/114029] -Warray-bounds does not warn for global arrays
  2024-02-21 12:13 [Bug middle-end/114029] New: -Warray-bounds does not warn for global arrays dangelog at gmail dot com
@ 2024-02-21 17:28 ` pinskia at gcc dot gnu.org
  2024-02-21 17:37 ` [Bug c/114029] -Warray-bounds does not warn for const " pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-21 17:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Without `const`, GCC warns at -O2 also.

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

* [Bug c/114029] -Warray-bounds does not warn for const global arrays
  2024-02-21 12:13 [Bug middle-end/114029] New: -Warray-bounds does not warn for global arrays dangelog at gmail dot com
  2024-02-21 17:28 ` [Bug middle-end/114029] " pinskia at gcc dot gnu.org
@ 2024-02-21 17:37 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-21 17:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|middle-end                  |c

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
const form is optimized/removed in the front-end

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

end of thread, other threads:[~2024-02-21 17:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-21 12:13 [Bug middle-end/114029] New: -Warray-bounds does not warn for global arrays dangelog at gmail dot com
2024-02-21 17:28 ` [Bug middle-end/114029] " pinskia at gcc dot gnu.org
2024-02-21 17:37 ` [Bug c/114029] -Warray-bounds does not warn for const " pinskia 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).