C compiler bug (better fix)

ado at elsie.UUCP ado at elsie.UUCP
Sun Feb 12 10:23:10 AEST 1984


Subject: 4.?bsd C compiler error (better fix)
Index:	.../pcc/local2.c in 4.?BSD

Description:
	The C compiler generates incorrect code in some cases.
	A fix posted earlier fixed the problem while degrading code in some
	cases; this fix avoids code degradation.
Repeat-By:
	Use the command
		cc -S test.c
	where test.c contains:
		test()
		{
			register struct {
				short	i;
				short	j;
			} * sp;
			while ((sp++)->i != 0);
		}
	and then look at the "test.s" file produced.  You'll see that the
	"while" loop generates this code:
		 L16:
			tstw	(r11)+
			jeql	L17
			jbr 	L16
	which only increments r11 by two (rather than four) each time through.
Fix:	This is the fix to the version distributed by Berkeley.

	ed - .../pcc/local2.c
	/ISPTR(p->in.left->in.type)/c
	#ifdef OLDVERSION
					if ( ISPTR(p->in.left->in.type) ) {
	#else
	/*
	** We want to look for a pointer to a pointer, rather than a pointer.
	*/
					if ( ISPTR(p->in.left->in.type) &&
					   ISPTR(DECREF(p->in.left->in.type))) {
	#endif OLDVERSION
	.
	w
	q
-- 
UUCP:	decvax!harpo!seismo!rlgvax!cvl!elsie!ado
DDD:	(301) 496-5688



More information about the Comp.bugs.4bsd.ucb-fixes mailing list