scc

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

commit 71c6d0ec20a1644b4cf34d52691993d271417660
parent 3a225104759c18a70e8eb918d88a07111f3a128b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  8 Sep 2015 22:23:17 +0200

Allow 0 in pointer initialization

This situation is handled in assignop(), so it is better
do the work on it, but the error message can be a bit
confusing, so it is better define a new operator
and give the correct message.

Diffstat:
Mcc1/cc1.h | 3++-
Mcc1/code.c | 2++
Mcc1/decl.c | 7+------
Mcc1/expr.c | 4+++-
4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -305,7 +305,8 @@ enum op { ORET, ODECL, OSWITCH, - OSWITCHT + OSWITCHT, + OINIT }; /* error.c */ diff --git a/cc1/code.c b/cc1/code.c @@ -39,6 +39,7 @@ char *optxt[] = { [OBXOR] = "^", [OBOR] = "|", [OASSIGN] = ":", + [OINIT] = ":", [OA_MUL] = ":*", [OA_DIV] = ":/", [OA_MOD] = ":%", @@ -91,6 +92,7 @@ void (*opcode[])(unsigned, void *) = { [OBXOR] = emitbin, [OBOR] = emitbin, [OASSIGN] = emitbin, + [OINIT] = emitbin, [OA_MUL] = emitbin, [OA_DIV] = emitbin, [OA_MOD] = emitbin, diff --git a/cc1/decl.c b/cc1/decl.c @@ -372,16 +372,11 @@ initializer(Symbol *sym) return; } np = expr(); - if ((np = convert(np, tp, 0)) == NULL) - goto bad_initializer; if ((sym->flags & ISLOCAL) == 0) { - emit(OEXPR, assignop(OASSIGN, varnode(sym), np)); + emit(OEXPR, assignop(OINIT, varnode(sym), np)); return; } return; - -bad_initializer: - errorp("invalid initializer"); } static Symbol * diff --git a/cc1/expr.c b/cc1/expr.c @@ -433,7 +433,9 @@ assignop(char op, Node *lp, Node *rp) force = 1; } if ((rp = convert(rp, tp, force)) == NULL) { - errorp("incompatible types when assigning"); + errorp((op == OINIT) ? + "incorrect initiliazer" : + "incompatible types when assigning"); return lp; }