commit 837e8100c97d4280c0b6c0892afdb05bd0317e7c
parent 5a5db977a8a65fc1cb3656ef55cd579496a377bf
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Sun, 29 Mar 2026 20:21:11 +0200
cc1: Accept static and qualifiers in array params
While they are ignored, at least they are parsed and the (few)
programs using them can be compiled.
Diffstat:
4 files changed, 58 insertions(+), 12 deletions(-)
diff --git a/src/cmd/scc-cc/cc1/decl.c b/src/cmd/scc-cc/cc1/decl.c
@@ -10,10 +10,9 @@
#define NOSCLASS 0
-#define NOREP 0
-#define REP 1
-#define QUIET 1
-#define NOQUIET 0
+#define NOREP 0
+#define REP 1
+#define FUNDCL 2
#define NR_DCL_TYP (NR_DECLARATORS+NR_FUNPARAM)
#define NR_DCL_SYM (NR_DECLARATORS+NR_FUNPARAM+1)
@@ -21,6 +20,7 @@
struct declarators {
unsigned nr;
unsigned ns;
+ unsigned flags;
struct decl *dcl;
unsigned nr_types;
Type **tpars;
@@ -132,11 +132,31 @@ arydcl(struct declarators *dp)
{
Node *np = NULL;
long long n = 0;
- int ns;
+ int isfun, ns;
+
+ isfun = dp->flags & FUNDCL;
ns = namespace;
namespace = NS_IDEN;
expect('[');
+
+ for (;;) {
+ if (yytoken == SCLASS && yylval.token == STATIC) {
+ next();
+ if (!isfun)
+ errorp("static in non-parameter array declarator");
+ continue;
+ }
+
+ if (accept(TQUALIFIER)) {
+ if (!isfun)
+ errorp("type qualifiers in non-parameter array declarator");
+ continue;
+ }
+
+ break;
+ }
+
if (yytoken != ']') {
if ((np = constexpr()) == NULL) {
errorp("invalid storage size");
@@ -449,12 +469,15 @@ ansifun(struct declarators *dp)
errorp("... must be the last parameter");
sym = NULL;
tp = ellipsistype;
- } else if ((sym = dodcl(NOREP, parameter, NS_IDEN, &type)) == NULL) {
- voidpar = 1;
- sym = NULL;
- tp = NULL;
} else {
- tp = sym->type;
+ sym = dodcl(NOREP|FUNDCL, parameter, NS_IDEN, &type);
+ if (sym) {
+ tp = sym->type;
+ } else {
+ voidpar = 1;
+ sym = NULL;
+ tp = NULL;
+ }
}
if (sym) {
@@ -965,8 +988,9 @@ field(struct decl *dcl)
}
static Symbol *
-dodcl(int rep, Symbol *(*fun)(struct decl *), unsigned ns, Type *parent)
+dodcl(int flags, Symbol *(*fun)(struct decl *), unsigned ns, Type *parent)
{
+ int rep = flags & REP;
Symbol *sym;
Type *base;
struct decl dcl;
@@ -984,6 +1008,7 @@ dodcl(int rep, Symbol *(*fun)(struct decl *), unsigned ns, Type *parent)
stack.pars = dcl.bufpars;
stack.dcl = &dcl;
stack.ns = ns;
+ stack.flags = flags;
declarator(&stack);
diff --git a/tests/cc/execute/0102-decl.c b/tests/cc/execute/0102-decl.c
@@ -12,4 +12,6 @@ main(void)
char *p = "Hello, world!";
char *hello[] = {p};
printhello(hello);
+
+ return 0;
}
diff --git a/tests/cc/execute/0256-ary.c b/tests/cc/execute/0256-ary.c
@@ -0,0 +1,18 @@
+int f1(int b[static 3])
+{
+ return b[0] + 1;
+}
+
+int f2(int b[volatile 3])
+{
+ return b[0] + 2;
+}
+
+int
+main(void)
+{
+ int a[10] = {1, 2, 3};
+ int b[10] = {4, 5, 6};
+
+ return !(f1(a) + f2(b) == 8);
+}
diff --git a/tests/cc/execute/scc-tests.lst b/tests/cc/execute/scc-tests.lst
@@ -92,7 +92,7 @@
0097-extern.c
0098-tentative.c
0099-tentative.c
-0102-decl.c [TODO]
+0102-decl.c
0103-voidparm.c
0104-qbebug.c
0105-shl.c
@@ -246,3 +246,4 @@
0253-maxconst.c
0254-litchar.c
0255-init.c
+0256-ary.c