matsc@sics.se (Mats Carlsson) (03/23/89)
Enclosed is a typescript of a program giving incorrect results when
compiled with -O. The problem has to do with Boolean operations and
seems to be machine-independent; it manifests itself on Sun-3 (SunOS
4.0), Sun-4 (SunOS 4.0), Sequent Symmetry (DYNIX(R) V3.0.12 NFS).
skarabe>gcc -version
gcc version 1.34
skarabe>gcc -o bug bug.c
skarabe>bug
expected = 0x12, result = 0x12
expected = 0x7, result = 0x7
skarabe>gcc -O -o bug bug.c
expected = 0x12, result = 0x2
expected = 0x7, result = 0x17
skarabe>cat bug.c
#include <stdio.h>
/* AND all bits but 0x10, which is OR:ed */
orand(x,y)
unsigned long x,y;
{
return ((x^0x10)&(y^0x10))^0x10;
}
/* OR all bits but 0x10, which is AND:ed */
andor(x,y)
unsigned long x,y;
{
return ((x^0x10)|(y^0x10))^0x10;
}
main()
{
unsigned long x = 0x13;
unsigned long y = 0x06;
printf("expected = 0x%x, result = 0x%x\n", 0x12, orand(x,y));
printf("expected = 0x%x, result = 0x%x\n", 0x07, andor(x,y));
}
--
Mats Carlsson
SICS, PO Box 1263, S-164 28 KISTA, Sweden
Internet: matsc@sics.se EAN: matsc@sics.sunet
Phone: +46 8 7521543 Fax: +46 8 7517230