summaryrefslogtreecommitdiff
path: root/test/regression
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2010-03-03 10:22:27 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2010-03-03 10:22:27 +0000
commit891377ce1962cdb31357d6580d6546ec22df2b4f (patch)
tree4ff7c38749cc7a4c1af411c5aa3eb7225c4ae6a1 /test/regression
parent018edf2d81bf94197892cf1df221f7eeac1f96f6 (diff)
Switching to the new C parser/elaborator/simplifier
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1269 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'test/regression')
-rw-r--r--test/regression/Makefile40
-rw-r--r--test/regression/Results/bitfields13
-rw-r--r--test/regression/Results/expr11
-rw-r--r--test/regression/bitfields1.c39
-rw-r--r--test/regression/commaprec.c6
-rw-r--r--test/regression/expr1.c17
-rw-r--r--test/regression/expr2.c8
-rw-r--r--test/regression/expr3.c7
-rw-r--r--test/regression/expr4.c5
-rw-r--r--test/regression/extern1.c8
-rw-r--r--test/regression/funct1.c8
-rw-r--r--test/regression/funct2.c4
-rw-r--r--test/regression/funptr1.c10
-rw-r--r--test/regression/init1.c3
-rw-r--r--test/regression/init2.c8
-rw-r--r--test/regression/init3.c6
-rw-r--r--test/regression/init4.c13
-rw-r--r--test/regression/ptrs1.c1
-rw-r--r--test/regression/ptrs2.c26
-rw-r--r--test/regression/sizeof1.c31
-rw-r--r--test/regression/struct1.c8
-rw-r--r--test/regression/struct2.c4
-rw-r--r--test/regression/struct3.c17
-rw-r--r--test/regression/struct4.c9
-rw-r--r--test/regression/struct5.c43
-rw-r--r--test/regression/struct6.c17
-rw-r--r--test/regression/types1.c15
-rw-r--r--test/regression/varargs1.c18
-rw-r--r--test/regression/volatile1.c9
29 files changed, 384 insertions, 0 deletions
diff --git a/test/regression/Makefile b/test/regression/Makefile
new file mode 100644
index 0000000..2af20e6
--- /dev/null
+++ b/test/regression/Makefile
@@ -0,0 +1,40 @@
+include ../../Makefile.config
+
+CCOMP=../../ccomp
+CCOMPFLAGS=-stdlib ../../runtime -dparse -dclight -dasm -fall-extensions
+
+LIBS=$(LIBMATH)
+
+# Can run and have reference output in Results
+TESTS=bitfields1 expr1 initializers
+
+# Other tests: should compile to .s without errors (but expect warnings)
+EXTRAS=commaprec expr2 expr3 expr4 extern1 funct2 funptr1 init1 \
+ init2 init3 init4 pragmas ptrs1 ptrs2 sizeof1 struct1 struct2 struct3 \
+ struct4 struct5 struct6 types1 volatile1
+
+# Test known to fail
+FAILURES=funct1 varargs1
+
+all_s: $(TESTS:%=%.s) $(EXTRAS:%=%.s)
+
+all: $(TESTS:%=%.compcert) $(EXTRAS:%=%.s)
+
+%.compcert: %.c $(CCOMP)
+ $(CCOMP) $(CCOMPFLAGS) -o $*.compcert $*.c $(LIBS)
+
+%.s: %.c $(CCOMP)
+ $(CCOMP) $(CCOMPFLAGS) -S $*.c
+
+clean:
+ rm -f *.compcert
+ rm -f *.parsed.c *.light.c *.s *.o *~
+
+test_compcert:
+ @for i in $(TESTS); do \
+ if ./$$i.compcert | cmp -s - Results/$$i; \
+ then echo "$$i: passed"; \
+ else echo "$$i: FAILED"; \
+ fi; \
+ done
+
diff --git a/test/regression/Results/bitfields1 b/test/regression/Results/bitfields1
new file mode 100644
index 0000000..3b2bb6a
--- /dev/null
+++ b/test/regression/Results/bitfields1
@@ -0,0 +1,3 @@
+x = {a = -6, b = 2 }
+y = {c = 12345, d = 1, e = 89 }
+f returns 12434
diff --git a/test/regression/Results/expr1 b/test/regression/Results/expr1
new file mode 100644
index 0000000..dc49203
--- /dev/null
+++ b/test/regression/Results/expr1
@@ -0,0 +1 @@
+Result: 0x0
diff --git a/test/regression/bitfields1.c b/test/regression/bitfields1.c
new file mode 100644
index 0000000..c6022dd
--- /dev/null
+++ b/test/regression/bitfields1.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+
+struct s {
+ signed char a: 6;
+ unsigned int b: 2;
+};
+
+struct t {
+ unsigned int c: 16;
+ unsigned int d: 1;
+ short e: 8;
+};
+
+int f(struct s * x, struct t * y, int z)
+{
+ x->a += x->b;
+ y->d = z;
+ return y->c + y->e;
+}
+
+int main()
+{
+ struct s x;
+ struct t y;
+ int res;
+
+ x.a = 56;
+ x.b = 2;
+ y.c = 12345;
+ y.d = 0;
+ y.e = 89;
+ res = f(&x, &y, 1);
+
+ printf("x = {a = %d, b = %d }\n", x.a, x.b);
+ printf("y = {c = %d, d = %d, e = %d }\n", y.c, y.d, y.e);
+ printf("f returns %d\n", res);
+
+ return 0;
+}
diff --git a/test/regression/commaprec.c b/test/regression/commaprec.c
new file mode 100644
index 0000000..aa18eda
--- /dev/null
+++ b/test/regression/commaprec.c
@@ -0,0 +1,6 @@
+extern int f(int, int);
+
+int g(int y) {
+ int z = (y++, 0);
+ return f((z = 1, z), y+2);
+}
diff --git a/test/regression/expr1.c b/test/regression/expr1.c
new file mode 100644
index 0000000..0cc7b54
--- /dev/null
+++ b/test/regression/expr1.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+struct list { int hd; struct list * tl; };
+
+struct list * f(struct list ** p)
+{
+ return ((*p)->tl = 0);
+}
+
+int main(int argc, char ** argv)
+{
+ struct list l;
+ l.tl = &l;
+ f(&(l.tl));
+ printf("Result: %p\n", l.tl);
+ return 0;
+}
diff --git a/test/regression/expr2.c b/test/regression/expr2.c
new file mode 100644
index 0000000..66c563f
--- /dev/null
+++ b/test/regression/expr2.c
@@ -0,0 +1,8 @@
+extern int f(int);
+
+void g(int x)
+{
+ if (x > 0) {
+ (void) f(x - 1);
+ }
+}
diff --git a/test/regression/expr3.c b/test/regression/expr3.c
new file mode 100644
index 0000000..9b696e5
--- /dev/null
+++ b/test/regression/expr3.c
@@ -0,0 +1,7 @@
+/* Array decay in && */
+
+struct s {
+ int a[1];
+};
+
+int f(struct s * x) { return x && x->a; }
diff --git a/test/regression/expr4.c b/test/regression/expr4.c
new file mode 100644
index 0000000..ad86eae
--- /dev/null
+++ b/test/regression/expr4.c
@@ -0,0 +1,5 @@
+/* Warning, not error */
+
+#define NULL ((void *) 0)
+
+int f(int x) { return x == NULL; }
diff --git a/test/regression/extern1.c b/test/regression/extern1.c
new file mode 100644
index 0000000..86def95
--- /dev/null
+++ b/test/regression/extern1.c
@@ -0,0 +1,8 @@
+int x = 5;
+int f() {
+ int x = 3;
+ {
+ extern int x;
+ return x;
+ }
+}
diff --git a/test/regression/funct1.c b/test/regression/funct1.c
new file mode 100644
index 0000000..1e26803
--- /dev/null
+++ b/test/regression/funct1.c
@@ -0,0 +1,8 @@
+int f() { return 0; }
+
+int g(void) { return f(1); }
+
+int h(x, y) int x, y; { return x + y; }
+
+int k(void) { return h(1); }
+
diff --git a/test/regression/funct2.c b/test/regression/funct2.c
new file mode 100644
index 0000000..6b648c7
--- /dev/null
+++ b/test/regression/funct2.c
@@ -0,0 +1,4 @@
+extern int f(int x);
+
+double g(int x) { return 3.14 * f(x); }
+
diff --git a/test/regression/funptr1.c b/test/regression/funptr1.c
new file mode 100644
index 0000000..9bb7046
--- /dev/null
+++ b/test/regression/funptr1.c
@@ -0,0 +1,10 @@
+int (*pf)(void);
+int f(void) {
+
+ pf = &f; // This looks ok
+ pf = ***f; // Dereference a function?
+ pf(); // Invoke a function pointer?
+ (****pf)(); // Looks strange but Ok
+ (***************f)(); // Also Ok
+ return 0;
+}
diff --git a/test/regression/init1.c b/test/regression/init1.c
new file mode 100644
index 0000000..ea9db0f
--- /dev/null
+++ b/test/regression/init1.c
@@ -0,0 +1,3 @@
+/* Initializer can refer to ident just declared */
+
+struct list { int hd; struct list * tl; } circular = { sizeof(circular), &circular };
diff --git a/test/regression/init2.c b/test/regression/init2.c
new file mode 100644
index 0000000..400bd94
--- /dev/null
+++ b/test/regression/init2.c
@@ -0,0 +1,8 @@
+/* Initialization of local const array */
+
+int f(int x)
+{
+ const int dfl = 2;
+ const int tbl[3] = { 12, 34, 56 };
+ return tbl[x >= 0 && x < 3 ? x : dfl];
+}
diff --git a/test/regression/init3.c b/test/regression/init3.c
new file mode 100644
index 0000000..00a36e2
--- /dev/null
+++ b/test/regression/init3.c
@@ -0,0 +1,6 @@
+/* Warning, not error */
+
+#define NULL ((void *) 0)
+
+char x = NULL;
+int t[2] = { NULL, NULL };
diff --git a/test/regression/init4.c b/test/regression/init4.c
new file mode 100644
index 0000000..02b0bd5
--- /dev/null
+++ b/test/regression/init4.c
@@ -0,0 +1,13 @@
+/* C99-style initializers in the middle of a block */
+
+int g(int x) { return x << 2; }
+
+int f(int x, int y)
+{
+ int a = x + y;
+ {
+ y++;
+ int b = y - g(x);
+ return b * a;
+ }
+}
diff --git a/test/regression/ptrs1.c b/test/regression/ptrs1.c
new file mode 100644
index 0000000..3585a8f
--- /dev/null
+++ b/test/regression/ptrs1.c
@@ -0,0 +1 @@
+const char * f(char * p, const char * q) { return p == q ? p : q; }
diff --git a/test/regression/ptrs2.c b/test/regression/ptrs2.c
new file mode 100644
index 0000000..0b66ed2
--- /dev/null
+++ b/test/regression/ptrs2.c
@@ -0,0 +1,26 @@
+#include <stdlib.h>
+
+typedef double Matrix[4][4];
+
+Matrix * CopyMatrix(Matrix * Mat) {
+ int i,j;
+ Matrix * Res = NULL;
+ if (Mat == 0) return Mat;
+ Res = malloc(sizeof(Matrix));
+ for(i=0;i<4;i++){
+ for(j=0;j<4;j++){
+ (*Res)[i][j] = (*Mat)[i][j];
+ }
+ }
+ return Res;
+}
+
+Matrix * IdentMatrix(void)
+{
+ Matrix SI = { { 1.00, 0.00, 0.00, 0.00 },
+ { 0.00, 1.00, 0.00, 0.00 },
+ { 0.00, 0.00, 1.00, 0.00 },
+ { 0.00, 0.00, 0.00, 1.00 }};
+ return CopyMatrix(&SI);
+}
+
diff --git a/test/regression/sizeof1.c b/test/regression/sizeof1.c
new file mode 100644
index 0000000..e8441a2
--- /dev/null
+++ b/test/regression/sizeof1.c
@@ -0,0 +1,31 @@
+struct s {
+ char c;
+ union { int i[3]; double d; } n;
+ struct { struct s * hd; struct s * tl; } l;
+};
+
+char tbl[sizeof(struct s)];
+/* Should be 32:
+ char c at 0
+ union n at 8 because alignment = 8; sizeof = 12
+ struct l at 8+12=20 with alignment = 4; sizeof = 8
+ end of struct at 20+8=28
+ alignment of whole struct is 8 because of d
+ 28 aligned to 8 -> 32
+*/
+
+struct bits1 {
+ unsigned a: 1;
+ unsigned b: 6;
+};
+
+char b1[sizeof(struct bits1)]; /* should be 1 */
+
+struct bits2 {
+ unsigned a: 1;
+ unsigned b: 6;
+ unsigned c: 28;
+};
+
+char b2[sizeof(struct bits2)]; /* should be 8 */
+
diff --git a/test/regression/struct1.c b/test/regression/struct1.c
new file mode 100644
index 0000000..2203fe7
--- /dev/null
+++ b/test/regression/struct1.c
@@ -0,0 +1,8 @@
+struct s;
+
+struct s { int x; double y; };
+
+struct s my_s;
+
+double f(struct s * a) { return a->y; }
+
diff --git a/test/regression/struct2.c b/test/regression/struct2.c
new file mode 100644
index 0000000..10437e2
--- /dev/null
+++ b/test/regression/struct2.c
@@ -0,0 +1,4 @@
+struct B;
+int f(struct B);
+struct B { double d; };
+int g() { struct B b; return f(b); }
diff --git a/test/regression/struct3.c b/test/regression/struct3.c
new file mode 100644
index 0000000..e98bf12
--- /dev/null
+++ b/test/regression/struct3.c
@@ -0,0 +1,17 @@
+int f() {
+ {
+ struct B;
+ struct B { double d; };
+ {
+ struct B;
+ extern void bar(struct B d);
+ struct B {
+ int k;
+ short h;
+ };
+ struct B p = { 1, 2};
+ bar(p);
+ }
+ }
+ return 0;
+}
diff --git a/test/regression/struct4.c b/test/regression/struct4.c
new file mode 100644
index 0000000..8cb3c19
--- /dev/null
+++ b/test/regression/struct4.c
@@ -0,0 +1,9 @@
+struct obj {
+ int tag;
+ union {
+ struct { struct obj * car, * cdr; } cons;
+ struct { char * name; struct obj * plist; } atom;
+ } u;
+};
+
+struct obj some_obj;
diff --git a/test/regression/struct5.c b/test/regression/struct5.c
new file mode 100644
index 0000000..13a1aa5
--- /dev/null
+++ b/test/regression/struct5.c
@@ -0,0 +1,43 @@
+typedef struct HPointStruct
+{
+ double x;
+ double y;
+ double z;
+ double w;
+}HPoint;
+
+typedef struct ObjPointStruct
+{
+ double x;
+ double y;
+ double z;
+ double tx;
+ double ty;
+ double tz;
+}ObjPoint;
+
+HPoint PointToHPoint(ObjPoint P);
+
+HPoint PointToHPoint(ObjPoint P)
+{
+ HPoint res;
+ res.x = P.x;
+ res.y = P.y;
+ res.z = P.z;
+ res.w = 1;
+ return res;
+}
+
+double test1(HPoint (*f)(ObjPoint), double x)
+{
+ ObjPoint P;
+ HPoint HP;
+ P.x = x;
+ HP = f(P);
+ return HP.x;
+}
+
+double test2(double x)
+{
+ return test1(PointToHPoint, x);
+}
diff --git a/test/regression/struct6.c b/test/regression/struct6.c
new file mode 100644
index 0000000..d8d9cc9
--- /dev/null
+++ b/test/regression/struct6.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+struct value {
+ int tag;
+ union {
+ int i;
+ double r;
+ char * sl;
+ } u;
+};
+
+void print_value(struct value * s)
+{
+ printf ("%d\n", s->u.i);
+}
+
+
diff --git a/test/regression/types1.c b/test/regression/types1.c
new file mode 100644
index 0000000..c05e30d
--- /dev/null
+++ b/test/regression/types1.c
@@ -0,0 +1,15 @@
+/* Printing of modifiers */
+
+typedef struct vba_version_tag {
+ unsigned char signature[4];
+ const char *name;
+ int is_mac;
+} vba_version_t;
+
+static const vba_version_t vba_version[10];
+
+int f(int x)
+{
+ return sizeof(vba_version[0].signature);
+}
+
diff --git a/test/regression/varargs1.c b/test/regression/varargs1.c
new file mode 100644
index 0000000..99dba39
--- /dev/null
+++ b/test/regression/varargs1.c
@@ -0,0 +1,18 @@
+#include <stdarg.h>
+
+int sum_v(int n, va_list ap)
+{
+ int i, s;
+ for (i = 0, s = 0; i < n; i++) s += va_arg(ap, int);
+ return s;
+}
+
+int sum_l(int n, ...)
+{
+ va_list ap;
+ int s;
+ va_start(ap, n);
+ s = sum_v(n, ap);
+ va_end(ap);
+ return s;
+}
diff --git a/test/regression/volatile1.c b/test/regression/volatile1.c
new file mode 100644
index 0000000..3818c23
--- /dev/null
+++ b/test/regression/volatile1.c
@@ -0,0 +1,9 @@
+volatile int v;
+
+int f1(void) { return v; }
+
+int f2(void) { return v++; }
+
+int f3(void) {return v / v + 1 + v; }
+
+void f4(void) { v; }