Subject: addendum to last C compiler patch Index: lib/ccom/c10.c 2.11BSD Description: The previous update to the C compiler generated better code for the u_char -> char case but broke the case where the u_char was being moved to a register. Repeat-By: compile the test program: unsigned char x; main() {register int y; y = x;} note that a "movb _x,r4" is generated instead of "clr r0;bisb _x,r0; mov r0,r4". Fix: Apply the following patch (after installing the previous one) and remake 'c1'. -------------------------------------------------------------------------- *** c10.c.old Sat Oct 5 16:41:38 1991 --- c10.c Wed Oct 9 17:02:52 1991 *************** *** 508,513 **** --- 508,531 ---- && (tree->t.tr1->t.type==CHAR || tree->t.tr1->t.type==UNCHAR) && tree->t.tr2->t.type!=CHAR && tree->t.tr2->t.type!=UNCHAR) tree->t.tr2 = tnode(LOAD, tree->t.tr2->t.type, tree->t.tr2, TNULL); + /* + * Another peculiarity of the PDP11 table manifested itself when + * amplifying the move3: table. The same case which optimizes + * u_char to char moves is used to move a u_char to a register. This + * is wrong, leading to sign extension. Rather than lose the ability + * to generate better code when moving a u_char to a char, a check + * is made here to prevent sign extension. + * + * If the opcode is assign, the destination is a register and the + * source is u_char then do a conversion. + * + * u_char handling in the compiler is a bit awkward, it would be nice + * if %aub in the tables had a more unique meaning. + */ + if (tree->t.tr2 && tree->t.tr1->t.op == NAME + && tree->t.tr1->n.class == REG && tree->t.op == ASSIGN + && tree->t.tr2->t.type == UNCHAR) + tree->t.tr2 = tnode(LOAD, UNSIGN, tree->t.tr2, TNULL); if (table==cregtab) table = regtab; /*