sam@think.uucp (Sam Kendall) (03/18/87)
Index: /usr/src/lib/mip/trees.c 4.3BSD +FIX
Description:
The C compiler on 4.3BSD, Ultrix, Sun 3.2 and System V.2 (tested
on 3B20 only) allows one to cast a structure or a double into a
pointer. Usually this happens without complaint, and the
generated code takes the first word of the structure or double
to be the value of the pointer; for some code you will get
second pass complaints (on 4.3BSD VAX, "compiler error: no table
entry for op REG"; on Sun, "expression causes compiler loop: try
simplifying"). This bug is NOT present in the UniSoft V7
compiler, oddly enough.
Note for C++ users: C++ releases 1.1 and 1.2 can generate
erroneous code that passes cc without error because of this bug,
so I suggest you install this fix. (We will post separately
about this C++ bug.)
We include the fix for the 4.3BSD C compiler only. The fixes
for the other compilers are probably identical.
Repeat-By:
Compile this program with "cc -S":
main(){
struct { int i; } s;
f((char *) s);
}
Notice the lack of complaint. Inspect the assembly code if you
wish. Now replace `(char *) s' with `(char *)(0, s)', and you
will get the second pass complaint.
Fix:
After you make this change, recompile all the binaries made from
the portable C compiler sources (except that Fortran doesn't
need to be recompiled). On BSD systems, these binaries are
ccom, sccom, and lint. Don't forget lint!
*** trees.c~ Tue Mar 3 12:08:05 1987
--- trees.c Tue Mar 3 12:29:30 1987
***************
*** 1416,1422 ****
else if( mt2 == 0 &&
( p->in.right->in.op == CALL ||
p->in.right->in.op == UNARY CALL)) break;
! else if( mt1 & MPTR ) return( LVAL+PTMATCH+PUN );
else if( mt12 & MPTI ) return( TYPL+LVAL+TYMATCH+PUN );
break;
--- 1416,1426 ----
else if( mt2 == 0 &&
( p->in.right->in.op == CALL ||
p->in.right->in.op == UNARY CALL)) break;
! /*
! * Test of mt2 below added by sam@think.com 3/3/87. Fixes bug
! * that struct, double could be cast to ptr without complaint.
! */
! else if( (mt1&MPTR) && (mt2&MPTI) ) return( LVAL+PTMATCH+PUN );
else if( mt12 & MPTI ) return( TYPL+LVAL+TYMATCH+PUN );
break;
---
Sam Kendall sam@Think.COM
Thinking Machines Corp. {seismo,ihnp4}!think!sam