Bug 30724 - Wrong code from -O2 taking ptr=(struct *)&int_proc_parm on x86_64
Wrong code from -O2 taking ptr=(struct *)&int_proc_parm on x86_64
Status: RESOLVED DUPLICATE of bug 21920
Product: gcc
Classification: Unclassified
Component: c
: P3 major
: ---
Assigned To: Not yet assigned to anyone
Depends on:
  Show dependency treegraph
Reported: 2007-02-07 03:39 UTC by Karl Schendel
Modified: 2007-02-07 06:51 UTC (History)
10 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Karl Schendel 2007-02-07 03:39:06 UTC
gcc -v
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.1.0 --enable-ssp --disable-libssp --enable-java-awt=gtk --enable-gtk-cairo --disable-libjava-multilib --with-slibdir=/lib64 --with-system-zlib --enable-shared --enable-__cxa_atexit --enable-libstdcxx-allocator=new --without-system-libunwind --with-cpu=generic --host=x86_64-suse-linux
Thread model: posix
gcc version 4.1.0 (SUSE Linux)
Compile the following with cc -O2, gets wrong code.
If you use -fno-strict-aliasing or -fno-schedule-insns2 it works.
cc -O1 works.  cc -O1 -fstrict-aliaseing -fschedule-insns2 fails.
I might have prioritized this critical except I found the ref to
-fno-strict-aliasing in the 4.1.2rc1 thread...

/* -O2 compiles the fetch of lx_id->id_id before it stores
** external_lx_id into the stack:

        movzwl  6(%rsp), %eax   // oops, too soon
        movl    %edi, 4(%rsp)
        testw   %ax, %ax  //  tests garbage


typedef int LG_LXID;
typedef int i4;
typedef unsigned short u_i2;
typedef struct _LG_ID {
    u_i2 foo;
    u_i2 id_id;
} LG_ID;

LG_LXID             external_lx_id,
i4                  flag)
    LG_ID               *lx_id = (LG_ID*)&external_lx_id;

    if (lx_id->id_id == 0 || (i4)lx_id->id_id > flag)
Comment 1 Andrew Pinski 2007-02-07 06:51:53 UTC
If you use -fno-strict-aliasing and it works, that should tell you something right there really.

Anyways you are violating C/C++ aliasing rules, see PR 21920.

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