From 891377ce1962cdb31357d6580d6546ec22df2b4f Mon Sep 17 00:00:00 2001 From: xleroy Date: Wed, 3 Mar 2010 10:22:27 +0000 Subject: 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 --- test/regression/Makefile | 40 +++++++++++++++++++++++++++++++++++ test/regression/Results/bitfields1 | 3 +++ test/regression/Results/expr1 | 1 + test/regression/bitfields1.c | 39 ++++++++++++++++++++++++++++++++++ test/regression/commaprec.c | 6 ++++++ test/regression/expr1.c | 17 +++++++++++++++ test/regression/expr2.c | 8 +++++++ test/regression/expr3.c | 7 +++++++ test/regression/expr4.c | 5 +++++ test/regression/extern1.c | 8 +++++++ test/regression/funct1.c | 8 +++++++ test/regression/funct2.c | 4 ++++ test/regression/funptr1.c | 10 +++++++++ test/regression/init1.c | 3 +++ test/regression/init2.c | 8 +++++++ test/regression/init3.c | 6 ++++++ test/regression/init4.c | 13 ++++++++++++ test/regression/ptrs1.c | 1 + test/regression/ptrs2.c | 26 +++++++++++++++++++++++ test/regression/sizeof1.c | 31 +++++++++++++++++++++++++++ test/regression/struct1.c | 8 +++++++ test/regression/struct2.c | 4 ++++ test/regression/struct3.c | 17 +++++++++++++++ test/regression/struct4.c | 9 ++++++++ test/regression/struct5.c | 43 ++++++++++++++++++++++++++++++++++++++ test/regression/struct6.c | 17 +++++++++++++++ test/regression/types1.c | 15 +++++++++++++ test/regression/varargs1.c | 18 ++++++++++++++++ test/regression/volatile1.c | 9 ++++++++ 29 files changed, 384 insertions(+) create mode 100644 test/regression/Makefile create mode 100644 test/regression/Results/bitfields1 create mode 100644 test/regression/Results/expr1 create mode 100644 test/regression/bitfields1.c create mode 100644 test/regression/commaprec.c create mode 100644 test/regression/expr1.c create mode 100644 test/regression/expr2.c create mode 100644 test/regression/expr3.c create mode 100644 test/regression/expr4.c create mode 100644 test/regression/extern1.c create mode 100644 test/regression/funct1.c create mode 100644 test/regression/funct2.c create mode 100644 test/regression/funptr1.c create mode 100644 test/regression/init1.c create mode 100644 test/regression/init2.c create mode 100644 test/regression/init3.c create mode 100644 test/regression/init4.c create mode 100644 test/regression/ptrs1.c create mode 100644 test/regression/ptrs2.c create mode 100644 test/regression/sizeof1.c create mode 100644 test/regression/struct1.c create mode 100644 test/regression/struct2.c create mode 100644 test/regression/struct3.c create mode 100644 test/regression/struct4.c create mode 100644 test/regression/struct5.c create mode 100644 test/regression/struct6.c create mode 100644 test/regression/types1.c create mode 100644 test/regression/varargs1.c create mode 100644 test/regression/volatile1.c (limited to 'test/regression') diff --git a/test/regression/Makefile b/test/regression/Makefile new file mode 100644 index 00000000..2af20e62 --- /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 00000000..3b2bb6a0 --- /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 00000000..dc492037 --- /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 00000000..c6022dd1 --- /dev/null +++ b/test/regression/bitfields1.c @@ -0,0 +1,39 @@ +#include + +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 00000000..aa18eda5 --- /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 00000000..0cc7b540 --- /dev/null +++ b/test/regression/expr1.c @@ -0,0 +1,17 @@ +#include + +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 00000000..66c563f2 --- /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 00000000..9b696e5d --- /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 00000000..ad86eaed --- /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 00000000..86def95c --- /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 00000000..1e26803e --- /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 00000000..6b648c75 --- /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 00000000..9bb7046d --- /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 00000000..ea9db0f9 --- /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 00000000..400bd94c --- /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 00000000..00a36e28 --- /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 00000000..02b0bd5e --- /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 00000000..3585a8fb --- /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 00000000..0b66ed2c --- /dev/null +++ b/test/regression/ptrs2.c @@ -0,0 +1,26 @@ +#include + +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 00000000..e8441a2c --- /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 00000000..2203fe76 --- /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 00000000..10437e2d --- /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 00000000..e98bf12a --- /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 00000000..8cb3c19d --- /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 00000000..13a1aa5c --- /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 00000000..d8d9cc93 --- /dev/null +++ b/test/regression/struct6.c @@ -0,0 +1,17 @@ +#include + +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 00000000..c05e30d8 --- /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 00000000..99dba39a --- /dev/null +++ b/test/regression/varargs1.c @@ -0,0 +1,18 @@ +#include + +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 00000000..3818c238 --- /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; } -- cgit