http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50262
Bug #: 50262
Summary: PTA doesn't disambiguate locally allocated heap
objects from pointed to by arguments
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: [email protected]
ReportedBy: [email protected]
CC: [email protected]
char *r;
char
foo (char *p, int len)
{
char *q = __builtin_malloc (len);
*p = 1;
*q = 2;
r = q;
return *p;
}
doesn't optimize return *p; into return 1; even when *q store can't alias *p.
This matters e.g. for the string length optimization I'm working on.
Testcase for the latter is e.g.:
#include <string.h>
#include <stdlib.h>
char *
foo (char *p, char *r)
{
char *q = malloc (strlen (p) + strlen (r) + 64);
if (q == NULL) return NULL;
strcpy (q, p);
strcat (q, "/");
strcat (q, "abcde");
strcat (q, r);
strcat (q, "/");
return q;
}