scc

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

commit 30ff9b5f8bc315f859e4b3e282fda9af480ccbd7
parent c4597d8ae1298e3bab5cc694f15d7fca8c721246
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 15 Nov 2021 21:03:04 +0100

cc1: Ensure namespace in array expressions

When the size of an array is calculated we have to ensure that
the namespace if changed to NS_IDEN, because the expression may
use enumeration constants. If the array is declared inside of
a struct the current namespace is the struct namespace and not
NS_IDEN.

Diffstat:
Msrc/cmd/cc/cc1/decl.c | 7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/cmd/cc/cc1/decl.c b/src/cmd/cc/cc1/decl.c @@ -117,7 +117,10 @@ arydcl(struct declarators *dp) { Node *np = NULL; TINT n = 0; + int ns; + ns = namespace; + namespace = NS_IDEN; expect('['); if (yytoken != ']') { if ((np = constexpr()) == NULL) { @@ -130,6 +133,7 @@ arydcl(struct declarators *dp) freetree(np); } } + namespace = ns; expect(']'); push(dp, ARY, n); @@ -773,9 +777,8 @@ structdcl(void) error("too many levels of nested structure or union definitions"); ++nested; - while (yytoken != '}') { + while (yytoken != '}') fieldlist(tp); - } --nested; deftype(tp);