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