shithub: scc

Download patch

ref: 2f307820bc3dab666974d065749aef367982f420
parent: 4521cc8f0aade2082ec19d310fbc4facc1158f32
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Jun 14 17:43:58 EDT 2022

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.

--- a/src/cmd/cc/cc1/decl.c
+++ b/src/cmd/cc/cc1/decl.c
@@ -48,13 +48,19 @@
 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 @@
 		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 @@
 
 	do {
 		dcl.type = base;
+		dcl.pars = NULL;
 		stack.nr_types = stack.nr = 0;
 		stack.tpars = dcl.buftpars;
 		stack.pars = dcl.bufpars;