diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index f2a815e..d7ffa55 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -5214,8 +5214,7 @@ static void scanloopvariables(symstate **loopvars) /* if the variable already has the uLOOPVAR flag set (from being used * in an enclosing loop), we have to set the uNOLOOPVAR to exclude it * from checks in the current loop */ - if ((sym->ident==iVARIABLE || sym->ident==iREFERENCE || sym->ident==iARRAY - || sym->ident==iREFARRAY) && (sym->usage & uLOOPVAR)!=0) { + if ((sym->ident==iVARIABLE || sym->ident==iREFERENCE) && (sym->usage & uLOOPVAR)!=0) { /* ... but it might be already set from an enclosing loop, * so we need to temporarily store it in "loopvars[num]" first */ (*loopvars)[num].usage |= (sym->usage & uNOLOOPVAR); @@ -5245,8 +5244,8 @@ static void testloopvariables(symstate *loopvars,int line) if (pc_numloopvars!=0) { warnnum=(pc_numloopvars==1) ? 250 : 251; for (sym=start; sym!=NULL; sym=sym->next) - if ((sym->ident==iVARIABLE || sym->ident==iREFERENCE || sym->ident==iARRAY - || sym->ident==iREFARRAY) && (sym->usage & (uLOOPVAR | uNOLOOPVAR))==uLOOPVAR) + if ((sym->ident==iVARIABLE || sym->ident==iREFERENCE) + && (sym->usage & (uLOOPVAR | uNOLOOPVAR))==uLOOPVAR) pc_numloopvars--; if (pc_numloopvars==0 && warnnum==251) { errorset(sSETPOS,line); @@ -5256,8 +5255,7 @@ static void testloopvariables(symstate *loopvars,int line) } /* if */ for (num=0,sym=start; sym!=NULL; num++,sym=sym->next) { - if (sym->ident==iVARIABLE || sym->ident==iREFERENCE - || sym->ident==iARRAY || sym->ident==iREFARRAY) { + if (sym->ident==iVARIABLE || sym->ident==iREFERENCE) { if ((sym->usage & (uLOOPVAR | uNOLOOPVAR))==uLOOPVAR) { sym->usage &= ~uLOOPVAR; /* warn only if none of the variables used inside the loop condition diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 028595f..07bd7bb 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -3309,10 +3309,8 @@ SC_FUNC void markusage(symbol *sym,int usage) sym->lnumber=fline; if ((usage & uREAD)!=0 && (sym->ident==iVARIABLE || sym->ident==iREFERENCE)) sym->usage &= ~uASSIGNED; - if ((usage & (uREAD | uWRITTEN))!=0 - && (sym->vclass==sLOCAL || sym->vclass==sSTATIC) - && (sym->ident==iVARIABLE || sym->ident==iREFERENCE - || sym->ident==iARRAY || sym->ident==iREFARRAY)) + if ((usage & (uREAD | uWRITTEN))!=0 && (sym->vclass==sLOCAL || sym->vclass==sSTATIC) + && (sym->ident==iVARIABLE || sym->ident==iREFERENCE)) markloopvariable(sym,usage); /* check if (global) reference must be added to the symbol */ if ((usage & (uREAD | uWRITTEN))!=0) { diff --git a/source/compiler/sc3.c b/source/compiler/sc3.c index 7ed94e1..c6f2506 100644 --- a/source/compiler/sc3.c +++ b/source/compiler/sc3.c @@ -1770,6 +1770,12 @@ restart: error(51); /* invalid subscript, must use [ ] */ invsubscript=TRUE; } /* if */ + if (pc_loopcond) { + /* stop counting variables that were used in loop condition, + * otherwise warnings 250 and 251 may be inaccurate */ + pc_loopcond=FALSE; + pc_numloopvars=0; + } /* if */ if (invsubscript) { if (sym!=NULL && sym->ident!=iFUNCTN) sym->usage |= uREAD; /* avoid the "symbol is never used" warning */ @@ -2177,7 +2183,6 @@ static int nesting=0; int nargs=0; /* number of arguments */ int heapalloc=0; int namedparams=FALSE; - int save_loopcond; value lval = {0}; arginfo *arg; char arglist[sMAXARGS]; @@ -2197,10 +2202,12 @@ static int nesting=0; error(29); /* invalid expression, assumed zero */ return; } /* if */ - /* make the compiler not count variables passed as function arguments - * as being used inside a loop condition */ - save_loopcond=pc_loopcond; - pc_loopcond=FALSE; + if (pc_loopcond) { + /* stop counting variables that were used in loop condition, + * otherwise warnings 249 and 250 may be inaccurate */ + pc_loopcond=FALSE; + pc_numloopvars=0; + } /* if */ /* check whether this is a function that returns an array */ symret=finddepend(sym); assert(symret==NULL || symret->ident==iREFARRAY); @@ -2614,7 +2621,6 @@ static int nesting=0; if (symret!=NULL) popreg(sPRI); /* pop hidden parameter as function result */ pc_sideeffect=TRUE; /* assume functions carry out a side-effect */ - pc_loopcond=save_loopcond; delete_consttable(&arrayszlst); /* clear list of array sizes */ delete_consttable(&taglst); /* clear list of parameter tags */