commit 9adea1257259dd445efff48073917cc5a6b3f230
Author:     Roberto E. Vargas Caballero <k...@shike2.com>
AuthorDate: Sun Jan 10 17:28:26 2016 +0100
Commit:     Roberto E. Vargas Caballero <k...@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
@@ -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
index 7f4ab89..2fc66a5 100644
--- 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'
 */
 

Reply via email to