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 middle-end/96900] [9/10/11 Regression] bogus -Warray-bounds on strlen with valid pointer obtained from just-past-the-end Date: Thu, 03 Sep 2020 23:37:05 +0000 [thread overview] Message-ID: <bug-96900-4-1biEY4HqCU@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-96900-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96900 Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |missed-optimization --- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> --- This is also a missed optimization opportunity. Another test case that shows both the bogus warning and the suboptimal codegen is the following. Because there is no explicit initializer for a.b, fold_nonarray_ctor_reference() returns a scalar zero, which again triggers the warning and prevents the strlen call from being folded. The optimization never worked in this case so that part is not a regression. $ cat z.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout z.c struct A { char n, a[4], b[4]; }; const struct A a = { }; int f (void) { const char *p = &a.b[2]; return __builtin_strlen (p - 2); } z.c: In function ‘f’: z.c:7:10: warning: offset ‘5’ outside bounds of constant string [-Warray-bounds] 7 | return __builtin_strlen (p - 2); | ^~~~~~~~~~~~~~~~~~~~~~~~ z.c:2:16: note: ‘a’ declared here 2 | const struct A a = { }; | ^ ;; Function f (f, funcdef_no=0, decl_uid=1935, cgraph_uid=1, symbol_order=1) f () { long unsigned int _1; int _3; <bb 2> [local count: 1073741824]: _1 = __builtin_strlen (&MEM <const char> [(void *)&a + 5B]); _3 = (int) _1; return _3; }
next prev parent reply other threads:[~2020-09-03 23:37 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-09-02 16:50 [Bug middle-end/96900] New: " msebor at gcc dot gnu.org 2020-09-02 16:51 ` [Bug middle-end/96900] [9/10/11 Regression] " msebor at gcc dot gnu.org 2020-09-02 18:57 ` msebor at gcc dot gnu.org 2020-09-03 6:15 ` rguenth at gcc dot gnu.org 2020-09-03 23:37 ` msebor at gcc dot gnu.org [this message] 2021-01-14 9:19 ` rguenth at gcc dot gnu.org 2021-02-14 0:26 ` msebor at gcc dot gnu.org 2021-06-01 8:18 ` [Bug middle-end/96900] [9/10/11/12 " rguenth at gcc dot gnu.org 2022-05-27 9:43 ` [Bug middle-end/96900] [10/11/12/13 " rguenth at gcc dot gnu.org 2022-06-28 10:41 ` jakub at gcc dot gnu.org 2023-07-07 10:38 ` [Bug middle-end/96900] [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-96900-4-1biEY4HqCU@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).