scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 825d523e6ae30a93224c2d6799592ae73f7ea926
parent 7369e862b993e9e62b153f0101d0866f85d5a485
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  5 Aug 2014 18:13:42 +0200

Remove decay in convert()

convert() do all the needed operations to convert an expression
of a type in another type. It was generating a decay when the
destination type was an array or an function, but it was incorrect,
because it was generating a decay of the node, that surely was
not an array or a function. The correct here is return NULL,
because we should not receive such types as destination
types.

Diffstat:
Mcc1/expr.c | 10+++-------
1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -111,17 +111,15 @@ decay(Node *np) Node * convert(Node *np, Type *tp, char iscast) { - uint8_t t; - if (eqtype(np->type, tp)) return np; - t = tp->op; switch (np->typeop) { case ENUM: case INT: case FLOAT: - switch (t) { + switch (tp->op) { case PTR: if (!iscast || np->typeop == FLOAT) return NULL; + /* PASSTHROUGH */ case INT: case FLOAT: case ENUM: case VOID: break; default: @@ -129,13 +127,11 @@ convert(Node *np, Type *tp, char iscast) } break; case PTR: - switch (t) { + switch (tp->op) { case ENUM: case INT: case VOID: /* TODO: allow p = 0 */ if (!iscast) return NULL;; break; - case ARY: case FTN: - np = decay(np); case PTR: if (iscast || tp == pvoidtype ||