🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by guy Mon, 26 May 1986 22:46
Type checking code in PCC is wrong
#167
Author: guy
Date: Mon, 26 May 1986 22:46
133 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads