scc

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

commit 22c9d2196d0be85579fd57745f9a398bb8f01df5
parent 00f3f535342d3e8fedd68d6171cb3498574fcfe4
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 21 Feb 2017 21:08:20 +0100

[cc1] Fix comparisions

Comparisions are a bit different to other binary oeprators, because
they have two types, the type in which the operation is done and
the type of the result of the operation. This cannot be represented
with out IR because each node strictly has only one type, so the best
solution is to keep the result of the operation in the same type than
the oepration and add a cast after that. cc2 can cover perfctly with
this combination of nodes without any work.

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

diff --git a/cc1/expr.c b/cc1/expr.c @@ -352,18 +352,18 @@ arithmetic(int op, Node *lp, Node *rp) static Node * pcompare(int op, Node *lp, Node *rp) { - Node *np, *p; + Node *np; if (lp->type->prop & TINTEGER) XCHG(lp, rp, np); else if (eqtype(lp->type, pvoidtype, 1)) XCHG(lp, rp, np); - if ((p = convert(rp, lp->type, 0)) != NULL) - rp = p; + if ((np = convert(rp, lp->type, 0)) != NULL) + rp = np; else errorp("incompatible types in comparison"); - return node(op, inttype, lp, rp); + return convert(node(op, pvoidtype, lp, rp), inttype, 1); } static Node * @@ -378,7 +378,7 @@ compare(int op, Node *lp, Node *rp) return pcompare(op, rp, lp); } else if ((ltp->prop & TARITH) && (rtp->prop & TARITH)) { arithconv(&lp, &rp); - return node(op, inttype, lp, rp); + return convert(node(op, lp->type, lp, rp), inttype, 1);; } else { errorp("incompatible types in comparison"); freetree(lp);