[comp.bugs.4bsd] more problems with the VAX PCC and unsigned constants

donn@utah-cs.UUCP (Donn Seeley) (11/13/86)

This was pointed out by Spencer Thomas when he was testing Kenneth
Ballou's bug report on constant conversions from unsigned types to
floating types...  The compiler performs all unsigned constant
comparisons as signed.  For example the following program incorrectly
prints '0':

	main()
	{
		printf("%d\n", (unsigned) 0xffffffff > 0);
		exit(0);
	}

The fix is in conval() in lib/mip/trees.c:

------------------------------------------------------------------------
*** /tmp/,RCSt1029210	Wed Nov 12 23:27:09 1986
--- trees.c	Mon Nov 10 09:22:34 1986
***************
*** 739,754 ****
  		p->tn.lval = p->tn.lval >= val;
  		break;
  	case ULT:
! 		p->tn.lval = (p->tn.lval-val)<0;
  		break;
  	case ULE:
! 		p->tn.lval = (p->tn.lval-val)<=0;
  		break;
- 	case UGE:
- 		p->tn.lval = (p->tn.lval-val)>=0;
- 		break;
  	case UGT:
! 		p->tn.lval = (p->tn.lval-val)>0;
  		break;
  	case EQ:
  		p->tn.lval = p->tn.lval == val;
--- 739,754 ----
  		p->tn.lval = p->tn.lval >= val;
  		break;
  	case ULT:
! 		p->tn.lval = p->tn.lval < (unsigned) val;
  		break;
  	case ULE:
! 		p->tn.lval = p->tn.lval <= (unsigned) val;
  		break;
  	case UGT:
! 		p->tn.lval = p->tn.lval > (unsigned) val;
! 		break;
! 	case UGE:
! 		p->tn.lval = p->tn.lval >= (unsigned) val;
  		break;
  	case EQ:
  		p->tn.lval = p->tn.lval == val;
------------------------------------------------------------------------

Don't ask me why anyone might have thought the old code would work,

Donn Seeley    University of Utah CS Dept    donn@utah-cs.arpa
40 46' 6"N 111 50' 34"W    (801) 581-5668    decvax!utah-cs!donn