This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug rtl-optimization/33450] New: Optimization with -O3 and -O2 producing bad code


I have tested this code with many version of GCC, three under Linux x86 PC and
one into x86 Mac OS X.
This bug appears with version 3.4.5 (Gentoo 3.4.5, ssp-3.4.5-1.0, pie-8.7.9),
in a Gentoo x86_64 Linux PC, and with Gcc 4.1.2 (Ubuntu 4.1.2-0ubuntu4) and
4.1.2 20061115 (prerelease) (Debian 4.1.1-21).
It doesn't appear in x86 Mac Os X 10.4 with "version 4.0.1 (Apple Computer,
Inc. build 5250)"

This very simple code show the gcc's bug.

#include <stdio.h> // for printf

struct ELT {
  int item;
} one_elt;


int main()
{ struct ELT *two_elt;
  long *src,*dst;


  two_elt = malloc(sizeof(struct ELT));


  src = (long *)&one_elt;
  dst = (long *)two_elt;

  dst[0] = src[0];

  two_elt->item = 27;

  malloc(2);

  printf("27 = %d\n",two_elt->item);
  return( 0);
}

When you compile with -O1 or -O0, we get "27=27", but when we compile with -O2
or -O3 switch, we get "27=0"
Gcc "forget" code's dependancy.


-- 
           Summary: Optimization with -O3 and -O2 producing bad code
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ontologiae at gmail dot com
 GCC build triplet: x86 and x86_64-linux-pc-gnu
  GCC host triplet: x86 and x86_64-linux-pc-gnu
GCC target triplet: x86 and x86_64-linux-pc-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33450


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]