shithub: scc

Download patch

ref: cde67f41cb37d1c695d7de0a5100458bcc5de9c1
parent: 3c619b9a7518c458fe6343faab8f566368557080
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Aug 5 05:07:45 EDT 2015

Fix error related to incorrect parameter declaration

dodcl is called without knowing that the next token
is a valid specifier, so specifier() can return
NULL in the case of parameters. This patch detects
this situation and apply old rule of default int.
Maybe is better to put a flag for it.

--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -364,7 +364,7 @@
 }
 
 static void
-field(Symbol *sym, unsigned sclass, Type *data)
+field(Symbol *sym, int sclass, Type *data)
 {
 	Type *tp = sym->type, *funtp = data;
 	size_t n = funtp->n.elem;
@@ -384,7 +384,7 @@
 }
 
 static void
-parameter(Symbol *sym, unsigned sclass, Type *data)
+parameter(Symbol *sym, int sclass, Type *data)
 {
 	Type *tp = sym->type, *funtp = data;
 	size_t n = funtp->n.elem;
@@ -415,7 +415,7 @@
 }
 
 static void
-internal(Symbol *sym, unsigned sclass, Type *data)
+internal(Symbol *sym, int sclass, Type *data)
 {
 
 	if (!sym->name) {
@@ -431,7 +431,7 @@
 }
 
 static void
-external(Symbol *sym, unsigned sclass, Type *data)
+external(Symbol *sym, int sclass, Type *data)
 {
 	if (!sym->name) {
 		warn("empty declaration");
@@ -480,25 +480,24 @@
 }
 
 static bool
-dodcl(int rep, void (*fun)(Symbol *, unsigned, Type *), uint8_t ns, Type *type)
+dodcl(int rep, void (*fun)(Symbol *, int, Type *), uint8_t ns, Type *type)
 {
-	Type *base, *tp = NULL;
-	unsigned sclass = 0;
-	Symbol *sym = NULL;
+	Type *base;
+	int sclass;
 
 	/* FIXME: curctx == PARCTX is incorrect. Structs also
 	 * create new contexts
 	 */
-	/* FIXME: in arguments base can be NULL */
-	base = specifier(&sclass);
-	if (!base && curctx == OUTCTX) {
+	if ((base = specifier(&sclass)) == NULL) {
+		if (curctx != OUTCTX)
+			unexpected();
 		warn("type defaults to 'int' in declaration");
-		tp = inttype;
+		base = inttype;
 	}
 
 	do {
-		sym = declarator(base, ns);
-		tp = sym->type;
+		Symbol *sym = declarator(base, ns);
+		Type *tp = sym->type;
 
 		switch (sclass) {
 		case REGISTER: