scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 818531121a8b011fd6a977e6d5751b892063f187
parent 6662e4323b9d658de6cf909c16f997515e03d83b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 12 Jan 2017 11:56:33 +0100

[test] Import new tests from Andrew Chambers

Diffstat:
Atests/0082-bug.c | 17+++++++++++++++++
Atests/0083-voidret.c | 13+++++++++++++
Atests/0084-longlong.c | 12++++++++++++
Atests/0085-ulonglong.c | 12++++++++++++
Atests/0086-variadic.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/0087-variadic.c | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/0088-macros.c | 30++++++++++++++++++++++++++++++
Atests/0089-short.c | 12++++++++++++
Atests/0090-fptr.c | 21+++++++++++++++++++++
Atests/0091-fptr.c | 12++++++++++++
Atests/0092-fptr.c | 31+++++++++++++++++++++++++++++++
Atests/0093-arrayinit.c | 15+++++++++++++++
Atests/0094-arrayinit.c | 20++++++++++++++++++++
Atests/0095-arrayselector.c | 23+++++++++++++++++++++++
Atests/0096-inferredarraysize.c | 12++++++++++++
Atests/0097-extern.c | 6++++++
Atests/0098-tentative.c | 23+++++++++++++++++++++++
Atests/0099-tentative.c | 13+++++++++++++
Atests/0100-redeclaremacro.c | 15+++++++++++++++
Atests/0101-wcharlit.c | 6++++++
Atests/0102-bug.c | 14++++++++++++++
Atests/0103-voidparm.c | 12++++++++++++
Atests/0104-voidparm.c | 11+++++++++++
Atests/0105-shl.c | 12++++++++++++
Atests/0106-ppcast.c | 15+++++++++++++++
Atests/0107-bnot.c | 22++++++++++++++++++++++
Atests/0108-bug.c | 13+++++++++++++
Mtests/scc-tests.lst | 22++++++++++++++++++++++
28 files changed, 523 insertions(+), 0 deletions(-)

diff --git a/tests/0082-bug.c b/tests/0082-bug.c @@ -0,0 +1,17 @@ +#define x(y) ((y) + 1) + +int +main() +{ + int x; + int y; + + y = 0; + x = x(y); + + if(x != 1) + return 1; + + return 0; +} + diff --git a/tests/0083-voidret.c b/tests/0083-voidret.c @@ -0,0 +1,13 @@ + +void +voidfn() +{ + return; +} + +int +main() +{ + voidfn(); + return 0; +} diff --git a/tests/0084-longlong.c b/tests/0084-longlong.c @@ -0,0 +1,12 @@ + +int +main() +{ + long long x; + + x = 0; + x = x + 1; + if (x != 1) + return 1; + return 0; +} diff --git a/tests/0085-ulonglong.c b/tests/0085-ulonglong.c @@ -0,0 +1,12 @@ + +int +main() +{ + unsigned long long x; + + x = 0; + x = x + 1; + if (x != 1) + return 1; + return 0; +} diff --git a/tests/0086-variadic.c b/tests/0086-variadic.c @@ -0,0 +1,55 @@ +#define CALL(FUN, ...) FUN(__VA_ARGS__) + +int +none() +{ + return 0; +} + +int +one(int a) +{ + if (a != 1) + return 1; + + return 0; +} + +int +two(int a, int b) +{ + if (a != 1) + return 1; + if (b != 2) + return 1; + + return 0; +} + +int +three(int a, int b, int c) +{ + if (a != 1) + return 1; + if (b != 2) + return 1; + if (c != 3) + return 1; + + return 0; +} + +int +main() +{ + if (CALL(none)) + return 1; + if (CALL(one, 1)) + return 2; + if (CALL(two, 1, 2)) + return 3; + if (CALL(three, 1, 2, 3)) + return 4; + + return 0; +} diff --git a/tests/0087-variadic.c b/tests/0087-variadic.c @@ -0,0 +1,54 @@ +#define ARGS(...) __VA_ARGS__ + +int +none() +{ + return 0; +} + +int +one(int a) +{ + if (a != 1) + return 1; + + return 0; +} + +int +two(int a, int b) +{ + if (a != 1) + return 1; + if (b != 2) + return 1; + + return 0; +} + +int +three(int a, int b, int c) +{ + if (a != 1) + return 1; + if (b != 2) + return 1; + if (c != 3) + return 1; + + return 0; +} + +int +main() +{ + if (none(ARGS())) + return 1; + if (one(ARGS(1))) + return 2; + if (two(ARGS(1, 2))) + return 3; + if (three(ARGS(1, 2, 3))) + return 4; + return 0; +} diff --git a/tests/0088-macros.c b/tests/0088-macros.c @@ -0,0 +1,30 @@ +#define ZERO_0() 0 +#define ZERO_1(A) 0 +#define ZERO_2(A, B) 0 +#define ZERO_VAR(...) 0 +#define ZERO_1_VAR(A, ...) 0 + +int +main() +{ + if (ZERO_0()) + return 1; + if (ZERO_1(1)) + return 1; + if (ZERO_2(1, 2)) + return 1; + if (ZERO_VAR()) + return 1; + if (ZERO_VAR(1)) + return 1; + if (ZERO_VAR(1, 2)) + return 1; + if (ZERO_1_VAR(1)) + return 1; + if (ZERO_1_VAR(1, 2)) + return 1; + if (ZERO_1_VAR(1, 2, 3)) + return 1; + + return 0; +} diff --git a/tests/0089-short.c b/tests/0089-short.c @@ -0,0 +1,12 @@ + +int +main() +{ + short x; + + x = 0; + x = x + 1; + if (x != 1) + return 1; + return 0; +} diff --git a/tests/0090-fptr.c b/tests/0090-fptr.c @@ -0,0 +1,21 @@ + +struct S +{ + int (*fptr)(); +}; + +int +foo() +{ + return 0; +} + +int +main() +{ + struct S v; + + v.fptr = foo; + return v.fptr(); +} + diff --git a/tests/0091-fptr.c b/tests/0091-fptr.c @@ -0,0 +1,12 @@ + +int (*fptr)() = 0; + + +int +main() +{ + if (fptr) + return 1; + return 0; +} + diff --git a/tests/0092-fptr.c b/tests/0092-fptr.c @@ -0,0 +1,31 @@ + +int +zero() +{ + return 0; +} + +struct S +{ + int (*zerofunc)(); +} s = { &zero }; + +struct S * +anon() +{ + return &s; +} + +typedef struct S * (*fty)(); + +fty +go() +{ + return &anon; +} + +int +main() +{ + return go()()->zerofunc(); +} diff --git a/tests/0093-arrayinit.c b/tests/0093-arrayinit.c @@ -0,0 +1,15 @@ + +int a[3] = {0, 1, 2}; + +int +main() +{ + if (a[0] != 0) + return 1; + if (a[1] != 1) + return 2; + if (a[2] != 2) + return 3; + + return 0; +} diff --git a/tests/0094-arrayinit.c b/tests/0094-arrayinit.c @@ -0,0 +1,20 @@ + +typedef struct { + int v; + int sub[2]; +} S; + +S a[1] = {{1, {2, 3}}}; + +int +main() +{ + if (a[0].v != 1) + return 1; + if (a[0].sub[0] != 2) + return 2; + if (a[0].sub[1] != 3) + return 3; + + return 0; +} diff --git a/tests/0095-arrayselector.c b/tests/0095-arrayselector.c @@ -0,0 +1,23 @@ + + + + +int a[] = {5, [2] = 2, 3}; + +int +main() +{ + if (sizeof(a) != 4*sizeof(int)) + return 1; + + if (a[0] != 5) + return 2; + if (a[1] != 0) + return 3; + if (a[2] != 2) + return 4; + if (a[3] != 3) + return 5; + + return 0; +} diff --git a/tests/0096-inferredarraysize.c b/tests/0096-inferredarraysize.c @@ -0,0 +1,12 @@ + + +int a[] = {1, 2, 3, 4}; + +int +main() +{ + if (sizeof(a) != 4*sizeof(int)) + return 1; + + return 0; +} diff --git a/tests/0097-extern.c b/tests/0097-extern.c @@ -0,0 +1,6 @@ +extern int x; + +int main() +{ + return 0; +} diff --git a/tests/0098-tentative.c b/tests/0098-tentative.c @@ -0,0 +1,23 @@ + +int x; +int x = 3; +int x; + +int main(); + +void * +foo() +{ + return &main; +} + +int +main() +{ + if (x != 3) + return 0; + + x = 0; + return x; +} + diff --git a/tests/0099-tentative.c b/tests/0099-tentative.c @@ -0,0 +1,13 @@ + +int x, x = 3, x; + +int +main() +{ + if (x != 3) + return 0; + + x = 0; + return x; +} + diff --git a/tests/0100-redeclaremacro.c b/tests/0100-redeclaremacro.c @@ -0,0 +1,15 @@ + +#define NULL ((void*)0) +#define NULL ((void*)0) + +#define FOO(X, Y) (X + Y + Z) +#define FOO(X, Y) (X + Y + Z) + +#define BAR(X, Y, ...) (X + Y + Z) +#define BAR(X, Y, ...) (X + Y + Z) + +int +main() +{ + return 0; +} diff --git a/tests/0101-wcharlit.c b/tests/0101-wcharlit.c @@ -0,0 +1,6 @@ + +int +main() +{ + return L'\0'; +} diff --git a/tests/0102-bug.c b/tests/0102-bug.c @@ -0,0 +1,14 @@ +// This wouldn't compile + +typedef struct { } Vec; + +static void +vecresize(Vec *v, int cap) +{ + return; +} + +int main() +{ + return 0; +} diff --git a/tests/0103-voidparm.c b/tests/0103-voidparm.c @@ -0,0 +1,12 @@ + +int +foo(void) +{ + return 0; +} + +int +main() +{ + return foo(); +} diff --git a/tests/0104-voidparm.c b/tests/0104-voidparm.c @@ -0,0 +1,11 @@ + +int +main() +{ + int c; + c = 0; + do + ; + while (0); + return c; +} diff --git a/tests/0105-shl.c b/tests/0105-shl.c @@ -0,0 +1,12 @@ + +int +main() +{ + int x; + + x = 1; + if ((x << 1) != 2) + return 1; + + return 0; +} diff --git a/tests/0106-ppcast.c b/tests/0106-ppcast.c @@ -0,0 +1,15 @@ + +int +main() +{ + int x; + void *foo; + void **bar; + + x = 0; + + foo = (void*)&x; + bar = &foo; + + return **(int**)bar; +} diff --git a/tests/0107-bnot.c b/tests/0107-bnot.c @@ -0,0 +1,22 @@ + + +int +main() +{ + int x; + long long l; + + x = 0; + l = 0; + + x = ~x; + if (x != 0xffffffff) + return 1; + + l = ~l; + if (x != 0xffffffffffffffff) + return 2; + + + return 0; +} diff --git a/tests/0108-bug.c b/tests/0108-bug.c @@ -0,0 +1,13 @@ + + +int +main() +{ + int i; + + for(i = 0; i < 10; i++) + if (!i) + continue; + + return 0; +} diff --git a/tests/scc-tests.lst b/tests/scc-tests.lst @@ -77,3 +77,25 @@ 0079-cond.c 0080-arrays.c 0081-calls.c +0082-bug.c +0083-voidret.c +0084-longlong.c +0085-ulonglong.c +0089-short.c +0090-fptr.c +0091-fptr.c +0092-fptr.c +0093-arrayinit.c +0094-arrayinit.c +0095-arrayselector.c +0096-inferredarraysize.c +0097-extern.c +0098-tentative.c +0099-tentative.c +0102-bug.c +0103-voidparm.c +0104-voidparm.c +0105-shl.c +0106-ppcast.c +0107-bnot.c +0108-bug.c