[Bug tree-optimization/90662] strlen of a string in a vla plus offset not folded
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed May 29 19:56:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90662
--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
It doesn't help that the ADDR_EXPR is rendered as &*a.1_9[2] when it should be
&(*a.1_9)[2] because a.1_9 is a pointer to a char[n] array. With the
parenthesization the problem becomes more apparent (to me, anyway): the strlen
pass doesn't handle pointers to arrays:
$ cat a.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout a.c
typedef char A8[8];
void f (A8 *pa)
{
__builtin_strcpy (*pa, "12345");
if (__builtin_strlen (&(*pa)[2]) != 3) // not folded
__builtin_abort ();
}
;; Function f (f, funcdef_no=0, decl_uid=1907, cgraph_uid=1, symbol_order=0)
f (char[8] * pa)
{
char * _1;
long unsigned int _2;
<bb 2> [local count: 1073741824]:
__builtin_memcpy (pa_4(D), "12345", 6);
_1 = &*pa_4(D)[2];
_2 = __builtin_strlen (_1);
if (_2 != 3)
goto <bb 3>; [0.00%]
else
goto <bb 4>; [100.00%]
<bb 3> [count: 0]:
__builtin_abort ();
<bb 4> [local count: 1073741824]:
return;
}
More information about the Gcc-bugs
mailing list