optimization/7728: Invalid statement reordering gcc 3.2 -O2

ghouston@arglist.com ghouston@arglist.com
Mon Aug 26 11:26:00 GMT 2002


>Number:         7728
>Category:       optimization
>Synopsis:       Invalid statement reordering gcc 3.2 -O2
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Aug 26 11:26:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Gary Houston
>Release:        3.2
>Organization:
>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
>Description:
  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

>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;
}

>Fix:
   reduce optimization
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list