diff options
author | Nihal Jere <nihal@nihaljere.xyz> | 2024-04-27 14:47:15 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2024-04-27 15:34:03 -0700 |
commit | 4f206ac1ea1b20400fa242f2f3be86237c4ba3bf (patch) | |
tree | 2dc2742c051e6601874fc699265da40fd51bd5e5 /test/sizeof-vla.c | |
parent | 487079af3d6f39b379f52f7e0ea6edec63587e5b (diff) |
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 <mforney@mforney.org>
Diffstat (limited to 'test/sizeof-vla.c')
-rw-r--r-- | test/sizeof-vla.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/sizeof-vla.c b/test/sizeof-vla.c new file mode 100644 index 0000000..16d6fa1 --- /dev/null +++ b/test/sizeof-vla.c @@ -0,0 +1,19 @@ +int c = 0; +int main(void) { + int r = 0; + int l = 2; + int (*p)[l] = 0; + r += sizeof(c++, p) != sizeof(int (*)[]); /* VM, but not VLA */ + r += c != 0; + r += sizeof(*(c++, p)) != 2 * sizeof(int); /* VLA */ + r += c != 1; + r += sizeof(c++, *p) != sizeof(int *); /* VLA decayed to pointer */ + r += c != 1; + r += sizeof(int[++l]) != 3 * sizeof(int); /* VLA */ + r += l != 3; + r += sizeof(int[++l][1]) != sizeof(int[4][1]); /* VLA */ + r += l != 4; + r += sizeof(int[(c++, 5)]) != 5 * sizeof(int); /* VLA */ + r += c != 2; + return r; +} |