aboutsummaryrefslogtreecommitdiff
path: root/test/func-vla.qbe
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/func-vla.qbe
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/func-vla.qbe')
-rw-r--r--test/func-vla.qbe24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/func-vla.qbe b/test/func-vla.qbe
new file mode 100644
index 0000000..ac3cb9b
--- /dev/null
+++ b/test/func-vla.qbe
@@ -0,0 +1,24 @@
+export
+function w $f(w %.1, l %.3) {
+@start.1
+ %.2 =l alloc4 4
+ storew %.1, %.2
+ %.4 =w loadw %.2
+ %.5 =l extsw %.4
+ %.6 =l mul %.5, 8
+ %.7 =l alloc8 8
+ storel %.3, %.7
+@body.2
+ %.8 =l loadl %.7
+ ret %.6
+}
+export
+function w $main() {
+@start.3
+ %.1 =l alloc8 40
+@body.4
+ %.2 =w call $f(w 5, l %.1)
+ %.3 =l extsw %.2
+ %.4 =w cnel %.3, 40
+ ret %.4
+}