public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "npfhrotynz-ptnqh.myvf at noclue dot notk.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/106920] New: -Warray-bound false positive regression with -O2 or -Os Date: Tue, 13 Sep 2022 06:44:55 +0000 [thread overview] Message-ID: <bug-106920-4@http.gcc.gnu.org/bugzilla/> (raw) 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!
next reply other threads:[~2022-09-13 6:44 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-09-13 6:44 npfhrotynz-ptnqh.myvf at noclue dot notk.org [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-106920-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).