>Submitter-Id:  net
>Originator:    Konstantin Kivi
>Organization:  
>Confidential:  no
>Synopsis: wrong code generated with -O 
>Severity:      serious
>Priority:       medium 
>Category:      optimization
>Class:         wrong-code 
>Release:       3.0.4 (Debian testing/unstable)
>Environment:
System: Linux konst 2.4.20 #4 SMP ðÎÄ óÅÎ 22 18:41:18 MSD 2003 i686 unknown
Architecture: i686

        
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: ../src/configure -v 
--enable-languages=c,c++,java,f77,proto,objc --prefix=/usr 
--infodir=/share/info --mandir=/share/man --enable-shared --with-gnu-as 
--with-gnu-ld --with-system-zlib --enable-long-long --enable-nls 
--without-included-gettext --disable-checking --enable-threads=posix 
--enable-java-gc=boehm --with-cpp-install-dir=bin --enable-objc-gc i386-linux




>Description:
    in the example below gcc generate incorrect code in optimization mode

>How-To-Repeat:

Script started on Fri May 14 15:57:37 2004
[EMAIL PROTECTED]://.../Bug>cat bbug.c

struct a  {
    char t[2];
    int b;
} ;
struct aa  {
    char t[2];
} ;



int main()
{
    struct a A;
    struct aa AA;

    A.t[0]=0xFF;
    A.t[1]=0xF9;
    

    if((unsigned char )A.t[0]==0xFF && 
            (unsigned char)A.t[1]==0xF9  ) {
        puts("A Ok");
    }
    AA.t[0]=0xFF;
    AA.t[1]=0xF9;

    if((unsigned char )AA.t[0]==0xFF && 
            (unsigned char)AA.t[1]==0xF9  ) {
        puts("AA Ok");
    }
 return 0;   
}
[EMAIL PROTECTED]://.../Bug>cat makefile
.PHONY: good bad all
all: good bad
good:
        gcc -Wall bbug.c -o good_prog
bad:
        gcc -Wall -O bbug.c -o bad_prog
[EMAIL PROTECTED]://.../Bug>make
gcc -Wall bbug.c -o good_prog
bbug.c: In function `main':
bbug.c:23: warning: implicit declaration of function `puts'
gcc -Wall -O bbug.c -o bad_prog
bbug.c: In function `main':
bbug.c:22: warning: comparison is always 0
bbug.c:23: warning: implicit declaration of function `puts'
[EMAIL PROTECTED]://.../Bug>./good_prog
A Ok
AA Ok
[EMAIL PROTECTED]://.../Bug>./bad_prog
AA Ok
[EMAIL PROTECTED]://.../Bug>gcc -v
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
gcc version 2.95.4 20011002 (Debian prerelease)
[EMAIL PROTECTED]://.../Bug>exit

Script done on Fri May 14 15:58:25 2004


Script started on Fri May 14 16:03:25 2004
[EMAIL PROTECTED]://.../konst>ssh tnuma
DYNIX/ptx(R) V4.5.3 #4 (root): Sat Jun 21 14:39:42 MSD 2003
Copyright 1988 - 2001 Sequent Computer Systems, Inc.
Patents No. 5,185,861; 5,261,053; 5,442,758; 5,608,893; 5,655,122; 5,727,209

No mail.
DYNIX/ptx(R) V4.5.3 #4 (root): Sat Jun 21 14:39:42 MSD 2003
Copyright 1988 - 2001 Sequent Computer Systems, Inc.
Patents No. 5,185,861; 5,261,053; 5,442,758; 5,608,893; 5,655,122; 5,727,209

[EMAIL PROTECTED]://...konst>cd Bug
[EMAIL PROTECTED]://...Bug>make
        gcc -Wall bbug.c -o good_prog
bbug.c: In function `main':
bbug.c:23: warning: implicit declaration of function `puts'
        gcc -Wall -O bbug.c -o bad_prog
bbug.c: In function `main':
bbug.c:22: warning: comparison is always 0
bbug.c:23: warning: implicit declaration of function `puts'
[EMAIL PROTECTED]://...Bug>./good_prog
A Ok
AA Ok
[EMAIL PROTECTED]://...Bug>./bad_prog
AA Ok
[EMAIL PROTECTED]://...Bug>gcc -v
Reading specs from /usr/local/lib/gcc-lib/i386-sequent-sysv4/3.3.2/specs
Configured with: ../gcc-3.3.2/configure --with-gnu-as --with-gas --with-gnu-ld 
--enable-languages=c,c++ --with-stubs
Thread model: single
gcc version 3.3.2
[EMAIL PROTECTED]://...Bug>exit
logout
Connection to tnuma closed.
Script done on Fri May 14 16:04:10 2004
>Fix:
 do not use -O


Reply via email to