With the following testcase lowering memcpy to pointer assignment causes
wrong alias information to be generated.

struct Foo {
  int a;
  int b;
};
struct Node;
struct Node {
  struct Node *next;
};
struct Node *pool;
void grow (void)
{
  char *mem = __builtin_malloc (4096);
  struct Node *node = (struct Node *)mem;
  struct Foo *foo;
  __builtin_memcpy (&node->next, &pool, sizeof(struct Node*));
  pool = node;
} 
static inline void *alloc_one (void)
{ 
  struct Node *node = pool;
  __builtin_memcpy (&pool, &node->next, sizeof(struct Node*));
  return node;
}
static inline void dealloc_one (void *p)
{
  struct Node *node = p;
  __builtin_memcpy (&node->next, &pool, sizeof(struct Node*));
  pool = node;
}
int bar(void)
{
  grow();
  struct Foo* foo = alloc_one();
  foo->a = 0;
  foo->b = -1;
  dealloc_one (foo);
  return foo->a;
}

while we have in .optimized

<bb 2>:
  grow ();
  node = pool;
  D.1928 = node->next;
  pool = D.1928;
  foo = (struct Foo *) node;
  foo->a = 0;
  foo->b = -1;
  node = (struct Node *) foo;
  node->next = D.1928;
  pool = node;
  return foo->a;

asm generates:

bar:
.LFB5:
        subq    $8, %rsp
.LCFI1:
        call    grow
        movq    pool(%rip), %rax
        movl    $0, (%rax)
        movl    $-1, 4(%rax)
        xorl    %eax, %eax
        addq    $8, %rsp
        ret

which is wrong.


-- 
           Summary: [4.2 Regression] memcpy optimization causes wrong-code
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Keywords: wrong-code, alias
          Severity: blocker
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rguenth at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29272

Reply via email to