nagle@well.sf.ca.us (John Nagle) (06/01/91)
ZORTECH C++ COMPILER DEFECT Product: Macintosh compiler Compiler version: V.2.1R1 Date: 31 MAY 91 Submitted by: John Nagle / 999 Woodland Avenue / Menlo Park, CA 94025 Incorrect code is generated for calls to Macintosh toolbox routines when the result is discarded with a cast to (void). The compiler does not reserve space for the return value in such cases. Recall that for Macintosh Pascal calling sequences, return values are placed on the stack. Example: short sink; sink = Alert(rUnimplementedFeature,nil); generates 0000004A: 554F SUBQ.W #$2,A7 0000004C: 3F3C 03F4 MOVE.W #$03F4,-(A7) 00000050: 7000 MOVEQ #$00,D0 00000052: 2F00 MOVE.L D0,-(A7) 00000054: A985 _Alert ; A985 00000056: 361F MOVE.W (A7)+,D3 which is right, but (void) Alert(rUnimplementedFeature,nil); generates 00000032: 3F3C 03F4 MOVE.W #$03F4,-(A7) 00000036: 7000 MOVEQ #$00,D0 00000038: 2F00 MOVE.L D0,-(A7) 0000003A: A985 _Alert without the stack adjustment for the 2-byte return value. This, of course, results in a corrupted stack and a machine crash. John Nagle