shithub: scc

Download patch

ref: 83c47446b030f8abd1c7b635d41bdd84fc10f8b0
parent: a47da4831e6000e825decbeb876cfc604082d41f
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Nov 16 01:17:03 EST 2014

Check type of function parameters

Not all the types are valid for functions (for example function parameters),
and it is also needed decay the array types to pointers.

--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -383,8 +383,11 @@
 	if ((tp = specifier(&sclass)) == voidtype)
 		return tp;
 	sym = declarator(tp, ID_ACCEPTED, NS_IDEN);
-	sym->s.isdefined = 1;
-	/* TODO: check type of the parameter */
+	tp = sym->type;
+	if (tp->op == FTN)
+		error("incorrect function type for a function parameter");
+	if (tp->op == ARY)
+		tp = mktype(tp->type, PTR, 0, NULL);
 	switch (sclass) {
 	case REGISTER:
 		sym->s.isregister = 1;
@@ -395,7 +398,7 @@
 	default:
 		error("bad storage class in function parameter");
 	}
-	return sym->type;
+	return tp;
 }
 
 void