[net.bugs.4bsd] weird C-compiler error message

guy@sun.UUCP (06/07/86)

> Hi.  We're talking SVR2 Unix on a Vax 11/780 here.

This is a close-to-universal PCC bug (most PCC bugs not involved in code
generation are, alas); read on, even if you aren't running S5R2 on a VAX.

> A novice user was playing around with C and wrote a program that started
> like this:
> 
> int f1, f2;  /* other variable declarations, too */
> main(argc,argv)
> int argc, f1, f2;
> char **argv;
> {
> 
> On lines 27 and 30 of his program, he referenced the variable "f2".
> 
> Our illustrious (actually usually pretty damn good) C compiler said:
> 
> 27: warning: bad arg temp

Yup.  The trouble is that it didn't catch the error when it should have, and
found out that it'd screwed up later.  (Why that "bad arg temp" is a
warning, I dunno - if it's a compiler bug it should report it as such.)

Here's a fix for the S5R2 PCC; the line numbers will be different.  It
should be obvious how to apply this fix to earlier PCCs, like the S3/4BSD
version, as well as to the version hidden away amongst the S3 "lint" source.
No guarantees that this won't break anything, but it seems to make sense
(after the fix, the rules are "if it was declared as a function argument
(i.e., blevel == 1), and if it did not appear in the argument list for that
function (i.e., stp != FARG), and if it's not a name of a structure, union,
or enum, a member of same, or a typedef, it's an error"), definitely catches
the above case, and doesn't seem to choke on other cases.

------- pftn.c -------
*** /tmp/da5007	Fri Jun  6 20:58:37 1986
--- pftn.c	Fri Jun  6 17:18:31 1986
***************
*** 81,104 ****
  
  	if( stp == FTN && p->sclass == SNULL )goto enter;
  		/* name encountered as function, not yet defined */
- 	if( stp == UNDEF|| stp == FARG ){
- 		if( blevel==1 && stp!=FARG ) switch( class ){
  
! 		default:
! 			/* "declared argument %.8s is missing" */
! 			/* "declared argument %s is missing" */
! 			if(!(class&FIELD)) UERROR( MESSAGE( 28 ), p->sname );
! 		case MOS:
! 		case STNAME:
! 		case MOU:
! 		case UNAME:
! 		case MOE:
! 		case ENAME:
! 		case TYPEDEF:
! 			;
! 			}
! 		goto enter;
  		}
  
  	if( type != stp ) goto mismatch;
  	/* test (and possibly adjust) dimensions */
--- 81,104 ----
  
  	if( stp == FTN && p->sclass == SNULL )goto enter;
  		/* name encountered as function, not yet defined */
  
! 	if( blevel==1 && stp!=FARG ) switch( class ){
! 
! 	default:
! 		/* "declared argument %.8s is missing" */
! 		/* "declared argument %s is missing" */
! 		if(!(class&FIELD)) UERROR( MESSAGE( 28 ), p->sname );
! 	case MOS:
! 	case STNAME:
! 	case MOU:
! 	case UNAME:
! 	case MOE:
! 	case ENAME:
! 	case TYPEDEF:
! 		;
  		}
+ 
+ 	if( stp == UNDEF|| stp == FARG ) goto enter;
  
  	if( type != stp ) goto mismatch;
  	/* test (and possibly adjust) dimensions */
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy@sun.com (or guy@sun.arpa)