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

            Bug ID: 68480
           Summary: strict-aliasing not respected
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: manjeetdahiya at gmail dot com
  Target Milestone: ---

When I compile following code with -O2 -m32 -S -fno-strict-aliasing
-fno-unrolling -fno-builtin. GCC seems to be not respecting
-fno-strict-aliasing. I don't encounter this issue in gcc-4.8.

struct list { int hd; struct list * tl; };

struct list * reverselist (struct list * l)
{
  struct list * r, * r2;
  for (r = NULL; l != NULL; l = l->tl) {
    r2 = mymalloc(sizeof(struct list));
    r2->hd = l->hd;
    r2->tl = r;
    r = r2;
  }
  return r;
}

The issue is that statement A precedes B. It is fine in gcc-4.8.4.

Assembly gcc-4.1.0:
    movl  (%ebx), %eax  # <variable>.hd, <variable>.hd
    movl  %esi, 4(%edx) # r, <variable>.tl
    movl  %edx, %esi  # D.3244, r
A:  movl  4(%ebx), %ebx # <variable>.tl, l
B:  movl  %eax, (%edx)  # <variable>.hd, <variable>.hd
    testl %ebx, %ebx  # l

Assembly gcc-4.8.4:
    movl  (%ebx), %edx  # l_16->hd, D.5537
    movl  %esi, 4(%eax) # r, r_7->tl
    movl  %edx, (%eax)  # D.5537, r_7->hd
    movl  4(%ebx), %ebx # l_16->tl, l
    testl %ebx, %ebx  # l

Reply via email to