Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!think!sam From: sam@think.uucp (Sam Kendall) Newsgroups: comp.bugs.4bsd,comp.bugs.sys5,comp.lang.c,comp.lang.c++ Subject: C compiler bug on 4.3BSD, Ultrix, Sun 3.2, System V.2 Message-ID: <2488@think.UUCP> Date: Tue, 17-Mar-87 16:18:26 EST Article-I.D.: think.2488 Posted: Tue Mar 17 16:18:26 1987 Date-Received: Thu, 19-Mar-87 01:15:01 EST Sender: news@think.UUCP Lines: 65 Xref: mnetor comp.bugs.4bsd:230 comp.bugs.sys5:85 comp.lang.c:1273 comp.lang.c++:179 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