[comp.sys.mac.programmer] Bug in LSC 3.0

henriks@nada.kth.se (Henrik Syk) (01/26/89)

There seems to be a bug in LSC 3.0p2. The compiler generates erraneous
code in the following situation: a function call with at least two 
parameters, the first which is another function call and the second 
which is a compound boolean expression.

The first parameter is computed by calling the function and its result
should be stored in a temporary local variable (-4(a6) in the example below).
If only the first part of the boolean expression is evaluated 
(as in "false && ....) this will not happen and the temporary variable
will contain garbage which is pushed onto the stack.

Is there another version available without this bug? (it is a bug or ...)


test()
{
	.
	.
	.
	test2( FrontWindow(), false && TickCount() > 1000 );
}

test2(wp, bool)
WindowPtr wp;
Boolean bool;
{
	/* wp != FrontWindow here !!!!, wp == garbage! */
}


  	 TEST
     	+0044  038EFC    *CLR.L      -(A7)
     	+0046  038EFE     _FrontWindow
     	+0048  038F00     MOVEA.L    (A7)+,A0      ; FrontWindow in A0 here
     --	+004A  038F02     BRA.S      TEST+005E
    |	+004C  038F04     CLR.L      -(A7)
    |	+004E  038F06     MOVE.L     A0,-$0004(A6) ; never executed !!
    |	+0052  038F0A     _TickCount
    |	+0054  038F0C     MOVE.L     (A7)+,D0
    |	+0056  038F0E     CMPI.L     #$000003E8,D0
    |	+005C  038F14     BGT.S      TEST+0062
     ->	+005E  038F16     MOVEQ      #$00,D0          ; move false to D0
     --	+0060  038F18     BRA.S      TEST+0064
    |	+0062  038F1A     MOVEQ      #$01,D0
     ->	+0064  038F1C     MOVE.W     D0,-(A7)         ; push false
     	+0066  038F1E     MOVE.L     -$0004(A6),-(A7) ; push garbage
 ------	+006A  038F22     JSR        TEST2+0000       ; and jump
|    	+006E  038F26     ADDQ.L     #$6,A7
|    	+0070  038F28     UNLK       A6
|    	+0072  038F2A     RTS
|
 --> TEST2
     	+0000  038F34     LINK       A6,#$0000
     	+0004  038F38     UNLK       A6
     	+0006  038F3A     RTS


*******************************************************************************
Henrik Syk                                    | henriks@nada.kth.se
School of Computer Science and Engineering    | 
Royal Institute of Technology                 | Vitalisv. 3
Stockholm                                     | S-112 55  STOCKHOLM
Sweden                                        | (8) - 56 13 95
*******************************************************************************