summaryrefslogtreecommitdiff
path: root/test/c
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2006-09-11 16:20:00 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2006-09-11 16:20:00 +0000
commit9d125a3c856d891b234cec1a24264ba72659c18f (patch)
tree7146e10dd1600339dfe5d37c05ea96a5293784e2 /test/c
parentc26b35f57f673a9cef1994bb9da29a63dafce97c (diff)
Ajout du test lists
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@99 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'test/c')
-rw-r--r--test/c/Makefile4
-rw-r--r--test/c/lists.c55
2 files changed, 57 insertions, 2 deletions
diff --git a/test/c/Makefile b/test/c/Makefile
index bcc7cad..b125688 100644
--- a/test/c/Makefile
+++ b/test/c/Makefile
@@ -3,7 +3,7 @@ CFLAGS=-O2 -Wall
CCOMP=../../ccomp
CCOMPFLAGS=-dump-c
-PROGS=fib integr qsort fft sha1 aes almabench
+PROGS=fib integr qsort fft sha1 aes almabench lists
all_s: $(PROGS:%=%.s)
@@ -17,4 +17,4 @@ all: $(PROGS)
clean:
rm -f $(PROGS)
- rm -f *.clight *.s *.o *~
+ rm -f *.light.c *.s *.o *~
diff --git a/test/c/lists.c b/test/c/lists.c
new file mode 100644
index 0000000..c472d72
--- /dev/null
+++ b/test/c/lists.c
@@ -0,0 +1,55 @@
+/* List manipulations */
+
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+struct list { int hd; struct list * tl; };
+
+struct list * buildlist(int n)
+{
+ struct list * r;
+ if (n < 0) return NULL;
+ r = malloc(sizeof(struct list));
+ r->hd = n;
+ r->tl = buildlist(n - 1);
+ return r;
+}
+
+struct list * reverselist (struct list * l)
+{
+ struct list * r, * r2;
+ for (r = NULL; l != NULL; l = l->tl) {
+ r2 = malloc(sizeof(struct list));
+ r2->hd = l->hd;
+ r2->tl = r;
+ r = r2;
+ }
+ return r;
+}
+
+int checklist(int n, struct list * l)
+{
+ int i;
+ for (i = 0; i <= n; i++) {
+ if (l == NULL) return 0;
+ if (l->hd != i) return 0;
+ l = l->tl;
+ }
+ return (l == NULL);
+}
+
+int main(int argc, char ** argv)
+{
+ int n;
+
+ if (argc >= 2) n = atoi(argv[1]); else n = 10;
+ if (checklist(n, reverselist(buildlist(n)))) {
+ printf("OK\n");
+ return 0;
+ } else {
+ printf("Bug!\n");
+ return 2;
+ }
+}
+