This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Gcc builtin review: strdup
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Cc: Andrew Pinski <pinskia at gmail dot com>
- Date: Mon, 25 May 2015 14:04:32 +0200
- Subject: Gcc builtin review: strdup
- Authentication-results: sourceware.org; auth=none
- References: <20150525101505 dot GA11233 at domone> <20150525114545 dot GC11233 at domone>
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.