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/95794] New: strnlen of a constant string plus variable offset not folded when bound exceeds size Date: Sat, 20 Jun 2020 23:19:46 +0000 [thread overview] Message-ID: <bug-95794-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95794 Bug ID: 95794 Summary: strnlen of a constant string plus variable offset not folded when bound exceeds size Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- GCC folds comparisons of the results of calls to strlen with constant strings and variable offsets but it doesn't do the same for the equivalent strnlen with a bound in excess of the string size (strnlen with a bound greater than the string length are equivalent to strlen with the same argument). $ cat z.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout z.c const char a[] = "12345"; void f (int i) { if (__builtin_strlen (&a[i]) > 5) // folded to false __builtin_abort (); } void g (int i) { if (__builtin_strnlen (&a[i], 7) > 5) // not folded __builtin_abort (); } ;; Function f (f, funcdef_no=0, decl_uid=1931, cgraph_uid=1, symbol_order=1) f (int i) { <bb 2> [local count: 1073741824]: return; } ;; Function g (g, funcdef_no=1, decl_uid=1934, cgraph_uid=2, symbol_order=2) g (int i) { const char * _1; long unsigned int _2; sizetype _6; <bb 2> [local count: 1073741824]: _6 = (sizetype) i_3(D); _1 = &a + _6; _2 = __builtin_strnlen (_1, 7); if (_2 > 5) goto <bb 3>; [0.00%] else goto <bb 4>; [100.00%] <bb 3> [count: 0]: __builtin_abort (); <bb 4> [local count: 1073741824]: return; }
next reply other threads:[~2020-06-20 23:19 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-20 23:19 msebor at gcc dot gnu.org [this message] 2021-12-22 10:14 ` [Bug tree-optimization/95794] " pinskia 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-95794-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).