scc

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

commit 4a0c2ccd2a49423967a9f0826bdfc012739327c7
parent eb8960812d92714eb568df36e09d8c76af5cd46c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  7 Oct 2024 17:15:05 +0200

cc1: Reduce to unary for sizeof expressions

The grammar is clear and sizeof applies to a unary expression,
but the code was reducing to a cast expression, creating problems
with expresions like:

	sizeof "hello" - 1

or accepting invalid expressions like:

	sizeof (char *) 3

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

diff --git a/src/cmd/cc/cc1/expr.c b/src/cmd/cc/cc1/expr.c @@ -843,7 +843,7 @@ typeof(Node *np) return tp; } -static Node *cast(void); +static Node *unary(void), *cast(void); static Type * sizeexp(void) @@ -851,7 +851,7 @@ sizeexp(void) Type *tp; if (!accept('(')) - return typeof(cast()); + return typeof(unary()); switch (yytoken) { case TYPE: @@ -859,7 +859,7 @@ sizeexp(void) tp = typename(); break; default: - tp = typeof(cast()); + tp = typeof(unary()); break; } expect(')');