[hackers] [scc] [cc1] Fix comparisions || Roberto E. Vargas Caballero
commit 22c9d2196d0be85579fd57745f9a398bb8f01df5
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Feb 21 21:08:20 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
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
_AT_@ -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 *
_AT_@ -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);
Received on Tue Feb 21 2017 - 21:11:50 CET
This archive was generated by hypermail 2.3.0
: Tue Feb 21 2017 - 21:12:28 CET