4.?BSD C fails to optimize a function's last expression (with fix?)

M.J.Shannon mjs at sfmag.UUCP
Sun Sep 15 23:33:29 AEST 1985


> Index:		src/lib/pcc/code.c Fix
> 
> Description:
> 	The 4.?BSD C compiler and optimizer can fail to produce optimized
> 	code for expressions that appear just before a value-free "return".
> 
> Fix:
> 	The fix involves changing two files.  As usual, the trade secret status
> 	of the code involved precludes a clearer posting.  The idea was
> 	suggested by umcp-cs!chris.
> 
> 	Change the indicated line in "pcc/code.c":
> 
> 		#ifdef OLDVERSION
> 				printf( "	ret\n" );
> 		#else
> 				if ((retstat & RETVAL) == 0)
> 					printf("\tret\t# return;\n");
> 				else	printf("\tret\n");
> 		#endif
> 
> 	...and make this change to "c2/c21.c":
> 
> 		#ifdef OLDVERSION
> 				if (p->subop==RET || p->subop==RSB) {uses[0]=p; regs[0][0]= -1; break;}
> 		#else
> 				if (p->subop == RET || p->subop == RSB) {
> 					if (p->code == 0 ||
> 						!equstr(p->code, "# return;"))
> 							uses[0] = p;
> 					regs[0][0] = -1;
> 					break;
> 				}
> 		#endif
> 
> 	UUCP: ..decvax!seismo!elsie!ado    ARPA: elsie!ado at seismo.ARPA
> 	DEC, VAX and Elsie are Digital Equipment and Borden trademarks

You also have to deal with the case that the function may be returning a
double (which takes r0 & r1).  Once upon a time (in a galaxy far, far away)
I fixed this problem for the AT&T VAX compiler/optimizer.  I have no idea
of the current status of those fixes.  Oh, the return value may also be
a structure, but I don't recal the maximum size that will be returned in
registers.
-- 
	Marty Shannon
UUCP:	ihnp4!attunix!mjs
Phone:	+1 (201) 522 6063
Disclaimer: I speak for no one.



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