[comp.sys.mac.programmer] MPW C bug

west@turing.toronto.edu (Tom West) (01/22/91)

  I have a problem with both MPW C compiler 3.1 and 3.2b3q101.  Both will
occasionally allocate vast amounts of space for structures that should
only take a few bytes.  An example of a program fragment is provided 
below.  (I tried to cut it down to a small complete program, but the 
problem kept disappearing.)  Does anyone know anything about this bug?

  Below, in the program fragment, kindToAssignOpOffset is a static array
19 bytes long.  It's allocated over 23k!!  Likewise, kindToAssignInverted
should be 38 bytes and is likewise allocated 23 or so k.  I've included the
code fragment where they're declared, the fragment from the MAP file 
produced by the link, and fragments from the DUMPOBJ file where they
are mentioned.  It's clear from line 60952 and line 61032 of the DUMPOBJ file
that the C compiler is what is messing up.

  Can anybody help?  i.e. confirm the bug exists, suggest a work around, etc.

  P.S.  Apologies for the code, it is, as might be guessed, computer generated.

						Tom West
						tomwest@gpu.utcs.toronto.edu
						west@turing.toronto.edu
						west@hsa.on.ca


The C Code:
-----------

typedef	short	Compile_Opcode;
...
void Compile_Coder_Assign (op, tTarget, tSource)
Compile_Tok	op;
struct Compile_TyDef	*tTarget;
struct Compile_TyDef	*tSource;
{
    register struct Compile_TyDef	*t;
    register unsigned short	realKind;
    typedef	Compile_Opcode	__x2504[19]; 
    static __x2504	kindToAssign =        
	{40, 51, 39, 52, 52, 52, 40, 50, 48, 48,
	48, 40, 107, 49, 107, 107, 107, 107, 40};
    typedef	char	__x2505[19];
    static __x2505	kindToAssignOpOffset =		<-- Offending Structure
	{0, 2, -1, -2, -2, -2, 0, 1, -1, -1,
	-1, 3, -1, -1, -1, -1, -1, -1, 1};
	...
}
...
void Compile_Coder_AssignInverted (ty)
struct Compile_TyDef	*ty;
{
    register struct Compile_TyDef	*t;
    typedef	Compile_Opcode	__x2515[19];
    static __x2515	kindToAssignInverted = 		<-- Offending Structure
	{42, 46, 41, 47, 47, 107, 42, 45, 43, 43,
	43, 42, 107, 44, 107, 107, 107, 107, 42};
	...
}
...

Map File Produced When Linking:
-------------------------------

...
Segment "%GlobalData" size=$1778E
...
   GEOpcode                         -$16ABE(A5)  size=$0026  local   hasContents
   LEOpcode                         -$16A98(A5)  size=$0026  local   hasContents
   EQOpcode                         -$16A72(A5)  size=$0026  local   hasContents
   kindToAssignInverted             -$16A4C(A5)  size=$5C92  local   hasContents
						      ^^^^^
   kindToAssignOpOffset             -$10DBA(A5)  size=$5EA6  local   hasContents
						      ^^^^^
   kindToAssign                     -$AF14(A5)  size=$0042  local   hasContents
   kindToFetch                      -$AED2(A5)  size=$06C2  local   hasContents
...

DumpObj Output:
---------------

...
 10750:  Dictionary:          Flags $00 FirstId 8351
 10750:                  8351: kindToAssignOpOffset
 10777:  Pad         
...
 10834:  Dictionary:          Flags $80 (SymbolicIDs) FirstId 8353
 10834:                  8353: __x2505
 10848:  LocalID:             Flags $00 RecordSize=22 parentID=8333 FileID="coder.c"(1) FileOffset=42232
                              LocalID="kindToAssignOpOffset"(8351) Type="__x2505"(8353) FF:0 FileOffset=42232
                      Kind=(StorageClass=A5_Relative offsetSize=32bit) Offset(ID)="kindToAssignOpOffset"(51)

...
 11192:  Dictionary:          Flags $00 FirstId 8363
 11192:                  8363: kindToAssignInverted
 11219:  Pad    
...
 11276:  Dictionary:          Flags $80 (SymbolicIDs) FirstId 8365
 11276:                  8365: __x2515
 11290:  LocalID:             Flags $00 RecordSize=22 parentID=8357 FileID="coder.c"(1) FileOffset=43863
                              LocalID="kindToAssignInverted"(8363) Type="__x2515"(8365) FF:0 FileOffset=43863
                      Kind=(StorageClass=A5_Relative offsetSize=32bit) Offset(ID)="kindToAssignInverted"(54)
...
 37606:  Reference:           Flags=$90=(A5Relative 16BitPatch 16BitOffsets FromCode) 
                     Ref="kindToAssignOpOffset"(51)
                      000E

 37614:  Content:             Flags $08
 37614:  Contents offset $0000 size $0132
00000000: 4E56 FFFE      'NV..'            LINK       A6,#$FFFE
00000004: 48E7 0718      'H...'            MOVEM.L    D5-D7/A3/A4,-(A7)
00000008: 1A2E 000B      '....'            MOVE.B     $000B(A6),D5
0000000C: 47ED 0000      'G...'            LEA        kindToAssignOpOffset,A3 ; id: 51
00000010: 286E 000C      '(n..'            MOVEA.L    $000C(A6),A4
00000014: 700E           'p.'              MOVEQ      #$0E,D0
...
 38260:  Reference:           Flags=$90=(A5Relative 16BitPatch 16BitOffsets FromCode) 
                     Ref="kindToAssignInverted"(54)
                      0028

 38268:  Content:             Flags $08
 38268:  Contents offset $0000 size $00A8
00000000: 4E56 0000      'NV..'            LINK       A6,#$0000
00000004: 48E7 0118      'H...'            MOVEM.L    D7/A3/A4,-(A7)
00000008: 266E 0008      '&n..'            MOVEA.L    $0008(A6),A3
0000000C: 284B           '(K'              MOVEA.L    A3,A4
0000000E: 700E           'p.'              MOVEQ      #$0E,D0
00000010: B06C 0006      '.l..'            CMP.W      $0006(A4),D0
00000014: 660A           'f.'              BNE.S      *+$000C             ; 00000020
00000016: 2F0C           '/.'              MOVE.L     A4,-(A7)
00000018: 4EBA 0000      'N...'            JSR        Compile_Coder_UnOpaque ; id: 35
0000001C: 2840           '(@'              MOVEA.L    D0,A4
0000001E: 588F           'X.'              ADDQ.L     #$4,A7
00000020: 302C 0006      '0,..'            MOVE.W     $0006(A4),D0
00000024: D040           '.@'              ADD.W      D0,D0
00000026: 41ED 0000      'A...'            LEA        kindToAssignInverted,A0 ; id: 54
0000002A: 3E30 0000      '>0..'            MOVE.W     $00(A0,D0.W),D7
0000002E: 3007           '0.'              MOVE.W     D7,D0
00000030: 48C0           'H.'              EXT.L      D0
00000032: 2F00           '/.'              MOVE.L     D0,-(A7)
00000034: 4EBA 0000      'N...'            JSR        Compile_Coder_NoOperands ; id: 17
00000038: 7000           'p.'              MOVEQ      #$00,D0
0000003A: 3007           '0.'              MOVE.W     D7,D0
0000003C: 722B           'r+'              MOVEQ      #$2B,D1             ; '+'
0000003E: B280           '..'              CMP.L      D0,D1
00000040: 588F           'X.'              ADDQ.L     #$4,A7
00000042: 6610           'f.'              BNE.S      *+$0012             ; 00000054
00000044: 202B 0002      ' +..'            MOVE.L     $0002(A3),D0
00000048: E480           '..'              ASR.L      #$2,D0
0000004A: 2F00           '/.'              MOVE.L     D0,-(A7)
0000004C: 4EBA 0000      'N...'            JSR        Compile_Coder_AdditionalOffset ; id: 25
...
 60924:  Dictionary:          Flags $00 FirstId 54
 60924:                    54: kindToAssignInverted
 60951:  Pad         

 60952:  Module:              Flags=$01=(Local Data)  Module="kindToAssignInverted"(54) Size=23698

 60958:  Content:             Flags $09
 60958:  Contents offset $0000 size $0026
$000000: 002A 002E 0029 002F 002F 006B 002A 002D  '.*...)././.k.*.-'
$000010: 002B 002B 002B 002A 006B 002C 006B 006B  '.+.+.+.*.k.,.k.k'
$000020: 006B 006B 002A                          '.k.k.*'


 61004:  Dictionary:          Flags $00 FirstId 51
 61004:                    51: kindToAssignOpOffset
 61031:  Pad         

 61032:  Module:              Flags=$01=(Local Data)  Module="kindToAssignOpOffset"(51) Size=24230

 61038:  Content:             Flags $09
 61038:  Contents offset $0000 size $0013
$000000: 0002 FFFE FEFE 0001 FFFF FF03 FFFF FFFF  '................'
$000010: FFFF 0100                               '....'
...