public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/109233] [12/13 Regression] warning: array subscript 5 is above array bounds of ‘struct tg3_napi[5]’ since r12-2591 Date: Wed, 22 Mar 2023 14:37:37 +0000 [thread overview] Message-ID: <bug-109233-4-1ZZZfxFFMV@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-109233-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109233 --- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Slightly further reduced: /* { dg-do compile } */ /* { dg-options "-O2 -Warray-bounds" } */ struct S { unsigned x, y, z; }; struct T { struct S f[5]; unsigned h; }; void foo (void); void bar (struct T *t) { for (int i = 0; i < t->h; i++) { struct S *s = &t->f[i]; /* { dg-bogus "array subscript 5 is above array bounds" } */ if (i <= 4) s->y = 1; s->z = 2; if (i) s->x = 3; } } I guess what is going on is that we thread the body, if (i > 4) { s->z = 2; goto do_x; } else { s->y = 1; s->z = 2; if (i) { do_x: s->x = 3; } } because if i > 4, we know we don't want to store s->y and know we don't need to check if i is non-zero further. Next evrp determines that the range of the i_4 index is [0, 5] for some reason rather than the [0, 4] for which it is well defined, perhaps because of the dead s_15 = &t_10(D)->f[i_4]; statement that nothing has DCEd yet or what, and everything goes wrong from that point, as evrp because of that folds the MEM <struct T> [(struct S *)t_10(D)].f[i_4].z = 2; statement done only for i_4 > 4 into MEM <struct T> [(struct S *)t_10(D)].f[5].z = 2; and later we warn on that very statement. Now, a question on the kernel side is obviously why when #define TG3_RSS_MAX_NUM_QS 4 #define TG3_IRQ_MAX_VECS_RSS (TG3_RSS_MAX_NUM_QS + 1) #define TG3_IRQ_MAX_VECS TG3_IRQ_MAX_VECS_RSS ... struct tg3_napi napi[TG3_IRQ_MAX_VECS]; it has the for (i = 0; i < tp->irq_max; i++) { struct tg3_napi *tnapi = &tp->napi[i]; tnapi->tp = tp; tnapi->tx_pending = TG3_DEF_TX_RING_PENDING; tnapi->int_mbox = intmbx; if (i <= 4) intmbx += 0x8; else intmbx += 0x4; rather than just doing intmbx == 0x8; always. That introduction of the dead code there confuses the warning. And on the ranger side why we have determined the [0, 5] range rather than [0, 4], whether it is related to inaccurate number of iterations estimation, or ranger using it incorrectly, ...
next prev parent reply other threads:[~2023-03-22 14:37 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-03-21 13:58 [Bug c/109233] New: warning: array subscript 5 is above array bounds of ‘struct tg3_napi[5]’ ubizjak at gmail dot com 2023-03-21 14:01 ` [Bug c/109233] " ubizjak at gmail dot com 2023-03-21 14:05 ` ubizjak at gmail dot com 2023-03-22 10:27 ` ubizjak at gmail dot com 2023-03-22 10:38 ` [Bug c/109233] warning: array subscript 5 is above array bounds of ‘struct tg3_napi[5]’ since r12-2591 jakub at gcc dot gnu.org 2023-03-22 10:40 ` [Bug c/109233] [12/13 Regression] " jakub at gcc dot gnu.org 2023-03-22 10:43 ` ubizjak at gmail dot com 2023-03-22 12:10 ` ubizjak at gmail dot com 2023-03-22 14:13 ` marxin at gcc dot gnu.org 2023-03-22 14:37 ` jakub at gcc dot gnu.org [this message] 2023-03-22 14:39 ` jakub at gcc dot gnu.org 2023-03-22 15:02 ` aldyh at gcc dot gnu.org 2023-03-22 17:16 ` amacleod at redhat dot com 2023-03-23 10:00 ` rguenth at gcc dot gnu.org 2023-03-27 6:13 ` ubizjak at gmail dot com 2023-05-08 12:26 ` [Bug c/109233] [12/13/14 " rguenth at gcc dot gnu.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-109233-4-1ZZZfxFFMV@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).