This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[egcs-19980608] Extremely serious comparison bug


The following code runs incorrectly and prints "FAILED!" when compiled
with -O, -O1, or -O2 on x86 Linux. The reason is this sequence of
instructions for the comparison:

	movb (%ebx),%al
	andb $111,%al
	cmpl $2,%eax		<---- This is wrong

/*----------------------------------------------------------------------------*/
struct fd
{
	unsigned char a;
	unsigned char b;
} f = { 5 };

struct fd *g() { return &f; }
int h() { return -1; }

int main(int c, char **v)
{
	extern int printf(char *, ...);
	struct fd *f = g();
	f->b = h();
	if (((f->a & 0x7f) & ~0x10) <= 2)
		printf("FAILED!\n");
	return 0;
}
/*----------------------------------------------------------------------------*/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]