scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 76d8f0ce8320ce1802ad46692c86755149e47321
parent 3b2e44c857369ce03250eccb354420a52a04b201
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 16 Nov 2021 08:13:35 +0100

cc1: Simplify convert() in pcompare()

Pcompare() was trying to be too clever and to avoid 4 lines of
code it was interchanging parameters to apply only one logic
about how to convert left and right parts. This was making that
the integer parameter could be only at one side of the comparision.

Diffstat:
Msrc/cmd/cc/cc1/expr.c | 20++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/cmd/cc/cc1/expr.c b/src/cmd/cc/cc1/expr.c @@ -347,15 +347,19 @@ pcompare(int op, Node *lp, Node *rp) { Node *np; - if (lp->type->prop & TINTEGER) - XCHG(lp, rp, np); - else if (eqtype(lp->type, pvoidtype, 1)) - XCHG(lp, rp, np); + if (lp->type->prop&TINTEGER) { + if ((np = convert(lp, rp->type, 0)) == NULL) + errorp("incompatible types in comparison"); + else + lp = np; + } + if (rp->type->prop&TINTEGER) { + if ((np = convert(rp, lp->type, 0)) == NULL) + errorp("incompatible types in comparison"); + else + rp = np; + } - if ((np = convert(rp, lp->type, 0)) != NULL) - rp = np; - else - errorp("incompatible types in comparison"); return convert(node(op, pvoidtype, lp, rp), inttype, 1); }