[comp.sys.amiga.tech] Manx compiler bugs - aren't these special?

bmacintyre@watdragon.waterloo.edu (Blair MacIntyre) (03/07/89)

[eat this and choke]

I recently got my third compiler bug causing problems for me on this
one project, so I thought it was about time to summarize them and
post it.

Here is the output from the Manx C 3.6a of three bugs I have discovered:

-------
A) testing the wrong thing:
   ( I'm including every thing up to the bug for clarity )
-------
;
;_GLcode( x, y, z, w, wec )
;    double	    x, y, z;
	public	__GLcode
__GLcode:
	link	a5,#.2
	movem.l .3,-(sp)
;    register double w;
;    double	    wec[6];
;{
	move.l	32(a5),d4
;    short	    code = 0;
	clr.w	-2(a5)
;
;    if( (wec[0] = w+y) < 0.0 )
;	code |= 1;
	move.l	16(a5),d1
	move.l	d0,-(sp)            <-- what is it saving?  No one knows!
	move.l	d4,d0
	jsr	.Fadd#
	move.l	40(a5),a0
	move.l	d0,d1
	move.l	d1,(a0)
	move.l	(sp)+,d0            <-- whatever it was, that's what its
	jsr	.Ftst#			comparing against!
	bge	.4
	bset.b	#0,-1(a5)
;
.4

--------
B) so, I rewrote the routine, taking the assignment out of the if.
   Now I have a LUCAS board, so I compiled it for the 68881
   --> now, it's trashing a register variable
--------
;OutCode _GLcode1( x, y, z, w, wec )
;    Coord	    x, y, z;
	public	__GLcode1
__GLcode1:
	link	a5,#.8
	movem.l .9,-(sp)
	fmovem.x	.10,-(sp)
;    register Coord  w;
;    WindowEdgeCoord wec;
;{
	fmove.d 32(a5),fp4              <-- move w to fp4
;    OutCode	code = 0;
	clr.w	-2(a5)
;
;    wec[BOTTOM_PLANE] = w+y;
	move.l	40(a5),a0
	fadd.d	16(a5),fp4              <-- add y into w
	fmove.d fp4,(a0)
;    if( wec[BOTTOM_PLANE] < 0.0 )
;	code |= 1;
	move.l	40(a5),a0
	fmove.d (a0),fp0
	fbge	.11
	bset.b	#0,-1(a5)
;
;    wec[TOP_PLANE] = w-y;
.11
	move.l	40(a5),a0
	fsub.d	16(a5),fp4              <-- now, for the next use of w, it
	fmove.d fp4,8(a0)                   doesn't reinitialize it, giving
					    wec[TOP_PLANE] = w+y-y = w ... NO!
--------
C) On another note, here is the Manx compiler generating non-existant opcodes!
--------
;    register	valuea, valuep; 	    <-- missdeclared a var ... I wanted
						register double valuea, valuep;
;
;    [ insert other code here! ]
;
;    valuep = sqrt(valuep);
	move.w	d5,d0
	sqrt.w	d0			    <-- what the Heck is that?!
	fmove.w d0,fp0
	fintrz	fp0
	fmove.l fp0,d0
	move.w	d0,d5
;    valuea = sqrt(valuea);
	move.w	d4,d0
	sqrt.w	d0			    <-- and again!!!
	fmove.w d0,fp0
	fintrz	fp0
	fmove.l fp0,d0
	move.w	d0,d4
;
------
There you have it.  Straight from the horses mouth!

No, who was it that said they were selling the Lattice C 5.0?!? :-)

Blair
-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
= Blair MacIntyre, bmacintyre@watsol.{waterloo.edu, UWaterloo.ca}             =
= "Don't be mean ... remember, no matter where you go, there you are." BBanzai=
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=