Bug in C optimiser

utzoo!decvax!harpo!floyd!cmcl2!philabs!mcvax!ukc!root44!jmc utzoo!decvax!harpo!floyd!cmcl2!philabs!mcvax!ukc!root44!jmc
Wed Mar 23 12:04:40 AEST 1983


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



More information about the Comp.lang.c mailing list