scc

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

commit 5409316c723bf2f0acb020da55474671a3bd8ea9
parent 8ccd9af2728ca27dd8717acd51319cd0c9890904
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed,  4 Jan 2023 22:22:17 +0100

cc1: Update NCONST in aritmetic() with pointers

Pointer operations can generate constant expressions
too.

Diffstat:
Msrc/cmd/cc/cc1/expr.c | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/cmd/cc/cc1/expr.c b/src/cmd/cc/cc1/expr.c @@ -332,6 +332,7 @@ incorrect: static Node * arithmetic(int op, Node *lp, Node *rp) { + Node *np; Type *ltp = lp->type, *rtp = rp->type; if ((ltp->prop & TARITH) && (rtp->prop & TARITH)) { @@ -345,7 +346,10 @@ arithmetic(int op, Node *lp, Node *rp) case OA_SUB: case OINC: case ODEC: - return parithmetic(op, lp, rp); + np = parithmetic(op, lp, rp); + if ((lp->flags&NCONST) && (rp->flags&NCONST)) + np->flags |= NCONST; + return np; } } errorp("incorrect arithmetic operands");