public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/106920] New: -Warray-bound false positive regression with -O2 or -Os
@ 2022-09-13  6:44 npfhrotynz-ptnqh.myvf at noclue dot notk.org
  2022-09-13  6:51 ` [Bug c/106920] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: npfhrotynz-ptnqh.myvf at noclue dot notk.org @ 2022-09-13  6:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106920
           Summary: -Warray-bound false positive regression with -O2 or
                    -Os
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: npfhrotynz-ptnqh.myvf at noclue dot notk.org
  Target Milestone: ---

Hello,

I think I've run into a false positive on this file:
https://source.codeaurora.org/external/imx/imx-atf/tree/plat/imx/imx8m/hab.c?h=lf_v2.6

I could trim it down to this
----
#include <stdint.h>

typedef void hab_rvt_entry_t(void);

int main() {
        hab_rvt_entry_t *a;
        a = ((hab_rvt_entry_t *)(*(unsigned long *)(0x908)));
        a();
        return 0;
}
----
$ gcc -O2 -Warray-bounds -c t.c
t.c: In function ‘main’:
t.c:7:34: warning: array subscript 0 is outside array bounds of ‘long unsigned
int[0]’ [-Warray-bounds]
    7 |         a = ((hab_rvt_entry_t *)(*(unsigned long *)(0x908)));
      |                                 ~^~~~~~~~~~~~~~~~~~~~~~~~~~
----

According to godbolt this passed on 11.3 and starts emitting the warning on
12.1 (it doesn't have 12.0) and still emits it on trunk.

Note the warning requires -O2, -O3 or -Os to be emitted.


The problem seems to be that it considers an arbitrary address casted to u64*
to be a u64[0] ?

If so that might be a problem for quite a few embedded products as that is
quite common when dealing with hardware registers.
(and who doesn't love products that compile with -Werror for release builds...)

Thanks!

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

end of thread, other threads:[~2022-09-14  7:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-13  6:44 [Bug c/106920] New: -Warray-bound false positive regression with -O2 or -Os npfhrotynz-ptnqh.myvf at noclue dot notk.org
2022-09-13  6:51 ` [Bug c/106920] " rguenth at gcc dot gnu.org
2022-09-13  7:13 ` [Bug c/106920] -Warray-bound false positive regression with -O2 or -Os and constant address npfhrotynz-ptnqh.myvf at noclue dot notk.org
2022-09-13 16:48 ` pinskia at gcc dot gnu.org
2022-09-14  7:15 ` rguenth at gcc dot gnu.org
2022-09-14  7:37 ` npfhrotynz-ptnqh.myvf at noclue dot notk.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).