scc

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

commit bce4640e225094e43c4dd1c6a151abeb0dd3703f
parent c14d021feb8a7aaceaa959ad5d85c690299c67ee
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  3 Nov 2022 07:00:35 +0100

cc1: Accept OSYM null constants

There are some conditions where the null expression is folded
into a OSYM node where the cast was already removed.

Diffstat:
Msrc/cmd/cc/cc1/expr.c | 15++++++++++-----
Mtests/cc/execute/0158-ternary.c | 2++
2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/cmd/cc/cc1/expr.c b/src/cmd/cc/cc1/expr.c @@ -115,14 +115,19 @@ set_p1_p2: static int null(Node *np) { - if (np->type != pvoidtype || np->op != OCAST) + if (np->type != pvoidtype) return 0; - np = np->left; - if (np->type != inttype) + switch (np->op) { + case OCAST: + np = np->left; + if (np->type != inttype) + return 0; + case OSYM: + return cmpnode(np, 0); + default: return 0; - - return cmpnode(np, 0); + } } static Node * diff --git a/tests/cc/execute/0158-ternary.c b/tests/cc/execute/0158-ternary.c @@ -2,12 +2,14 @@ int main(void) { int i = 0, *q; + unsigned char *bp; void *p; i = i ? 0 : 0l; p = i ? (void *) 0 : 0; p = i ? 0 : (void *) 0; p = i ? 0 : (const void *) 0; + p = i ? (void *) 0 : bp-1; q = i ? 0 : p; q = i ? p : 0; q = i ? q : 0;