Bug 7728 - Invalid statement reordering gcc 3.2 -O2
Invalid statement reordering gcc 3.2 -O2
Status: RESOLVED DUPLICATE of bug 21920
Product: gcc
Classification: Unclassified
Component: rtl-optimization
3.2
: P2 critical
: ---
Assigned To: Not yet assigned to anyone
: wrong-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2002-08-26 11:26 UTC by ghouston
Modified: 2005-06-05 09:52 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
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 ghouston 2002-08-26 11:26:00 UTC
  Output of program below, compiled with gcc -O:
154
153
153
153
153
153
9
64

  Output when compiled with gcc -O2:
0
0
0
0
153
153
9
64

Release:
3.2

Environment:
System: Linux x.localnet 2.4.18 #1 Sat Apr 6 12:54:37 BST 2002 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc-3.2/configure --prefix=/usr --enable-threads=posix --enable-shared

How-To-Repeat:
#include <stdlib.h>
#include <string.h>

typedef struct
{
  unsigned long * type;
  unsigned long * pad;
  double real;
} x_double;

void * make_z (double x)
{
  void *z = malloc (50);

  memset (z, 0, 50);
  ((unsigned long *) z) [2] = 0;
  ((x_double *) z)->real = x;
  return z;
}

main ()
{
  void *z = make_z (3.2);
  double d = ((x_double *) z)->real;
  int i;

  for (i = 0; i < sizeof (double); i++)
    {
      printf ("%d\n", ((unsigned char *) &d)[i]);
    }
  return 0;
}
Comment 1 ghouston 2002-08-26 11:26:00 UTC
Fix:
   reduce optimization
Comment 2 Richard Henderson 2002-10-02 13:43:24 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Not a bug.  This code violates type aliasing rules.
Comment 3 Andrew Pinski 2005-06-05 09:50:29 UTC
Reopening to ...
Comment 4 Andrew Pinski 2005-06-05 09:52:34 UTC
Mark as a dup of bug 21920.

*** This bug has been marked as a duplicate of 21920 ***