scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 2f307820bc3dab666974d065749aef367982f420
parent 4521cc8f0aade2082ec19d310fbc4facc1158f32
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 14 Jun 2022 21:43:58 +0200

cc1: Don't remove warnings in typedef'ed functions

When a typedef of a function is used as base to build a new typedef
then it does not have any argument because in that case the typedef
only carries the type but no arguments. The pars field of the decl
structure was not initialized because this case was not expected and
any NULL check was failing.

Diffstat:
Msrc/cmd/cc/cc1/decl.c | 24+++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/cmd/cc/cc1/decl.c b/src/cmd/cc/cc1/decl.c @@ -48,13 +48,19 @@ struct decl { static void endfundcl(Type *tp, Symbol **pars) { - if ((tp->prop&TK_R) != 0 && *pars) - warn("parameter names (without types) in function declaration"); /* - * avoid non used warnings in prototypes + * If endfundcl is called from a type built from a typedef then + * we do not have any parameters because in that case we only + * care about the type. */ - while (*pars) - (*pars++)->flags |= SUSED; + if (pars) { + if ((tp->prop&TK_R) != 0 && *pars) + warn("parameter names (without types) in function declaration"); + + /* avoid non used warnings in prototypes */ + while (*pars) + (*pars++)->flags |= SUSED; + } popctx(); } @@ -104,6 +110,13 @@ pop(struct declarators *dp, struct decl *dcl) return 1; } + /* + * We have a type derived from a function type. We don't care + * about the parameters because they were used only in the + * process of building a final type. Prototype arguments are + * discarded in funbody() because the final type of the decl + * is an actual function. + */ if (dcl->type->op == FTN) endfundcl(dcl->type, dcl->pars); dcl->pars = p->pars; @@ -935,6 +948,7 @@ dodcl(int rep, Symbol *(*fun)(struct decl *), unsigned ns, Type *parent) do { dcl.type = base; + dcl.pars = NULL; stack.nr_types = stack.nr = 0; stack.tpars = dcl.buftpars; stack.pars = dcl.bufpars;