Subject: Bug in egcs/as ?
To: None <tech-toolchain@netbsd.org>
From: None <Anders.Hjalmarsson@economics.gu.se>
List: tech-toolchain
Date: 09/27/1998 03:29:59
I am running NetBSD-current i386 on a PPro, and I think I have found
a bug in egcs or in as.
This is with the latest NetBSD in-tree egcs:
gcc version egcs-2.91.57 19980901 (egcs-1.1 release)

The program at the end of the message misbehaves when compiled as follows:

	cc -O -mcpu=pentiumpro -march=pentiumpro  min.c -o min
	./min 5 10
min(5,10) = 10

If <= is changed to < in mymin, the program works correctly.

Here is a line by line comparison of the different code:

_mymin:
	<=  version		< version
	pushl %ebp		pushl %ebp
	movl %esp,%ebp		movl %esp,%ebp
	movl 8(%ebp),%edx	movl 8(%ebp),%edx
	movl 12(%ebp),%eax	movl 12(%ebp),%eax

	cmpl %eax,%edx		cmpl %edx,%eax
	cmovbe %edx,%eax	cmova %edx,%eax

	movl %ebp,%esp		movl %ebp,%esp
	popl %ebp		popl %ebp
	ret			ret

Both of the above code-fragments seem correct ok to me.
Can anybody see anything wrong ?


#include <stdlib.h>
#include <stdio.h>

int mymin(int a, int b);

int main(int argc, char **argv)
{
	int a, b;

	if (argc != 3) {
		fprintf(stderr, "usage: min a b\n");
		return(1);
	}

	a = atoi(argv[1]);
	b = atoi(argv[2]);

	printf("min(%d,%d) = %d\n", a, b, mymin(a,b));
	return 0;
}

int mymin(int a, int b)
{
	return a <= b ? a : b;
}