gcc configuration:

Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-3ubuntu3'
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--enable-multiarch --enable-linker-build-id --with-system-zlib
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls
--enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc
--enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-3ubuntu3) 

The bug occurs with all gcc 4.x versions I tried (4.0.1 on OS X, 4.2.1 on OS X,
4.3.3 on OpenSolaris,
4.4.1 on Ubuntu 9.10) but NOT with gcc 3.4.3 on Solaris 10. I have reproduced
it on i386 and PPC platforms.

To reproduce, compile the code below.  The bug occurs in generating the code
for foo(). Without -O, the begin and end values are identical; with -O, they
are not.  I'm sorry if the code is a bit hard to read, it was compiled to C
from a different language.

Regards,
Felix Croes


# include <stdio.h>

typedef int Int;
typedef unsigned int Uint;

typedef char bool;
typedef struct _string_ string;
typedef struct _array_ array;
typedef struct _object_ object;
typedef struct _value_ value;
typedef struct _control_ control;
typedef struct _dataplane_ dataplane;
typedef struct _dataspace_ dataspace;
typedef struct _frame_ frame;
typedef unsigned short uindex;
typedef uindex sector;
typedef unsigned short ssizet;
typedef char eindex;

typedef struct _rlinfo_ {
    Int maxdepth;
    Int ticks;
    bool nodepth;
    bool noticks;
    struct _rlinfo_ *next;
} rlinfo;
struct _frame_ {
    frame *prev;
    uindex oindex;
    array *lwobj;
    control *ctrl;
    dataspace *data;
    control *p_ctrl;
    unsigned short p_index;
    unsigned short nargs;
    bool external;
    bool sos;
    uindex foffset;
    struct _dfuncdef_ *func;
    char *prog;
    char *pc;
    value *stack;
    value *sp;
    value *lip;
    value *argp;
    value *fp;
    Int depth;
    rlinfo *rlim;
    Int level;
    bool atomic;
};
struct _value_ {
    char type;
    bool modified;
    uindex oindex;
    union {
 Int number;
 Uint objcnt;
 string *string;
 array *array;
 value *lval;
    } u;
};

extern void i_push_value (frame*, value*);
extern void i_index (frame*);
extern void i_funcall (frame*, object*, array*, int, int, int);

void foo(f)
register frame *f;
{
register Int ivar3 = 0;
register Int ivar10 = 1;
register Int ivar11 = 2;

(ivar11 |= (((i_push_value(f, (f->fp - 1)),
(--f->sp)->type = 0x01, f->sp->u.number = ((Int) 0x1L), i_index(f),
(--f->sp)->type = 0x01, f->sp->u.number = ((Int) 0x8L), kf_and(f),
(f->sp++)->u.number) ? ((Int) 0x1L) : ((Int) 0x0L)) | (((--f->sp)->type = 0x01,
f->sp->u.number = ivar10,
(f->argp + 3)->u.number = ivar3,
i_funcall(f, (object *) ((void *)0), (array *) ((void *)0), 0, 5 , 1),
(f->sp++)->u.number) ? ((Int) 0x4L) : ((Int) 0x0L))));
}

void i_push_value(f, v)
frame *f;
value *v;
{
    --f->sp;
}

void i_index(f)
frame *f;
{
    f->sp++;
}

int kf_and(f)
frame *f;
{
    f->sp++;
}

void i_funcall(f, obj, arr, a, b, c)
frame *f;
object *obj;
array *arr;
int a, b, c;
{
}

main()
{
    frame f;
    value stack[100];

    f.sp = f.argp = stack + 50;
    printf("begin %08x\n", f.sp);
    foo(&f);
    printf("end %08x\n", f.sp);
}


-- 
           Summary: gcc -O code generation error
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gccbug at dworkin dot nl
 GCC build triplet: Linux ubuntu 2.6.32-16-generic #25-Ubuntu SMP Tue Mar 9
                    16:33:52
  GCC host triplet: Linux ubuntu 2.6.32-16-generic #25-Ubuntu SMP Tue Mar 9
                    16:33:52
GCC target triplet: Linux ubuntu 2.6.32-16-generic #25-Ubuntu SMP Tue Mar 9
                    16:33:52


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

Reply via email to