aboutsummaryrefslogtreecommitdiff
path: root/test/builtin-vaarg-vm.c
diff options
context:
space:
mode:
authorNihal Jere <nihal@nihaljere.xyz>2024-04-27 14:47:15 -0700
committerMichael Forney <mforney@mforney.org>2024-04-27 15:34:03 -0700
commit4f206ac1ea1b20400fa242f2f3be86237c4ba3bf (patch)
tree2dc2742c051e6601874fc699265da40fd51bd5e5 /test/builtin-vaarg-vm.c
parent487079af3d6f39b379f52f7e0ea6edec63587e5b (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/builtin-vaarg-vm.c')
-rw-r--r--test/builtin-vaarg-vm.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/builtin-vaarg-vm.c b/test/builtin-vaarg-vm.c
new file mode 100644
index 0000000..aee7216
--- /dev/null
+++ b/test/builtin-vaarg-vm.c
@@ -0,0 +1,16 @@
+int f(int i, ...) {
+ int r, c = 0;
+ __builtin_va_list ap;
+
+ __builtin_va_start(ap, i);
+ r = **__builtin_va_arg(ap, int (*)[++i]);
+ __builtin_va_end(ap);
+ return r + i;
+}
+
+int main(void) {
+ int a[3];
+
+ a[0] = 123;
+ return f(3, &a) != 127;
+}