4.2bsd C compiler generates incorrect code

Peter Gross pag at hao.UUCP
Sat Jan 12 04:37:31 AEST 1985


Description:
	4.2bsd C compiler generates incorrect code for float/int compare.

Repeat-By:
	Compile and run the following program:
main()
{
	int i=0, y=10;
	float x[2];

	x[i] = 6.;
	if( x[i] <= y )
	    printf("No bug here.\n");
	else
	    printf("This should never print\n");
}

	Obvious wrong code is produced by the compiler, as indicated
	by this fragment of the assembly language produced:

L16:
	.double	0d6.00000000000000000000e+00
	.text
	movl	-4(fp),r0
	cvtdf	L16,-16(fp)[r0]
	movl	-4(fp),r0
	cvtld	-8(fp),r2
	cvtfd	-16(fp)[r0],r1
------>>cmpd	r1,r2<<--------- this is a no no!
	jgtr	L17
	.data	1

	The cmpd instruction should not be using adjacent registers!
	If the "float" declaration is changed to "double" in the C program,
	then the compiler produces correct code.
Fix:
	Unknown.  FYI, We have installed the bug fix (from rlgvax!guy) to
	src/lib/c2/c21.c dealing with improper conversions.

--peter gross
hao!pag



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