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


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

gcc optimization bug report


Dear EGCS team,

I prepared the example which compiled with optimization flag -O, -O2 
gives a wrong result.

/* C source start here.
   Name: EGCS Optimization Bug?   
*/
//________
int main()
{
 unsigned char A[4];
 unsigned char B[4];

 unsigned int *ip;

 A[0]=0x7f; A[1]=0x00; A[2]=0x00; A[3]=0x01;
 B[3]=0x01; B[2]=0x00; B[1]=0x00; B[0]=0x7f;

 printf("Arrays from the source code \n-->
 A[0]=0x7f; A[1]=0x00; A[2]=0x00; A[3]=0x01;
 B[3]=0x01; B[2]=0x00; B[1]=0x00; B[0]=0x7f;\n<--\n\n");

 ip = (unsigned int *)A;
 printf("Unsigned int(A)=0x%08x\n", *ip);

 ip = (unsigned int *)B;
 printf("Unsigned int(B)=0x%08x\n", *ip);

 return 0;
}          
//___________________________________         
/* The end of the code */


After compilation with optimization I have

bash-2.01$ /usr/egcs-1.1.2/bin/gcc  -O e.c
bash-2.01$ ./a.out
Arrays from the source code
-->
 A[0]=0x7f; A[1]=0x00; A[2]=0x00; A[3]=0x01;
 B[3]=0x01; B[2]=0x00; B[1]=0x00; B[0]=0x7f;
<--

Unsigned int(A)=0x0100007f
Unsigned int(B)=0x0000007f 


Without optimization

bash-2.01$ /usr/egcs-1.1.2/bin/gcc  e.c
bash-2.01$ ./a.out
Arrays from the source code
-->
 A[0]=0x7f; A[1]=0x00; A[2]=0x00; A[3]=0x01;
 B[3]=0x01; B[2]=0x00; B[1]=0x00; B[0]=0x7f;
<--

Unsigned int(A)=0x0100007f
Unsigned int(B)=0x0100007f    


I run Linux on pentium box
bash-2.01$ /usr/egcs-1.1.2/bin/gcc  -v
Reading specs from
/usr/egcs-1.1.2/lib/gcc-lib/i586-pc-linux-gnu/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release) 


How did I build the egcs compiler?
 mkdir egcs
 cd /scratch/egcs/egcs
 CFLAGS='-O2' CXXFLAGS='-02' ../egcs1.1b/configure --prefix=/usr

 the i586-pc-linux-gnu is chosen
 the gcc compiler (gcc version 2.7.2.3)

 make bootstrap 
 make install


That's all.
I hope it is my misunderstanding of something.
Thanks for you doing.
Good luck!

-- 
Mikhail N. Sazonov 	mailto: sazon@nu.jinr.ru

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