cristy@eplrx7.uucp (John Cristy) (09/08/90)
Is this a legitimate compiler bug? This code: register u_char ch, ch1; register u_char *ptr, *ptr1; ptr1 = Raster; do { ch = ch1 = NEXTBYTE; while (ch--) *ptr1++ = NEXTBYTE; if ((Raster - ptr1) > filesize) error("%s: %s is a corrupt GIF file (unblock).\n", inf); } while(ch1); using this cc command: cc -systype bsd43 -I.. -I/usr/include/bsd43 -I/usr/include -O -c file.c produces this assembly code: # 346 ptr1 = Raster; lw $16, Raster la $18, $$194 li $19, 255 $65: .loc 2 348 # 347 do { # 348 ch = ch1 = NEXTBYTE; lbu $3, 0($8) addu $8, $8, 1 .loc 2 349 # 349 while (ch--) *ptr1++ = NEXTBYTE; addu $17, $3, -1 and $2, $17, 255 and $2, $2, 255 beq $3, 0, $67 $66: lbu $12, 0($8) sb $12, 0($16) addu $8, $8, 1 addu $16, $16, 1 move $3, $2 addu $2, $2, -1 and $2, $2, 255 and $2, $2, 255 bne $3, 0, $66 $67: .loc 2 350 # 350 if ((Raster - ptr1) > filesize) lw $24, Raster subu $15, $24, $16 ble $15, $20, $68 .loc 2 351 # 351 error("%s: %s is a corrupt GIF file (unblock).\n", inf); move $4, $18 move $5, $22 sw $8, 64($sp) .livereg 0xc00ff0e,0xfff jal error lw $8, 64($sp) $68: .loc 2 352 # 352 } while(ch1); .loc 2 352 bne $17, $19, $65 .loc 2 354 Incorrect code is generated. Register $19 should be 0 but instead has been initilized to 255 (li $19, 255). This causes the program to fail. Compiling without the systype option produces the correct code and changing the statement } while(ch1); to } while(ch1 > 0); fixes the problem. -- The UUCP Mailer