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

            Bug ID: 115582
           Summary: [regression 15] wrong code when accessing members of
                    incompatible type structure
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tangyixuan at mail dot dlut.edu.cn
  Target Milestone: ---

Hi, I find GCC produces wrong code under optimizations when pointers point to
incompatible type structure but the member types are compatible.

Compiler Explorer: https://godbolt.org/z/jjY599Yfe

$ cat s.c

int printf(const char *, ...);
struct s {int x; } __attribute__((packed));
struct t {int x; };

void swap(struct s* p, struct t* q)
{
  p->x = q->x;
  q->x = p->x;
}
int main()
{    
  struct t a[2];
  a[0].x = 1234;
  a[1].x = 5678;
  swap ((struct s *)((char *)a + 1), a);
  printf("%d",a[0].x);
  return 0;
}

Reply via email to