scc

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

commit a100cd930fb84e4e0e1d3dc3c24d3bddd28eb4f0
parent 2ea4d1165e7bd877f2e4e0f5b3ba16d727cce808
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 11 Aug 2014 23:22:52 +0200

Fix tests of unary '-' and '+'

These operator only can be applied to numerical types, but
the code restricted them only to integers operators. Also
in the case of + no new code must be generated, it is only a nop
operator.

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

diff --git a/cc1/expr.c b/cc1/expr.c @@ -91,6 +91,18 @@ integerop(char op, Node *np1, Node *np2) } static Node * +numericaluop(char op, Node *np) +{ + np = eval(np); + switch (np->typeop) { + case INT: case FLOAT: + return (op == OADD) ? np : unarycode(op, np->type, np); + default: + error("unary operator requires integer operand"); + } +} + +static Node * integeruop(char op, Node *np) { np = eval(np); @@ -534,9 +546,8 @@ unary(void) next(); return incdec(unary(), op); case '!': op = 0; fun = negation; break; - /* FIXME: '-' and '+' can be applied to floats to */ - case '+': op = OADD; fun = integeruop; break; - case '-': op = ONEG; fun = integeruop; break; + case '+': op = OADD; fun = numericaluop; break; + case '-': op = ONEG; fun = numericaluop; break; case '~': op = OCPL; fun = integeruop; break; case '&': op = OADDR; fun = address; break; case '*': op = OPTR; fun = content; break;