Gcc builtin review: strdup
Ondřej Bílka
neleai@seznam.cz
Mon May 25 17:52:00 GMT 2015
Again there is missed optimization. Consider
int bar()
{
return strdup("xyz");
}
This could be clearly expanded to
int bar()
{
char *c = malloc (strlen ("xyz") + 1);
memcpy (c, "xyz", strlen ("xyz") + 1);
}
One of consequences of this missed optimization is that in
int bar()
{
char *c = strdup("xyz");
return c[1];
}
gcc cannot determine that c[1] is y while it can in memcpy case.
More information about the Libc-alpha
mailing list