cc generated code bug

Arthur David Olson ado at elsie.UUCP
Wed Jul 10 08:26:44 AEST 1985


In article <486 at tjalk.UUCP>, cogito at tjalk.UUCP (Robbert van Renesse) writes:
> When right-shifting an unsigned variable, the compiler generates an
> EXTZV instruction. If the shift count exceeds 32, a reserved operand
> fault occurs and the program gets an illegal instruction signal, instead
> of giving a null result.

The problem goes beyond unsigned variables.  When right-shifting a
signed variable, the compiler generates an ASHL instruction, which takes
a byte as its shift count.  If the shift count's magnitude is too large,
things go awry, as compiling and running the following source shows:

	#include <stdio.h>

	main()
	{
		int	i;

		i = 5;
		printf("%d\n", i >> 257);
	}

As to whether the illegal instruction or the bogus answer is the bigger
problem. . .
--
Bugs is a Warner Brothers trademark.
CC is a Canadian Club trademark.
--
	UUCP: ..decvax!seismo!elsie!ado    ARPA: elsie!ado at seismo.ARPA
	DEC, VAX and Elsie are Digital Equipment and Borden trademarks



More information about the Comp.bugs.4bsd.ucb-fixes mailing list