scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 20b5535ad47415dae9f55e048cb0958be03bb9a1
parent c40ecd533a2317a3db0b29c3ecdc6ffd0d8baeb4
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun,  6 Sep 2015 12:14:42 +0200

Fix problems with identities about &

The ones function was generating more problems, that the
problems it was fixing. At this moment there is a know bug,
because we are not expanding the most significant bit, so
some cases can be missed.

Diffstat:
Mcc1/fold.c | 26+++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/cc1/fold.c b/cc1/fold.c @@ -135,6 +135,16 @@ rshi(TINT l, TINT r, Type *tp) return 1; } +static TUINT +ones(int n) +{ + TUINT v; + + for (v = 1; n--; v |= 1) + v <<= 1; + return v; +} + static bool foldint(int op, Symbol *res, TINT l, TINT r) { @@ -360,20 +370,10 @@ commutative(int *op, Node **lp, Node **rp) aux = l; l = r; r = aux; - *rp = r; - *lp = l; break; } -} - -static TUINT -ones(int n) -{ - TUINT v; - - for (v = 1; n--; v |= 1) - v <<= 1; - return v; + *rp = r; + *lp = l; } static Node * @@ -462,7 +462,7 @@ identity(int *op, Node *lp, Node *rp) return NULL; case OBAND: /* i & ~0 => i */ - if (cmpnode(rp, ones(lp->type->size * 8))) + if (cmpnode(rp, ~0)) goto free_right; return NULL; case OMOD: