commit 9adea1257259dd445efff48073917cc5a6b3f230
parent 40f728bbc37cdce07a2dd000dfa81c0dfe0b307a
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 10 Jan 2016 17:28:26 +0100
Give non used warning in parameter of functions
This warning can be useful, and it is easy to remove it
using dummy assignations.
Diffstat:
2 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/cc1/decl.c b/cc1/decl.c
@@ -140,7 +140,9 @@ parameter(struct decl *dcl)
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 @@ parameter(struct decl *dcl)
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 @@ parameter(struct decl *dcl)
}
sym->type = tp;
- sym->flags |= ISUSED; /* avoid non used warnings in prototypes */
+ sym->flags |= flags;
return sym;
}
@@ -755,6 +757,27 @@ dodcl(int rep, Symbol *(*fun)(struct decl *), unsigned ns, Type *parent)
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 @@ decl(void)
}
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;
}
diff --git a/cc1/tests/test014.c b/cc1/tests/test014.c
@@ -42,6 +42,7 @@ test014.c:32: error: bad storage class in function parameter
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'
*/