Lint does not know voids

goldberg at uiucdcs.CS.UIUC.EDU goldberg at uiucdcs.CS.UIUC.EDU
Thu Mar 13 13:20:00 AEST 1986



Date: Wed, 12 Mar 86 14:48:04 cst
From: stevea at uiphysed.PE.UIUC.EDU (Steve Alexander)
To: goldberg at cs.uiuc.edu
Subject: Bug fix for 2.9 lint & voids -- please post

Subject: Lint does not grok voids
Index:	usr.bin/lint/lint.c lib/mip/{cgram.y,manifest,scan.c,trees.c} 
	CSS/Harvard 2.9 Fix

Description:
	Although the Ritchie compiler was changed to support voids, the PCC
	(and hence lint) was not.
Repeat-By:
	lint the following:

	extern void zz();
	main()
	{
		(void)printf("Won't work\n");
	}
	void z()
	{
		return;
	}
Fix:

	Install the following diffs...  *NOTE*  I have not tested these
	with the PCC, only with lint.  I don't use the PCC (does anyone?)
	These are mostly ripped off of the VAX 4.2 PCC...

### lint/lint.c

RCS file: RCS/lint.c,v
retrieving revision 1.1
diff -c -r1.1 lint.c
*** /tmp/,RCSt1021526	Wed Mar 12 01:05:37 1986
--- lint.c	Sun Mar  9 16:44:21 1986
***************
*** 73,79
  
  	default:
  		if( asgop(p->op) ) break;
! 		if( p->op == UNARY MUL && ( p->type == STRTY || p->type == UNIONTY) ) {
  			break;  /* the compiler does this... */
  			}
  		if( down == EFF && hflag ) werror( "null effect" );

--- 73,85 -----
  
  	default:
  		if( asgop(p->op) ) break;
! 		if( p->op == UNARY MUL && ( p->type == STRTY || p->type == UNIONTY || p->type == UNDEF) ) {
! 
! 		/*
! 		 * struct x f(); main() { (void) f(); }
! 		 * the cast call appears as U* UNDEF
! 		 */
! 
  			break;  /* the compiler does this... */
  			}
  		if( down == EFF && hflag ) werror( "null effect" );
***************
*** 335,340
  	case UNARY STCALL:
  	case UNARY FORTCALL:
  		if( p->left->op == ICON && (id=p->left->rval) != NONAME ){ /* used to be &name */
  			printf( "%.7s\t%03d\t%o\t%d\t",
  				exname(stab[id].sname),
  				down==EFF ? LUE : LUV,

--- 341,356 -----
  	case UNARY STCALL:
  	case UNARY FORTCALL:
  		if( p->left->op == ICON && (id=p->left->rval) != NONAME ){ /* used to be &name */
+ 			int lty;
+ 			if ((down == EFF) && (p->type != UNDEF)) {
+ 				lty = LUE;
+ 			}
+ 			else if (down == EFF) {
+ 				lty = LUV | LUE;
+ 			}
+ 			else {
+ 				lty = LUV;
+ 			}
  			printf( "%.7s\t%03d\t%o\t%d\t",
  				exname(stab[id].sname),
  				lty,
***************
*** 337,343
  		if( p->left->op == ICON && (id=p->left->rval) != NONAME ){ /* used to be &name */
  			printf( "%.7s\t%03d\t%o\t%d\t",
  				exname(stab[id].sname),
! 				down==EFF ? LUE : LUV,
  				DECREF(p->left->type), acount );
  			if( acount ) lpta( p->right );
  			ident();

--- 353,359 -----
  			}
  			printf( "%.7s\t%03d\t%o\t%d\t",
  				exname(stab[id].sname),
! 				lty,
  				DECREF(p->left->type), acount );
  			if( acount ) lpta( p->right );
  			ident();

### mip/cgram.y

RCS file: RCS/cgram.y,v
retrieving revision 1.2
diff -c -r1.2 cgram.y
*** /tmp/,RCSt1021533	Wed Mar 12 01:08:33 1986
--- cgram.y	Tue Mar 11 23:05:56 1986
***************
*** 190,195
  			={  $$ = mkty(INT,0,INT); }
  		|  type
  			={ curclass = SNULL ; }
  		;
  
  

--- 190,199 -----
  			={  $$ = mkty(INT,0,INT); }
  		|  type
  			={ curclass = SNULL ; }
+ 		|  type class type 
+ 			={  $1->type = types( $1->type, $3->type, UNDEF );
+ 			    $3->op = FREE;
+ 			    }
  		;
  
  
***************
*** 490,495
  			={  register NODE *temp;
  			    idname = curftn;
  			    temp = buildtree( NAME, NIL, NIL );
  			    temp->type = DECREF( temp->type );
  			    temp = buildtree( RETURN, temp, $2 );
  			    /* now, we have the type of the RHS correct */

--- 494,502 -----
  			={  register NODE *temp;
  			    idname = curftn;
  			    temp = buildtree( NAME, NIL, NIL );
+ 			    if (temp->type == TVOID)
+ 				uerror("void function %s cannot return value",
+ 					stab[idname].sname);
  			    temp->type = DECREF( temp->type );
  			    temp = buildtree( RETURN, temp, $2 );
  			    /* now, we have the type of the RHS correct */

### mip/manifest

RCS file: RCS/manifest,v
retrieving revision 1.1
diff -c -r1.1 manifest
*** /tmp/,RCSt1021539	Wed Mar 12 01:09:38 1986
--- manifest	Sat Mar  8 17:16:54 1986
***************
*** 147,152
  
  /*	type names, used in symbol table building */
  # define TNULL PTR    /* pointer to UNDEF */
  # define UNDEF 0
  # define FARG 1
  # define CHAR 2

--- 147,153 -----
  
  /*	type names, used in symbol table building */
  # define TNULL PTR    /* pointer to UNDEF */
+ # define TVOID FTN
  # define UNDEF 0
  # define FARG 1
  # define CHAR 2

### mip/scan.c

RCS file: RCS/scan.c,v
retrieving revision 1.1
diff -c -r1.1 scan.c
*** /tmp/,RCSt1021548	Wed Mar 12 01:10:19 1986
--- scan.c	Tue Mar 11 17:30:01 1986
***************
*** 784,789
  	"typedef",	AR_CL,	TYPEDEF,
  	"unsigned",	AR_TY,	UNSIGNED,
  	"union",	AR_U,	0,
  	"while",	AR_RW,	WHILE,
  	"",		0,	0,	/* to stop the search */
  	};

--- 784,790 -----
  	"typedef",	AR_CL,	TYPEDEF,
  	"unsigned",	AR_TY,	UNSIGNED,
  	"union",	AR_U,	0,
+ 	"void",		AR_TY,  UNDEF,
  	"while",	AR_RW,	WHILE,
  	"",		0,	0,	/* to stop the search */
  	};
***************
*** 828,834
  		c=26; break;
  	case 'u':
  		c=27; break;
! 	case 'w':
  		c=29; break;
  
  	default:

--- 829,835 -----
  		c=26; break;
  	case 'u':
  		c=27; break;
! 	case 'v':
  		c=29; break;
  	case 'w':
  		c=30; break;
***************
*** 830,835
  		c=27; break;
  	case 'w':
  		c=29; break;
  
  	default:
  		return( -1 );

--- 831,838 -----
  		c=27; break;
  	case 'v':
  		c=29; break;
+ 	case 'w':
+ 		c=30; break;
  
  	default:
  		return( -1 );

### mip/trees.c

RCS file: RCS/trees.c,v
retrieving revision 1.1
diff -c -r1.1 trees.c
*** /tmp/,RCSt1021555	Wed Mar 12 01:11:17 1986
--- trees.c	Wed Mar 12 00:20:18 1986
***************
*** 888,893
  	t1 = p->left->type;
  	t2 = p->right->type;
  
  	u = 0;
  	if( ISUNSIGNED(t1) ){
  		u = 1;

--- 888,900 -----
  	t1 = p->left->type;
  	t2 = p->right->type;
  
+ /*
+  * void mods from vax 4.2 pcc
+  */
+ 
+ 	if ((t1 == UNDEF || t2 == UNDEF) && o!=CAST)
+ 		uerror("void type illegal in expression");
+ 
  	u = 0;
  	if( ISUNSIGNED(t1) ){
  		u = 1;
***************
*** 1134,1139
  	case RETURN:
  		if( mt12 & MSTR ) return( LVAL+NCVT+TYPL+OTHER );
  	case CAST:
  		if( mt12 & MDBI ) return( TYPL+LVAL+TYMATCH );
  		else if( (mt1&MENU)||(mt2&MENU) ) return( LVAL+NCVT+TYPL+PTMATCH+PUN );
  		else if( mt1 & MPTR ) return( LVAL+PTMATCH+PUN );

--- 1141,1147 -----
  	case RETURN:
  		if( mt12 & MSTR ) return( LVAL+NCVT+TYPL+OTHER );
  	case CAST:
+ 		if (o==CAST && mt1==0) return(TYPL+TYMATCH);
  		if( mt12 & MDBI ) return( TYPL+LVAL+TYMATCH );
  		else if( (mt1&MENU)||(mt2&MENU) ) return( LVAL+NCVT+TYPL+PTMATCH+PUN );
  		else if( mt1 & MPTR ) return( LVAL+PTMATCH+PUN );
***************
*** 1182,1187
  
  	switch( ty ){
  
  	case ENUMTY:
  	case MOETY:
  		return( MENU );

--- 1190,1198 -----
  
  	switch( ty ){
  
+ 	case UNDEF:
+ 	case TVOID:
+ 		return(0);
  	case ENUMTY:
  	case MOETY:
  		return( MENU );



More information about the Comp.bugs.2bsd mailing list