scc

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

commit c33ee56f6924c8e0f4a06fd7c1d7e0b457660781
parent 2bc598101275d978b5494d034bd71d8e2b443f4a
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Tue, 24 Mar 2026 09:27:14 +0100

cc1: Fix log value returned by power2node()

The function power2node() can optionally returns the log base 2
of the input parameter. That use case is not currently used, but
the code calculating the log was wrong and produced always 1.
Also, the code was optimized a bit to avoid more tests per bit.

Diffstat:
Msrc/cmd/scc-cc/cc1/expr.c | 11++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/src/cmd/scc-cc/cc1/expr.c b/src/cmd/scc-cc/cc1/expr.c @@ -19,19 +19,16 @@ power2node(Node *np, int *log) return 0; sym = np->sym; - if (sym->type->op != INT) + if (sym->type->op != INT || (u = sym->u.u) == 0) return 0; - n = 0; - for (u = sym->u.u; u; u >>= 1) { - if (u & 1) - n++; - } + for (n = 0; (u & 1) == 0; n++) + u >>= 1; if (log) *log = n; - return n == 1; + return u == 1; } int