[15245] in Athena Bugs
SGI compiler bug
daemon@ATHENA.MIT.EDU (Mike Barker)
Thu Jul 10 16:24:33 1997
To: miked@MIT.EDU
Cc: bugs@MIT.EDU
Date: Thu, 10 Jul 1997 16:24:30 EDT
From: Mike Barker <mbarker@MIT.EDU>
This one should go into the SGI system.
Thanks
Mike
------- Forwarded Message
Received: from SOUTH-STATION-ANNEX.MIT.EDU by po8.MIT.EDU (5.61/4.7) id AA23277; Thu, 10 Jul 97 04:50:45 EDT
Received: from THE-LIGHT-FANTASTIC.MIT.EDU by MIT.EDU with SMTP
id AA00258; Thu, 10 Jul 97 04:50:43 EDT
Received: (from ghudson@localhost) by the-light-fantastic.MIT.EDU (8.6.12/8.6.12) id EAA14869; Thu, 10 Jul 1997 04:50:41 -0400
Date: Thu, 10 Jul 1997 04:50:41 -0400
Message-Id: <199707100850.EAA14869@the-light-fantastic.MIT.EDU>
From: Greg Hudson <ghudson@MIT.EDU>
To: bugs@MIT.EDU
Subject: SGI compiler bug
With optimization turned on, the IRIX 5.3 and 6.2 native compilers do
not properly convert a signed character contained within a promoted
argument variable to an unsigned character. The following test
program illustrates the bug:
#include <stdio.h>
void foo(int);
void foo(value)
char value;
{
if ((unsigned char) value == 255)
printf("Passed.\n");
else
printf("Failed.\n");
}
int main()
{
foo(255);
return 0;
}
With optimization turned off, the compiler does things the slow,
simple way, storing the argument ($4) into its slot on the stack (at
offset 32 from the stack pointer) and then loads the low-order byte
into $14:
sw $4, 32($sp)
lbu $14, 35($sp)
bne $14, 255, $32
With optimization turned on, the compiler decides to save a memory
access by doing the conversion inline, shifting the $4 value left 24
bits and then right again to get the low-order byte. Unfortunately,
it does an arithmetic right shift, extending the sign bit of the
low-order byte across the word so that you get -1 instead of 255:
sw $4, 32($sp)
sll $14, $4, 24
move $4, $14
sra $15, $4, 24
move $4, $15
bne $4, 255, $32
------- End of Forwarded Message