[net.unix-wizards] Pascal Bug fix

coltoff (10/22/82)

The bug fix for the pascal compiler that was posted the other day
creates other problems, at least here at burdvax. It did wonders
for fixing the pascal bug but really messed up the C compiler( our
real, true love). The added code went in the C back end which
the pascal compiler called.

My hunch as to what the cause of the problem is that all the code
assumes that certain values are stored as a fixed number of bytes
and the fix changes this number. Now that is fine for getting rid
of the pascal bug but it appears as though some of the C functions
(e.g. getenv(), switch(), scanf() ) reject this. No compiler
errors are generated but the programs don't work right.

I strongly suggest that you not make this modification to your
compiler code. Just code around the bug and you'll live a lot longer.

Joel Coltoff
lime!burdvax!coltoff

ARPAVAX:peter (10/23/82)

    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 */
  }