commit 22c9d2196d0be85579fd57745f9a398bb8f01df5
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Tue Feb 21 21:08:20 2017 +0100
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Tue Feb 21 21:11:05 2017 +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.

diff --git a/cc1/expr.c b/cc1/expr.c
index 960b78e..eb91a8e 100644
--- 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);

Reply via email to