From 0e1a2a18ac7056e7fe3a033b664e6ecb8faba651 Mon Sep 17 00:00:00 2001 From: lemon Date: Thu, 19 Mar 2026 20:02:09 +0100 Subject: c: fix qualifiers for array declarators `const int x[]` was being treated as `const int x[const]`, which is wrong, and matters when `x` is a function parameter that really decays to a pointer (`int const *const x`) --- src/c.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/c.c b/src/c.c index 92f917e..c8a040b 100644 --- a/src/c.c +++ b/src/c.c @@ -2525,8 +2525,10 @@ static struct DeclList { DeclList *prev, *next; uchar t; /* TYPTR, TYARRAY or TYFUNC */ union { - uchar qual; /* TYPTR */ - Expr count; /* TYARRAY */ + struct { + uchar qual; /* TYPTR, TYARRAY */ + Expr count; /* TYARRAY */ + }; struct { /* TYFUNC */ Type *param; internstr *pnames; @@ -2623,14 +2625,14 @@ decltypes(CComp *cm, DeclList *list, internstr *name, Span *span, Span *namespan for (;;) { if (match(cm, &tk, '[')) { node.span = tk.span; - int q = 0; + node.qual = 0; bool statik = 0; if (in_range(peek(cm, &tk), TKWBEGIN_, TKWEND_)) { - q = cvqual(cm); + node.qual = cvqual(cm); statik = match(cm, NULL, TKWstatic); - q |= cvqual(cm); + node.qual |= cvqual(cm); } - (void)q, (void)statik; /* stub */ + (void)statik; /* stub */ if (match(cm, &tk, ']')) { node.count.t = EARRAYUNSIZED; @@ -2727,7 +2729,7 @@ static Decl declarator(DeclState *st, CComp *cm, Span span0) { Decl decl = { st->base, st->scls, .qual = st->qual, .span = span0 }; DeclList list = { &list, &list }, *l; - Span namespan ={0}; + Span namespan = {0}; static bool inidecltmp; if (!inidecltmp) { inidecltmp = 1; @@ -2776,6 +2778,7 @@ declarator(DeclState *st, CComp *cm, Span span0) { } decl.ty = mkarrtype(decl.ty, decl.qual, n); } + decl.qual = l->qual; break; case TYFUNC: if (decl.ty.t == TYFUNC) -- cgit v1.2.3