aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-02-13 15:28:40 -0800
committerMichael Forney <mforney@mforney.org>2019-02-13 19:42:25 -0800
commita0c394bdd0f0c554f504ee8119e8304551653562 (patch)
treee11fe7fd0679b7a1b47717aed632f918d888c797 /tests
parentabccebea439d961c39e4a6f7d54f72e0b24e9100 (diff)
downloadcproc-a0c394bdd0f0c554f504ee8119e8304551653562.tar.xz
Implement __builtin_va_arg
Diffstat (limited to 'tests')
-rw-r--r--tests/varargs.c12
-rw-r--r--tests/varargs.qbe22
2 files changed, 34 insertions, 0 deletions
diff --git a/tests/varargs.c b/tests/varargs.c
new file mode 100644
index 0000000..0b5a73d
--- /dev/null
+++ b/tests/varargs.c
@@ -0,0 +1,12 @@
+void f(int n, ...) {
+ __builtin_va_list ap;
+
+ __builtin_va_start(ap, n);
+ while (n) {
+ __builtin_va_arg(ap, int);
+ __builtin_va_arg(ap, float);
+ __builtin_va_arg(ap, char *);
+ --n;
+ }
+ __builtin_va_end(ap);
+}
diff --git a/tests/varargs.qbe b/tests/varargs.qbe
new file mode 100644
index 0000000..16db877
--- /dev/null
+++ b/tests/varargs.qbe
@@ -0,0 +1,22 @@
+export
+function $f(w %.1, ...) {
+@start.1
+ %.2 =l alloc4 4
+ storew %.1, %.2
+ %.3 =l alloc8 24
+@body.2
+ vastart %.3
+@while_cond.3
+ %.4 =w loadsw %.2
+ jnz %.4, @while_body.4, @while_join.5
+@while_body.4
+ %.5 =w vaarg %.3
+ %.6 =s vaarg %.3
+ %.7 =l vaarg %.3
+ %.8 =w loadsw %.2
+ %.9 =w sub %.8, 1
+ storew %.9, %.2
+ jmp @while_cond.3
+@while_join.5
+ ret
+}