aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2024-04-26 18:31:18 -0700
committerMichael Forney <mforney@mforney.org>2024-04-27 02:48:40 -0700
commit186b7095eeb84bec527d6d7ac9320776a8b78734 (patch)
tree5a0da2807e8fa5a1d43aae307dc2316578c936ab /test
parent2b6c69c6b7f9dd4b30f00f3b1d9552c5b1c6077e (diff)
Use hlt to implement noreturn
Diffstat (limited to 'test')
-rw-r--r--test/func-noreturn.c13
-rw-r--r--test/func-noreturn.qbe28
2 files changed, 41 insertions, 0 deletions
diff --git a/test/func-noreturn.c b/test/func-noreturn.c
new file mode 100644
index 0000000..0cd7f7a
--- /dev/null
+++ b/test/func-noreturn.c
@@ -0,0 +1,13 @@
+_Noreturn void exit(int);
+int puts(const char *);
+void _Noreturn f(void) {
+ static int c;
+ while (c)
+ puts("loop");
+}
+int main(void) {
+ exit(0);
+ (*f)();
+ (***f)();
+ return 1;
+}
diff --git a/test/func-noreturn.qbe b/test/func-noreturn.qbe
new file mode 100644
index 0000000..d1771dc
--- /dev/null
+++ b/test/func-noreturn.qbe
@@ -0,0 +1,28 @@
+data $.Lc.2 = align 4 { z 4 }
+data $.Lstring.3 = align 1 { b "loop\000", }
+export
+function $f() {
+@start.1
+@body.2
+@while_cond.3
+ %.1 =w loadw $.Lc.2
+ jnz %.1, @while_body.4, @while_join.5
+@while_body.4
+ %.2 =w call $puts(l $.Lstring.3)
+ jmp @while_cond.3
+@while_join.5
+ hlt
+}
+export
+function w $main() {
+@start.6
+@body.7
+ call $exit(w 0)
+ hlt
+@dead.8
+ call $f()
+ hlt
+@dead.9
+ call $f()
+ hlt
+}