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]

Re: Miscompilation of tetex-1.0.6 by gcc-2.95 (some more info)


> It seems that with the -O2 option gcc simply forgets the i = i + 1 line:

Nice analysis. With that, it is possible to reduce this further :-)

#include <stdio.h>

int gfbyte ( void ) 
{
 return 0;
} 

int main( void ) 
{
 int i,j,k ;

 i = gfbyte();

 i = i + 1 ;

 if ( i == 0 ) 
     k = -0 ;
 else
     k = i + 0 ;

 printf("here is a bug: i=%d\n",i);/* should print 1 */

 k = 1 ;
 if ( k <= i)
     do 
	 j = gfbyte () ;
     while ( k++ < i ) ;

} 

With this test program, gcc 2.95 19990717 prints "0", on
i586-pc-linux-gnu. The problem apparently is that gcc finds out that
the conditional store to "k" is not needed; and then somehow assumes
that the increment of "i" can be removed, as well.

Regards,
Martin


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