https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119980

            Bug ID: 119980
           Summary: wrong aliasing decision with structure acces
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: uecker at gcc dot gnu.org
  Target Milestone: ---

In the following example, there seems to be an incorrect aliasing decision. The
function should return 2 but returns 1 (adapted from an example by John Payson)

#include <stdlib.h>
#include <stdio.h>

typedef struct foo { int x; } F;
typedef struct bar { int x; } B;

static int foo(void *p, int i, int j, int v)
{
    F *pp = p;
    pp[i] = (F){ v };
    return pp[j].x;
}

static int bar(void *p, int i, int j, int v)
{
    B *pp = p;
    pp[i] = (B){ v };
    return pp[j].x;
}

[[gnu::noinline]]
int test(void *fp, int i, int j, int k)
{
    foo(fp, i, j, 1);
    int s = bar(fp, j, k, 2);
 //   printf("%d", s);
    return foo(fp, k, i, s);
}

int main()
{
    void *fp = malloc(sizeof(F));
    if (!fp) return -1;
    return test(fp, 0, 0, 0);
}

Reply via email to