Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/17/84; site hao.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!teddy!panda!talcott!harvard!seismo!hao!pag
From: pag@hao.UUCP (Peter Gross)
Newsgroups: net.bugs.4bsd
Subject: 4.2bsd C compiler generates incorrect code
Message-ID: <1327@hao.UUCP>
Date: Fri, 11-Jan-85 13:37:31 EST
Article-I.D.: hao.1327
Posted: Fri Jan 11 13:37:31 1985
Date-Received: Sun, 13-Jan-85 08:22:49 EST
Distribution: net
Organization: High Altitude Obs./NCAR, Boulder CO
Lines: 41

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