cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 99d9848603d07114a79093f5fe71d6cf08a606aa
parent 73e7c145e0c5d983cec3be18240851324b818d9f
Author: Michael Forney <mforney@mforney.org>
Date:   Thu, 16 May 2019 00:02:11 -0700

decl: Qualifiers of array type are for element type

Diffstat:
Mdecl.c | 6+++++-
Atest/const-array.c | 5+++++
Atest/const-array.qbe | 10++++++++++
3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/decl.c b/decl.c @@ -416,8 +416,12 @@ done: default: error(&tok.loc, "invalid combination of type specifiers"); } - if (!t && (tq || (sc && *sc) || (fs && *fs))) + if (!t && (tq || sc && *sc || fs && *fs)) error(&tok.loc, "declaration has no type specifier"); + if (t && tq && t->kind == TYPEARRAY) { + t = mkarraytype(t->base, t->qual | tq, t->array.length); + tq = QUALNONE; + } return (struct qualtype){t, tq}; } diff --git a/test/const-array.c b/test/const-array.c @@ -0,0 +1,5 @@ +/* C11 6.7.3p9 - type qualifiers on array type qualify the element type */ +typedef int T[2]; +void f(const T x) { + x = 0; +} diff --git a/test/const-array.qbe b/test/const-array.qbe @@ -0,0 +1,10 @@ +export +function $f(l %.1) { +@start.1 + %.2 =l alloc8 8 + storel %.1, %.2 +@body.2 + %.3 =l extsw 0 + storel %.3, %.2 + ret +}