[1441] in Athena Bugs

home help back first fref pref prev next nref lref last post

[scs@ADAM.PIKA.MIT.EDU: Re: bugs in shorts (sic) in vax pcc]

daemon@ATHENA.MIT.EDU (Joe Harrington)
Tue Nov 29 16:07:24 1988

Date: Tue, 29 Nov 88 16:06:17 EST
From: Joe Harrington <jh@SOL.MIT.EDU>
To: eichin@ATHENA.MIT.EDU, bugs@ATHENA.MIT.EDU
Cc: jh@ATHENA.MIT.EDU
Reply-To: jh@ATHENA.MIT.EDU

This is a followup from a bug with the vax C compiler discovered in
our lab.  The bug was that shorts cast to doubles sometimes produced
junk.  The bug exists in all athena vaxen running unix (5.5T, 6.0R) I
could get my hands on.  It did not occur on the rt (6.0B using "cc")
or under gcc.

Below is a response from Chris Torek about the problem.  Thanks go to
Steve Summit for helping me figure out the vax assembly.

% cat short_bug.c
#include <stdio.h>

/* This is a program to demonstrate in a very few lines how casting a double as
   short is not done properly on this computer, with this compiler (sol, cc) */

main()
{
double d = 1.234567;

        printf("(short) %f = %d\n", d, (short) d);

}
% short_bug
(short) 1.234567 = 2147418113


Date: Fri, 25 Nov 88 20:59:48 EST
From: scs@ADAM.PIKA.MIT.EDU (Steve Summit)
To: jh@ATHENA.MIT.EDU

From chris@mimsy.umd.edu Wed Nov 23 03:11:09 1988
Received: by ADAM.PIKA.MIT.EDU (5.45/4.7) id AA16339; Wed, 23 Nov 88 03:11:03 EST
Received: by mimsy.umd.edu (5.58/4.7)
	id AA18855; Wed, 23 Nov 88 03:10:58 EST
Date: Wed, 23 Nov 88 03:10:58 EST
From: Chris Torek <chris@mimsy.umd.edu>
Message-Id: <8811230810.AA18855@mimsy.umd.edu>
To: scs@ADAM.PIKA.MIT.EDU
Subject: Re:  bugs in shorts (sic) in vax pcc

This is fixed in 4.3tahoe: the compiler emits

	cvtdw	-8(fp),r0
	cvtwl	r0,-(sp)
	<printf>

and

	cvtdw	-8(fp),r0
	cvtwl	r0,r0
	cvtwl	-10(fp),r1
	cmpl	r0,r1
	jeql	Lxxx
	calls	$0,_oops

The latter is far from optimal---

	cvtdw	-8(fp),r0
	cmpw	r0,-10(fp)

would do the trick---but is at least correct.

Incidentally, the `cvtwl' instruction on the Tahoe does not actually
convert anything.  Apparently there were a number of related bugs in
pcc.tahoe.

Going over to okeeffe, it seems that the tahoe compiler gets it wrong
still, using the sequence

	ldd	-60(fp)
	cvtdl	-(sp)
	<printf>

and

	ldd	-60(fp)
	cvtdl	r0
	cvtwl	-62(fp),r1
	cmpl	r0,r1
	jeql	Lxxx
	callf	$4,_oops

which compares the extended version of `s' against the truncated-to-
int-but-not-to-short version of `d'.

home help back first fref pref prev next nref lref last post