[Bug tree-optimization/86428] strlen of const array initialized with a string of the same length not folded
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Jul 6 21:03:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86428
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2018-07-06
Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Another test case for the same limitation:
const char a[4] = "123";
const char b[4] = "123";
int f (void)
{
return __builtin_memcmp (a, b, 4); // folded
}
const char c[4] = "123\0"; // sizeof "123\0" == 5
int g (void)
{
return __builtin_memcmp (a, c, 4); // not folded
}
The solution seems simple: change the string_constant() function to avoid
considering as string constants the strings of the last form, i.e., those with
more initializers than fit in the array they're stored in).
More information about the Gcc-bugs
mailing list