[mod.computers.gould] cc bug with short unsigned constants

parmelee@SYSTEMS.CS.CORNELL.EDU (Larry Parmelee) (11/22/85)

Index:	/usr/src/lib/ccom

Description:
	Unsigned short integer constants sometimes get sign extension, 
	when this is not desired.

Repeat-By:
	Compile the following little program, and run it.
	
------cut here------
main()
{
    int i, ij1, ij2;
    unsigned short int j;
 	
    i = 10;
    j = (unsigned short)(01<<15);

    ij1 = i + j ;				/* Line 9 */
    ij2 = i + (unsigned short)(01<<15) ; 	/* Line 10-- BUG!!! */

    printf("i=0x%x, j=0x%x,  ij1=0x%x,  ij2=0x%x \n",i,j,ij1,ij2);
}
------cut here------

	The output from the above is:

i=0xa, j=0x8000,  ij1=0x800a,  ij2=0xffff800a
	
	Line 9 produces the following code:  (No Bug)

--	line 9, file "main.c"
	movh	11w+LOC1[b2],r0
	andw	#0xffff,r0
	addw	8w+LOC1[b2],r0
	movw	r0,9w+LOC1[b2]

	Line 10 produces this--(BUG!!!: Note the missing "andw")

--	line 10, file "main.c"
	movh	#0x8000,r0
	addw	8w+LOC1[b2],r0
	movw	r0,10w+LOC1[b2]

	The operation (in the above, addition) does not seem to be significant;
	The same problem occurs with "or".

	-Larry Parmelee
	parmelee@gvax.cs.cornell.edu
	{allegra,ihnp4,decvax}!cornell!parmelee