From: utzoo!decvax!harpo!eagle!mit-vax!mp Newsgroups: net.lang.c,net.unix-wizards Title: pcc register allocation bug Article-I.D.: mit-vax.216 Posted: Mon Apr 4 18:41:04 1983 Received: Tue Apr 5 04:17:46 1983 Awhile ago I passed on a problem that was observed in the 4.1bsd (and System III and V) pcc. It went like this: From: Jeff Mogul The problem arises whenever an expression includes a comparison of a float and a double, and at least one other operation. Either the expression doesn't evaluate correctly because a temporary register is being used for two different things, or it does evaluate correctly, but a live register may be bashed. Here is a program that fails: #include double dd[] = { 0.0, 2.0 }; float ff[] = { 0.0, 1.0 }; int i = 1; main(){ if( ff[i] >= dd[i] ) printf( "ff >= dd\n" ); } Here is the buggy Vax machine code (cc -S, no optimizer): movl _i,r0 movl _i,r1 cvtfd _ff[r0],r0 cmpd r0,_dd[r1] jlss L25 Jeff Mogul and John Gill, of Stanford, found a way to fix the bug. They write: It involves changing one file (/usr/[local/]src/cmd/pcc/table.c), recompiling, and re-installing (using "make", of course.) *** /usr/src/cmd/pcc/table.c Wed Dec 17 15:04:41 1980 --- ntable.c Sun Mar 6 11:00:36 1983 *************** *** 228,234 OPLOG, FORCC, SAREG|AWD, TDOUBLE, SAREG|AWD, TFLOAT, ! NAREG|NASR, RESCC, " cvtfd AR,A1\n cmpd AL,A1\nZP", OPLOG, FORCC, --- 228,234 ----- OPLOG, FORCC, SAREG|AWD, TDOUBLE, SAREG|AWD, TFLOAT, ! 2*NTEMP, RESCC, " cvtfd AR,A1\n cmpd AL,A1\nZP", OPLOG, FORCC, *************** *** 234,240 OPLOG, FORCC, SAREG|AWD, TFLOAT, SAREG|AWD, TDOUBLE, ! NAREG|NASL, RESCC, " cvtfd AL,A1\n cmpd A1,AR\nZP", OPLOG, FORCC, --- 234,240 ----- OPLOG, FORCC, SAREG|AWD, TFLOAT, SAREG|AWD, TDOUBLE, ! 2*NTEMP, RESCC, " cvtfd AL,A1\n cmpd A1,AR\nZP", OPLOG, FORCC,