ref: 9adea1257259dd445efff48073917cc5a6b3f230
parent: 40f728bbc37cdce07a2dd000dfa81c0dfe0b307a
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Jan 10 12:28:26 EST 2016
Give non used warning in parameter of functions This warning can be useful, and it is easy to remove it using dummy assignations.
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -140,7 +140,9 @@
Type *funtp = dcl->parent, *tp = dcl->type;
TINT n = funtp->n.elem;
char *name = sym->name;
+ int flags;
+ flags = 0;
switch (dcl->sclass) {
case STATIC:
case EXTERN:
@@ -148,10 +150,10 @@
errorp("bad storage class in function parameter");
break;
case REGISTER:
- sym->flags |= ISREGISTER;
+ flags |= ISREGISTER;
break;
case NOSCLASS:
- sym->flags |= ISAUTO;
+ flags |= ISAUTO;
break;
}
@@ -180,7 +182,7 @@
}
sym->type = tp;
- sym->flags |= ISUSED; /* avoid non used warnings in prototypes */
+ sym->flags |= flags;
return sym;
}
@@ -755,6 +757,27 @@
return sym;
}
+static void
+prototype(Symbol *sym)
+{
+ int n;
+ Symbol **p;
+
+ emit(ODECL, sym);
+ /*
+ * avoid non used warnings in prototypes
+ */
+ n = sym->type->n.elem;
+ for (p = sym->u.pars; n-- > 0; ++p) {
+ if (*p == NULL)
+ continue;
+ (*p)->flags |= ISUSED;
+ }
+ free(sym->u.pars);
+ sym->u.pars = NULL;
+ popctx();
+}
+
void
decl(void)
{
@@ -775,11 +798,7 @@
}
if (curctx != GLOBALCTX+1 || yytoken == ';') {
- /* it is a prototype */
- emit(ODECL, sym);
- free(sym->u.pars);
- sym->u.pars = NULL;
- popctx();
+ prototype(sym);
expect(';');
return;
}
--- a/cc1/tests/test014.c
+++ b/cc1/tests/test014.c
@@ -42,6 +42,7 @@
test014.c:33: error: invalid storage class for function 'func4'
test014.c:34: error: invalid type specification
test014.c:35: warning: 'f' defined but not used
+test014.c:35: warning: 'par' defined but not used
test014.c:38: error: conflicting types for 'd'
*/