Article View: net.bugs.v7
Article #167Type checking code in PCC is wrong
From: guy
Date: Mon, 26 May 1986 22:46
Date: Mon, 26 May 1986 22:46
133 lines
4260 bytes
4260 bytes
The type checking code in the routine "chkpun" in "mip/trees.c" is wrong.
It considers pointers to be equivalent to arrays; as has repeatedly been
pointed out in net.lang.c, they are not equivalent.
Here is the fix. This fix is for the S5R2 PCC. Fixes for older PCCs are
the same, except that the calls to "WERROR" and "UERROR" with
"MESSAGE( n )" arguments become calls to "werror" and "uerror" with the
message string in the comment above as the argument.
This also fixes "chkpun" so that operations mixing "enum"s and "struct"s or
"union"s get an error indicating incompatible types, rather than a warning
indicating an enumeration type clash.
*** trees.c Mon May 26 15:35:05 1986
--- trees.c.new Mon May 26 15:43:44 1986
***************
*** 736,743 ****
return;
}
if( t1==ENUMTY && t2==ENUMTY && p->in.left->fn.csiz==p->in.right->fn.csiz ) return;
! /* "enumeration type clash, operator %s" */
! WERROR( MESSAGE( 37 ), opst[p->in.op] );
return;
}
--- 736,749 ----
return;
}
if( t1==ENUMTY && t2==ENUMTY && p->in.left->fn.csiz==p->in.right->fn.csiz ) return;
! if( t1==STRTY || t2==STRTY || t1==UNIONTY || t2==UNIONTY ) {
! /* "operands of %s have incompatible types" */
! UERROR( MESSAGE( 89 ), opst[p->in.op] );
! }
! else {
! /* "enumeration type clash, operator %s" */
! WERROR( MESSAGE( 37 ), opst[p->in.op] );
! }
return;
}
***************
*** 751,795 ****
}
}
else {
! d1 = p->in.left->fn.cdim;
! d2 = p->in.right->fn.cdim;
! for( ;; ){
! if( t1 == t2 ) {;
! if( p->in.left->fn.csiz != p->in.right->fn.csiz ) {
! /* "illegal structure pointer combination" */
! WERROR( MESSAGE( 69 ) );
}
! return;
}
#ifdef LINT
-
/* changes 10/23/80 - complain about pointer casts if cflag
* is set (this implies pflag is also set)
*/
! if ( p->in.op == CAST ) /* this implies cflag is set */
! if( ISPTR(t1) && ISPTR(t2) ) {
! /* pointer casts may be troublesome */
! WERROR( MESSAGE( 98 ) );
! return;
}
-
#endif
! if( ISARY(t1) || ISPTR(t1) ){
! if( !ISARY(t2) && !ISPTR(t2) ) break;
! if( ISARY(t1) && ISARY(t2) && dimtab[d1] != dimtab[d2] ){
! /* "illegal array size combination" */
! WERROR( MESSAGE( 49 ) );
! return;
! }
! if( ISARY(t1) ) ++d1;
! if( ISARY(t2) ) ++d2;
! }
! else break;
! t1 = DECREF(t1);
! t2 = DECREF(t2);
}
- /* "illegal pointer combination" */
- WERROR( MESSAGE( 66 ) );
}
}
--- 757,797 ----
}
}
else {
! if( t1 == t2 ) {
! if( p->in.left->fn.csiz != p->in.right->fn.csiz ) {
! /* "illegal structure pointer combination" */
! WERROR( MESSAGE( 69 ) );
! }
! d1 = p->in.left->fn.cdim;
! d2 = p->in.right->fn.cdim;
! for( ;; ){
! if( ISARY(t1) ){
! if( dimtab[d1] != dimtab[d2] ){
! /* "illegal array size combination" */
! WERROR( MESSAGE( 49 ) );
! return;
! }
! ++d1;
! ++d2;
}
! else if( !ISPTR(t1) ) break;
! t1 = DECREF(t1);
}
+ }
+ else {
#ifdef LINT
/* changes 10/23/80 - complain about pointer casts if cflag
* is set (this implies pflag is also set)
*/
! if ( p->in.op == CAST ){ /* this implies cflag is set */
! /* pointer casts may be troublesome */
! WERROR( MESSAGE( 98 ) );
! return;
}
#endif
! /* "illegal pointer combination" */
! WERROR( MESSAGE( 66 ) );
}
}
}
--
Guy Harris
{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
guy@sun.arpa
Technical Details
Message-ID:
<3764@sun.uucp>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!decwrl!sun!guyShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!decwrl!sun!guy From: guy@sun.UUCP Newsgroups: net.bugs.v7,net.bugs.2bsd,net.bugs.4bsd,net.bugs.usg Subject: Type checking code in PCC is wrong Message-ID: <3764@sun.uucp> Date: Mon, 26-May-86 18:46:10 EDT Article-I.D.: sun.3764 Posted: Mon May 26 18:46:10 1986 Date-Received: Wed, 28-May-86 04:23:07 EDT Distribution: net Organization: Sun Microsystems, Inc. Lines: 133