public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/97429] New: missing -Warray-bounds indexing past the end of a pointer to array Date: Wed, 14 Oct 2020 20:41:35 +0000 [thread overview] Message-ID: <bug-97429-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97429 Bug ID: 97429 Summary: missing -Warray-bounds indexing past the end of a pointer to array Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The out of bounds index in fa(), ga(), and fp() is diagnosed as expected by -Warray-bounds but the same bug in gp() is not. They all should be. $ cat xx.c && gcc -O2 -S -Wall xx.c int fa (int a[3][5]) { return a[3][5]; // warning (good) } int ga (int a[3][5]) { int *p = &a[0][0]; return p[15]; // warning (good) } int fp (int (*pa)[3][5]) { return (*pa)[3][5]; // warning (good) } int gp (int (*pa)[3][5]) { int *p = &(*pa)[0][0]; // missing warning return p[15]; } xx.c: In function ‘fa’: xx.c:3:14: warning: array subscript 5 is above array bounds of ‘int[5]’ [-Warray-bounds] 3 | return a[3][5]; // warning (good) | ~~~~^~~ xx.c:1:13: note: while referencing ‘a’ 1 | int fa (int a[3][5]) | ~~~~^~~~~~~ xx.c: In function ‘ga’: xx.c:9:11: warning: array subscript 15 is outside array bounds of ‘int[3]’ [-Warray-bounds] 9 | return p[15]; // warning (good) | ~^~~~ xx.c:6:13: note: while referencing ‘a’ 6 | int ga (int a[3][5]) | ~~~~^~~~~~~ xx.c: In function ‘fp’: xx.c:15:18: warning: array subscript 5 is above array bounds of ‘int[5]’ [-Warray-bounds] 15 | return (*pa)[3][5]; // warning (good) | ~~~~~~~~^~~ xx.c:13:15: note: while referencing ‘pa’ 13 | int fp (int (*pa)[3][5]) | ~~~~~~^~~~~~~~~
reply other threads:[~2020-10-14 20:41 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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-97429-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).