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 tree-optimization/103724] [9/10/11/12 Regression] invalid warning: iteration 7 invokes undefined behavior Date: Tue, 28 Dec 2021 19:53:37 +0000 [thread overview] Message-ID: <bug-103724-4-rYCzFNef3P@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 Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Seems the reason we warn is that we first unswitch the loop because of the (useless) b != 0 test in the loop, and so end up with: if (b == 0) for (int c = 0; c < 11; c++) d = a[c][c + 1]; else 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; } (the c >= b and c + 1 >= b comparisons in the first loop can be simplified because of the [0, 11] range for c), and on the first loop it indeed would invoke UB in 7th iteration. So the warning although it isn't clear from it (and the compiler doesn't know either) is about that if b is 0, which is something the user loop tests for, then it invokes UB, otherwise it isn't known whether it does or doesn't. This is a general problem with middle-end warnings, after unswitching, jump threading and similar optimizations it is unclear what code has been specialized on something that really ever happens in the code at runtime and what is dead.
next prev parent reply other threads:[~2021-12-28 19:53 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 ` [Bug c/103724] invalid warning: iteration 7 invokes undefined behavior f.heckenbach@fh-soft.de 2021-12-18 9:08 ` [Bug tree-optimization/103724] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org 2021-12-28 19:53 ` jakub at gcc dot gnu.org [this message] 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-rYCzFNef3P@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).