Bug 68480 - -fno-strict-aliasing not respected
Summary: -fno-strict-aliasing not respected
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-22 08:38 UTC by Manjeet Dahiya
Modified: 2015-11-23 05:35 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Manjeet Dahiya 2015-11-22 08:38:41 UTC
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
Comment 1 Andreas Schwab 2015-11-22 09:31:54 UTC
Did you mean gcc-5.1.0?
Comment 2 Manjeet Dahiya 2015-11-23 02:31:39 UTC
(In reply to Andreas Schwab from comment #1)
> Did you mean gcc-5.1.0?

No. It is for gcc-4.1.0 :) We were checking for equivalence of code generated across different versions and found this bug. We saw that it is possible to file bug reports for earlier versions so we filed it.
Comment 3 Manjeet Dahiya 2015-11-23 05:34:18 UTC
(In reply to Manjeet Dahiya from comment #2)
> (In reply to Andreas Schwab from comment #1)
> > Did you mean gcc-5.1.0?
> 
> No. It is for gcc-4.1.0 :) We were checking for equivalence of code
> generated across different versions and found this bug. We saw that it is
> possible to file bug reports for earlier versions so we filed it.

The reason we tested gcc-4.1.0 was that it is still being used for development of some of our tools.
Comment 4 Andrew Pinski 2015-11-23 05:35:50 UTC
4.1 is no longer support and has not been for over 5 years now.  Closing as won't fix.

There was some known issues in pre GCC 4.7 where aliasing was broken (there are a few bug reports already closed about it).