[net.lang.c] Bug in C optimiser

jmc (03/23/83)

Did anyone ever notice this bug? The C optimiser on Sys III/V7 PDP11, and I
think Sys III VAX loops with this program.

main()
{
	register int a;		/*  Doesnt have to be register */
	register int b;		/*  Ditto  */

	for (;;) {
		if (b) {
			while (a) ;	/*  More or less anything */
			b = 0;		/*  Must be a constant, failing 'if' */
		}
	}
}

The fix is in the routine 'redunbr' in the C optimiser which attempts to avoid
branching to a conditional branch which it knows the outcome of. Add the
condition '&& p->labno != p1->labno' to the condtion 'if (compare.....'.

Interesting - the program would loop infinately, so does the optimiser. Does
the optimiser know something that Turing didn't?

John Collins
	...!mcvax!ukc!root44!jmc
	...!edcaad!root44!jmc