[Bug middle-end/50262] New: PTA doesn't disambiguate locally allocated heap objects from pointed to by arguments

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Sep 1 09:58:00 GMT 2011


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: unassigned@gcc.gnu.org
        ReportedBy: jakub@gcc.gnu.org
                CC: rguenth@gcc.gnu.org


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;
}



More information about the Gcc-bugs mailing list