public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/95794] New: strnlen of a constant string plus variable offset not folded when bound exceeds size
@ 2020-06-20 23:19 msebor at gcc dot gnu.org
2021-12-22 10:14 ` [Bug tree-optimization/95794] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-06-20 23:19 UTC (permalink / raw)
To: gcc-bugs
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;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug tree-optimization/95794] strnlen of a constant string plus variable offset not folded when bound exceeds size
2020-06-20 23:19 [Bug middle-end/95794] New: strnlen of a constant string plus variable offset not folded when bound exceeds size msebor at gcc dot gnu.org
@ 2021-12-22 10:14 ` pinskia at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-22 10:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95794
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Component|middle-end |tree-optimization
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-22 10:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-20 23:19 [Bug middle-end/95794] New: strnlen of a constant string plus variable offset not folded when bound exceeds size msebor at gcc dot gnu.org
2021-12-22 10:14 ` [Bug tree-optimization/95794] " pinskia at gcc dot gnu.org
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).