Pascal Bug fix (really)

peter peter
Sat Oct 23 13:01:53 AEST 1982


    Okay, i admit it, the posted bug in the pascal compiler is a bug in
the pascal compiler.  I never tried the fix to /usr/src/cmd/pcc/local2.c,
but if people say it doesn't work, who am i to argue?  The problem is that
my first pass is not casting the righthandsides of double assignments before
issuing the assignment.  Most of the time the second pass handles this fine,
but for constants doesn't.  Here's a fix to /usr/src/cmd/pc0/stat.c:
basically pitch the entire switch on the class of the righthandside and
replace it.  The key lines are the conditional output of the SCONV, but i
had to clean up the #ifdef's and eliminate the undocumented fall through
cases to see where to put it.
			... peter

from the old stat.c, the end of routine asngop1()
(with a few lines of context to get you oriented):

  	if (incompat(p1, p, r[3])) {
  		cerror("Type of expression clashed with type of variable in assignment");
  		return (NIL);
  	}
< 	switch (classify(p)) {
< 		case TINT:
< 		case TBOOL:
< 		case TCHAR:
< 		case TSCAL:
< #			ifdef OBJ
< 			    rangechk(p, p1);
< #			endif OBJ
< #			ifdef PC
< 			    postcheck( p );
< #			endif PC
< 		case TDOUBLE:
< 		case TPTR:
< #			ifdef OBJ
< 			    gen(O_AS2, O_AS2, w, width(p1));
< #			endif OBJ
< #			ifdef PC
< 			    putop( P2ASSIGN , p2type( p ) );
< 			    putdot( filename , line );
< #			endif PC
< 			break;
< 		default:
< #			ifdef OBJ
< 			    put(2, O_AS, w);
< #			endif OBJ
< #			ifdef PC
< 			    putstrop( P2STASG , p2type( p )
< 					, lwidth( p ) , align( p ) );
< 			    putdot( filename , line );
< #			endif PC
< 	}
  	return (p);	/* Used by for statement */
  }

from the new .../stat.c (with the same context):

  	if (incompat(p1, p, r[3])) {
  		cerror("Type of expression clashed with type of variable in assignment");
  		return (NIL);
  	}
> #	ifdef OBJ
> 	    switch (classify(p)) {
> 		    case TINT:
> 		    case TBOOL:
> 		    case TCHAR:
> 		    case TSCAL:
> 			    rangechk(p, p1);
> 			    gen(O_AS2, O_AS2, w, width(p1));
> 			    break;
> 		    case TDOUBLE:
> 		    case TPTR:
> 			    gen(O_AS2, O_AS2, w, width(p1));
> 			    break;
> 		    default:
> 			    put(2, O_AS, w);
> 			    break;
> 	    }
> #	endif OBJ
> #	ifdef PC
> 	    switch (classify(p)) {
> 		    case TINT:
> 		    case TBOOL:
> 		    case TCHAR:
> 		    case TSCAL:
> 			    postcheck( p );
> 			    putop( P2ASSIGN , p2type( p ) );
> 			    putdot( filename , line );
> 			    break;
> 		    case TPTR:
> 			    putop( P2ASSIGN , p2type( p ) );
> 			    putdot( filename , line );
> 			    break;
> 		    case TDOUBLE:
> 			    if (isnta(p1,"d")) {
> 				putop( P2SCONV , P2DOUBLE );
> 			    }
> 			    putop( P2ASSIGN , p2type( p ) );
> 			    putdot( filename , line );
> 			    break;
> 		    default:
> 			    putstrop( P2STASG , p2type( p )
> 					, lwidth( p ) , align( p ) );
> 			    putdot( filename , line );
> 			    break;
> 	    }
> #	endif PC
  	return (p);	/* Used by for statement */
  }



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