public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/107677] -Warray-bounds: unclear what exactly it's meant to detect Date: Tue, 29 Nov 2022 13:29:40 +0000 [thread overview] Message-ID: <bug-107677-4-2BYgflD8XF@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-107677-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107677 --- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> --- If you supply a runtime index or pointer offset GCC tries to constrain that value. If it can constrain the index or pointer offset such that the access would always be out of the bounds of an array that is accessed or offsetted then this is an "always out of bounds" access to the diagnostic. Consider int a[3]; if (n > 1) return a[n]; here we'd constrain n to be in the range [2, INT_MAX] and _not_ diagnose the a[n] reference (because '2' would be a valid index). That's done to not make imperfect range analysis cause diagnostics all over the place. The most common reason for false positives is instead code that's never executed at runtime but the intermediate language GCC works on allowed it to constrain an access enough. That's either a missed optimization in case GCC should have been able to see it's eliminatable dead code it warns on or "unfortunate" in that it cannot. Often the constraints GCC uses result from other optimizations that duplicate code. Confusing is how GCC tries to second-guess the actual array you are accessing when it just sees pointer arithmetic instead of clearly communicating the offsetting of a pointer.
prev parent reply other threads:[~2022-11-29 13:29 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-11-14 14:16 [Bug c++/107677] New: " carlosgalvezp at gmail dot com 2022-11-14 17:42 ` [Bug middle-end/107677] " mpolacek at gcc dot gnu.org 2022-11-14 18:50 ` carlosgalvezp at gmail dot com 2022-11-15 12:41 ` carlosgalvezp at gmail dot com 2022-11-15 12:51 ` pinskia at gcc dot gnu.org 2022-11-15 13:14 ` carlosgalvezp at gmail dot com 2022-11-29 13:29 ` rguenth at gcc dot gnu.org [this message]
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-107677-4-2BYgflD8XF@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).