public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "f.heckenbach@fh-soft.de" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/103724] invalid warning: iteration 7 invokes undefined behavior Date: Wed, 15 Dec 2021 03:11:32 +0000 [thread overview] Message-ID: <bug-103724-4-WODysOlr3K@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-103724-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103724 Frank Heckenbach <f.heckenbach@fh-soft.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|warning |invalid warning: iteration | |7 invokes undefined | |behavior --- Comment #1 from Frank Heckenbach <f.heckenbach@fh-soft.de> --- % cat test.c int d = 0, b = 8, a[8][8]; int main () { for (int c = 0; c < 11; c++) { d = a[c >= b ? c - b : c][c + 1 >= b ? c + 1 - b : c + 1]; if (b && c) d = c; } } % gcc -O3 test.c test.c: In function 'main': test.c:7:32: warning: iteration 7 invokes undefined behavior [-Waggressive-loop-optimizations] 7 | d = a[c >= b ? c - b : c][c + 1 >= b ? c + 1 - b : c + 1]; | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test.c:5:3: note: within this loop 5 | for (int c = 0; c < 11; c++) | ^~~ Many things are strange about this warning: - First, I think it's invalid -- the "?:" ensures the array indexes are in bounds, all variables are initialized,so I don't see what would be UB. - It claims UB occurs on iteration 7, but the warning disappears when I change the loop condition to "c < 10" (which would also include iteration 7) - The "if" statement with both conditions and the assignment is necessary to trigger the warning, although it has no actual effect. - The warning seems to apply to the 2nd array index, but already disappears when I turn the first index into "0" without changing the 2nd one. - It disappears when I make all variables local or all global.
next prev parent reply other threads:[~2021-12-15 3:11 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-12-15 3:05 [Bug c/103724] New: warning f.heckenbach@fh-soft.de 2021-12-15 3:11 ` f.heckenbach@fh-soft.de [this message] 2021-12-18 9:08 ` [Bug tree-optimization/103724] [9/10/11/12 Regression] invalid warning: iteration 7 invokes undefined behavior pinskia at gcc dot gnu.org 2021-12-28 19:53 ` jakub at gcc dot gnu.org 2022-01-18 14:07 ` rguenth at gcc dot gnu.org 2022-01-20 3:34 ` f.heckenbach@fh-soft.de 2022-03-09 13:36 ` rguenth at gcc dot gnu.org 2022-03-09 15:22 ` f.heckenbach@fh-soft.de 2022-05-27 9:46 ` [Bug tree-optimization/103724] [10/11/12/13 " rguenth at gcc dot gnu.org 2022-06-28 10:47 ` jakub at gcc dot gnu.org 2022-12-20 13:31 ` rguenth at gcc dot gnu.org 2023-07-07 10:41 ` [Bug tree-optimization/103724] [11/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-103724-4-WODysOlr3K@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).