ref: 4afccc571200034864f9290b902fe6dddff4246e
parent: 41ed50efbfd832c5c4efd7615ac46c798d6ce76d
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Nov 16 03:13:35 EST 2021
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.
--- a/src/cmd/cc/cc1/expr.c
+++ b/src/cmd/cc/cc1/expr.c
@@ -347,15 +347,19 @@
{
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);
}