public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "gccbugs at dima dot secretsauce.net" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/95635] New: -Warray-bounds falsely claims out-of-bounds access Date: Thu, 11 Jun 2020 08:06:28 +0000 [thread overview] Message-ID: <bug-95635-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95635 Bug ID: 95635 Summary: -Warray-bounds falsely claims out-of-bounds access Product: gcc Version: 10.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: gccbugs at dima dot secretsauce.net Target Milestone: --- Created attachment 48716 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48716&action=edit Bug demo Hi. I'm running gcc-10 from Debian: dima@shorty:~$ gcc-10 --version gcc-10 (Debian 10.1.0-3) 10.1.0 I'm building the attached source like this: gcc-10 -Warray-bounds -O2 -c -o /dev/null tst.c And I get this: tst.c: In function 'a': tst.c:12:27: warning: array subscript <unknown> is outside array bounds of 'int[0]' [-Warray-bounds] 12 | if(L[i] > 0 && arr[L[i]] ) | ~~~^~~~~~ tst.c:8:9: note: while referencing 'arr' 8 | int arr[0]; | ^~~ tst.c:12:27: warning: array subscript <unknown> is outside array bounds of 'int[0]' [-Warray-bounds] 12 | if(L[i] > 0 && arr[L[i]] ) | ~~~^~~~~~ tst.c:8:9: note: while referencing 'arr' 8 | int arr[0]; The array arr[] has 0 elements, and gcc is telling me I'm accessing outside of those bounds. But L[i]>0 is always false, so we'll never actually look at arr[anything]. gcc knows this most of the time. If I remove the -O2 or the b() call or lots of little unrelated-looking things, the issue goes away. Thanks.
next reply other threads:[~2020-06-11 8:06 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-11 8:06 gccbugs at dima dot secretsauce.net [this message] 2020-06-11 8:21 ` [Bug c/95635] " marxin at gcc dot gnu.org 2020-06-11 14:37 ` [Bug tree-optimization/95635] -Warray-bounds while iterating over an escaped constant local array msebor 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-95635-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).