Miscompilation of tetex-1.0.6 by gcc-2.95 (some more info)
Jeffrey A Law
law@cygnus.com
Mon Aug 2 02:25:00 GMT 1999
In message <199907230816.KAA03891@mira.isdn.cs.tu-berlin.de>you write:
> > 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.
Thanks. I've got a beat on this one. The new cfg code is not as careful
as it ought to be when handling an insn like:
(jump_insn 17 16 20 (parallel[
(set (pc)
(if_then_else (ne (reg/v:SI 3 %ebx)
(const_int -1 [0xffffffff]))
(label_ref 23)
(pc)))
(set (reg/v:SI 3 %ebx)
(plus:SI (reg/v:SI 3 %ebx)
(const_int 1 [0x1])))
] ) 360 {casesi-2} (insn_list 11 (nil))
(nil))
Where the next nonnote insn is the same label this insn will jump to. I need
to sleep, but I'm confident we'll get this one fixed for gcc-2.95.1.
jeff
More information about the Gcc-bugs
mailing list