From 4f206ac1ea1b20400fa242f2f3be86237c4ba3bf Mon Sep 17 00:00:00 2001 From: Nihal Jere Date: Sat, 27 Apr 2024 14:47:15 -0700 Subject: Implement variable length arrays Variably modified types are required for C23. Since QBE doesn't currently support saving and restoring the stack pointer, a current limitation is that we can't reclaim stack space from VLAs that go out of scope. This is potentially problematic for VLAs appearing in a loop, but this case is uncommon enough that it is silently ignored for now. Implements: https://todo.sr.ht/~mcf/cproc/1 References: https://todo.sr.ht/~mcf/cproc/88 Co-authored-by: Michael Forney --- init.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'init.c') diff --git a/init.c b/init.c index 1a7f5cd..c8f4128 100644 --- a/init.c +++ b/init.c @@ -206,8 +206,12 @@ parseinit(struct scope *s, struct type *t) p.sub->iscur = false; p.init = NULL; p.last = &p.init; - if (t->incomplete && t->kind != TYPEARRAY) - error(&tok.loc, "initializer specified for incomplete type"); + if (t->incomplete) { + if (t->kind != TYPEARRAY) + error(&tok.loc, "initializer specified for incomplete type"); + } else if (t->kind == TYPEARRAY && t->size == 0) { + error(&tok.loc, "initializer specified for variable length array type"); + } for (;;) { if (p.cur) { if (tok.kind == TLBRACK || tok.kind == TPERIOD) -- cgit v1.2.3