ref: a590d782a37a2bea19608f5cb599de8b123daf7d
parent: 0913d2792e7acc50bd4a861322e28133a9807124
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Feb 21 16:08:20 EST 2017
[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.
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -352,7 +352,7 @@
static Node *
pcompare(int op, Node *lp, Node *rp)
{
- Node *np, *p;
+ Node *np;
if (lp->type->prop & TINTEGER)
XCHG(lp, rp, np);
@@ -359,11 +359,11 @@
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 @@
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);