scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit cde67f41cb37d1c695d7de0a5100458bcc5de9c1
parent 3c619b9a7518c458fe6343faab8f566368557080
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed,  5 Aug 2015 09:07:45 +0200

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.

Diffstat:
cc1/decl.c | 27+++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/cc1/decl.c b/cc1/decl.c @@ -364,7 +364,7 @@ typename(void) } 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 @@ field(Symbol *sym, unsigned sclass, Type *data) } 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 @@ parameter(Symbol *sym, unsigned sclass, Type *data) } static void -internal(Symbol *sym, unsigned sclass, Type *data) +internal(Symbol *sym, int sclass, Type *data) { if (!sym->name) { @@ -431,7 +431,7 @@ internal(Symbol *sym, unsigned sclass, Type *data) } 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 @@ prototype(Symbol *sym) } 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: