[hackers] [scc] Give non used warning in parameter of functions || Roberto E. Vargas Caballero
commit 9adea1257259dd445efff48073917cc5a6b3f230
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Sun Jan 10 17:28:26 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Sun Jan 10 17:52:50 2016 +0100
Give non used warning in parameter of functions
This warning can be useful, and it is easy to remove it
using dummy assignations.
diff --git a/cc1/decl.c b/cc1/decl.c
index f900ac6..f5a43f1 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
_AT_@ -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:
_AT_@ -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;
}
_AT_@ -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;
}
_AT_@ -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)
{
_AT_@ -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
index 7f4ab89..2fc66a5 100644
--- a/cc1/tests/test014.c
+++ b/cc1/tests/test014.c
_AT_@ -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'
*/
Received on Mon Jan 11 2016 - 10:17:13 CET
This archive was generated by hypermail 2.3.0
: Mon Jan 11 2016 - 10:24:22 CET