[hackers] [scc] Add test suite from https://github.com/andrewchambers/qc || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 20 Jun 2016 18:14:01 +0200 (CEST)

commit c64e4d4f07ef51d170230a44b1661b249475e162
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Mon Jun 20 18:11:38 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Mon Jun 20 18:11:38 2016 +0200

    Add test suite from https://github.com/andrewchambers/qc

diff --git a/tests/0001-sanity.c b/tests/0001-sanity.c
new file mode 100644
index 0000000..d659c45
--- /dev/null
+++ b/tests/0001-sanity.c
_AT_@ -0,0 +1,6 @@
+
+int
+main()
+{
+ return 0;
+}
diff --git a/tests/0002-expr.c b/tests/0002-expr.c
new file mode 100644
index 0000000..75b8616
--- /dev/null
+++ b/tests/0002-expr.c
_AT_@ -0,0 +1,6 @@
+
+int
+main()
+{
+ return 3-3;
+}
diff --git a/tests/0003-local.c b/tests/0003-local.c
new file mode 100644
index 0000000..894d770
--- /dev/null
+++ b/tests/0003-local.c
_AT_@ -0,0 +1,10 @@
+
+
+int
+main()
+{
+ int x;
+
+ x = 4;
+ return x - 4;
+}
diff --git a/tests/0004-pointer.c b/tests/0004-pointer.c
new file mode 100644
index 0000000..d5d471a
--- /dev/null
+++ b/tests/0004-pointer.c
_AT_@ -0,0 +1,14 @@
+
+
+int
+main()
+{
+ int x;
+ int *p;
+
+ x = 4;
+ p = &x;
+ *p = 0;
+
+ return *p;
+}
diff --git a/tests/0005-ifstmt.c b/tests/0005-ifstmt.c
new file mode 100644
index 0000000..2122c45
--- /dev/null
+++ b/tests/0005-ifstmt.c
_AT_@ -0,0 +1,24 @@
+
+int
+main()
+{
+ int x;
+ int *p;
+ int **pp;
+
+ x = 0;
+ p = &x;
+ pp = &p;
+
+ if(*p)
+ return 1;
+ if(**pp)
+ return 1;
+ else
+ **pp = 1;
+
+ if(x)
+ return 0;
+ else
+ return 1;
+}
diff --git a/tests/0006-whilestmt.c b/tests/0006-whilestmt.c
new file mode 100644
index 0000000..bc2068e
--- /dev/null
+++ b/tests/0006-whilestmt.c
_AT_@ -0,0 +1,11 @@
+
+int
+main()
+{
+ int x;
+
+ x = 50;
+ while (x)
+ x = x - 1;
+ return x;
+}
diff --git a/tests/0007-forstmt.c b/tests/0007-forstmt.c
new file mode 100644
index 0000000..99466ef
--- /dev/null
+++ b/tests/0007-forstmt.c
_AT_@ -0,0 +1,16 @@
+
+int
+main()
+{
+ int x;
+
+ x = 1;
+ for(x = 10; x; x = x - 1)
+ ;
+ if(x)
+ return 1;
+ x = 10;
+ for (;x;)
+ x = x - 1;
+ return x;
+}
diff --git a/tests/0008-dowhilestmt.c b/tests/0008-dowhilestmt.c
new file mode 100644
index 0000000..ecde256
--- /dev/null
+++ b/tests/0008-dowhilestmt.c
_AT_@ -0,0 +1,12 @@
+
+int
+main()
+{
+ int x;
+
+ x = 50;
+ do
+ x = x - 1;
+ while(x);
+ return x;
+}
diff --git a/tests/0009-expr.c b/tests/0009-expr.c
new file mode 100644
index 0000000..f9a3509
--- /dev/null
+++ b/tests/0009-expr.c
_AT_@ -0,0 +1,12 @@
+
+int
+main()
+{
+ int x;
+
+ x = 1;
+ x = x * 10;
+ x = x / 2;
+ x = x % 3;
+ return x - 2;
+}
diff --git a/tests/0010-goto.c b/tests/0010-goto.c
new file mode 100644
index 0000000..d5bfbbf
--- /dev/null
+++ b/tests/0010-goto.c
_AT_@ -0,0 +1,13 @@
+int
+main()
+{
+ start:
+ goto next;
+ return 1;
+ success:
+ return 0;
+ next:
+ foo:
+ goto success;
+ return 1;
+}
diff --git a/tests/0011-assign.c b/tests/0011-assign.c
new file mode 100644
index 0000000..831ebeb
--- /dev/null
+++ b/tests/0011-assign.c
_AT_@ -0,0 +1,9 @@
+
+int
+main()
+{
+ int x;
+ int y;
+ x = y = 0;
+ return x;
+}
diff --git a/tests/0012-expr.c b/tests/0012-expr.c
new file mode 100644
index 0000000..654dc11
--- /dev/null
+++ b/tests/0012-expr.c
_AT_@ -0,0 +1,6 @@
+
+int
+main()
+{
+ return (2 + 2) * 2 - 8;
+}
diff --git a/tests/0013-addridx.c b/tests/0013-addridx.c
new file mode 100644
index 0000000..1e51a0e
--- /dev/null
+++ b/tests/0013-addridx.c
_AT_@ -0,0 +1,11 @@
+
+int
+main()
+{
+ int x;
+ int *p;
+
+ x = 0;
+ p = &x;
+ return p[0];
+}
diff --git a/tests/0014-assignidx.c b/tests/0014-assignidx.c
new file mode 100644
index 0000000..3b11891
--- /dev/null
+++ b/tests/0014-assignidx.c
_AT_@ -0,0 +1,12 @@
+
+int
+main()
+{
+ int x;
+ int *p;
+
+ x = 1;
+ p = &x;
+ p[0] = 0;
+ return x;
+}
diff --git a/tests/0015-localarray.c b/tests/0015-localarray.c
new file mode 100644
index 0000000..fef1794
--- /dev/null
+++ b/tests/0015-localarray.c
_AT_@ -0,0 +1,11 @@
+
+int
+main()
+{
+ int arr[2];
+
+ arr[0] = 1;
+ arr[1] = 2;
+
+ return arr[0] + arr[1] - 3;
+}
diff --git a/tests/0016-addrarray.c b/tests/0016-addrarray.c
new file mode 100644
index 0000000..9db7edb
--- /dev/null
+++ b/tests/0016-addrarray.c
_AT_@ -0,0 +1,10 @@
+int
+main()
+{
+ int arr[2];
+ int *p;
+
+ p = &arr[1];
+ *p = 0;
+ return arr[1];
+}
diff --git a/tests/0017-struct.c b/tests/0017-struct.c
new file mode 100644
index 0000000..d74481b
--- /dev/null
+++ b/tests/0017-struct.c
_AT_@ -0,0 +1,11 @@
+
+
+int
+main()
+{
+ struct { int x; int y; } s;
+
+ s.x = 3;
+ s.y = 5;
+ return s.y - s.x - 2;
+}
diff --git a/tests/0018-structptr.c b/tests/0018-structptr.c
new file mode 100644
index 0000000..58b6b5d
--- /dev/null
+++ b/tests/0018-structptr.c
_AT_@ -0,0 +1,15 @@
+
+
+int
+main()
+{
+
+ struct S { int x; int y; } s;
+ struct S *p;
+
+ p = &s;
+ s.x = 1;
+ p->y = 2;
+ return p->y + p->x - 3;
+}
+
diff --git a/tests/0019-selfrefstruct.c b/tests/0019-selfrefstruct.c
new file mode 100644
index 0000000..768c36f
--- /dev/null
+++ b/tests/0019-selfrefstruct.c
_AT_@ -0,0 +1,11 @@
+
+int
+main()
+{
+ struct S { struct S *p; int x; } s;
+
+ s.x = 0;
+ s.p = &s;
+ return s.p->p->p->p->p->x;
+}
+
diff --git a/tests/0020-ptrptr.c b/tests/0020-ptrptr.c
new file mode 100644
index 0000000..4209c90
--- /dev/null
+++ b/tests/0020-ptrptr.c
_AT_@ -0,0 +1,11 @@
+
+int
+main()
+{
+ int x, *p, **pp;
+
+ x = 0;
+ p = &x;
+ pp = &p;
+ return **pp;
+}
diff --git a/tests/0021-intfunc.c b/tests/0021-intfunc.c
new file mode 100644
index 0000000..9633851
--- /dev/null
+++ b/tests/0021-intfunc.c
_AT_@ -0,0 +1,13 @@
+
+int
+foo(int a, int b)
+{
+ return 2 + a - b;
+}
+
+int
+main()
+{
+ return foo(1, 3);
+}
+
diff --git a/tests/0022-typedef.c b/tests/0022-typedef.c
new file mode 100644
index 0000000..81fd3b1
--- /dev/null
+++ b/tests/0022-typedef.c
_AT_@ -0,0 +1,11 @@
+
+typedef int x;
+
+int
+main()
+{
+ x v;
+ v = 0;
+ return v;
+}
+
diff --git a/tests/0023-global.c b/tests/0023-global.c
new file mode 100644
index 0000000..f058f49
--- /dev/null
+++ b/tests/0023-global.c
_AT_@ -0,0 +1,10 @@
+
+int x;
+
+int
+main()
+{
+ x = 0;
+ return x;
+}
+
diff --git a/tests/0024-typedefstruct.c b/tests/0024-typedefstruct.c
new file mode 100644
index 0000000..67e6ed8
--- /dev/null
+++ b/tests/0024-typedefstruct.c
_AT_@ -0,0 +1,13 @@
+
+typedef struct { int x; int y; } s;
+
+s v;
+
+int
+main()
+{
+ v.x = 1;
+ v.y = 2;
+ return 3 - v.x - v.y;
+}
+
diff --git a/tests/0025-string.c b/tests/0025-string.c
new file mode 100644
index 0000000..4b2ae82
--- /dev/null
+++ b/tests/0025-string.c
_AT_@ -0,0 +1,11 @@
+
+int strlen(char *);
+
+int
+main()
+{
+ char *p;
+
+ p = "hello";
+ return strlen(p) - 5;
+}
diff --git a/tests/0026-implicitret.c b/tests/0026-implicitret.c
new file mode 100644
index 0000000..0867241
--- /dev/null
+++ b/tests/0026-implicitret.c
_AT_@ -0,0 +1,6 @@
+
+main()
+{
+ return 0;
+}
+
diff --git a/tests/0027-charval.c b/tests/0027-charval.c
new file mode 100644
index 0000000..2f6d40a
--- /dev/null
+++ b/tests/0027-charval.c
_AT_@ -0,0 +1,9 @@
+
+int
+main()
+{
+ char *p;
+
+ p = "hello";
+ return p[0] - 104;
+}
diff --git a/tests/0028-bor.c b/tests/0028-bor.c
new file mode 100644
index 0000000..92beb1f
--- /dev/null
+++ b/tests/0028-bor.c
_AT_@ -0,0 +1,11 @@
+
+int
+main()
+{
+ int x;
+
+ x = 1;
+ x = x | 4;
+ return x - 5;
+}
+
diff --git a/tests/0029-band.c b/tests/0029-band.c
new file mode 100644
index 0000000..53e264e
--- /dev/null
+++ b/tests/0029-band.c
_AT_@ -0,0 +1,11 @@
+
+int
+main()
+{
+ int x;
+
+ x = 1;
+ x = x & 3;
+ return x - 1;
+}
+
diff --git a/tests/0030-bxor.c b/tests/0030-bxor.c
new file mode 100644
index 0000000..238955a
--- /dev/null
+++ b/tests/0030-bxor.c
_AT_@ -0,0 +1,11 @@
+
+int
+main()
+{
+ int x;
+
+ x = 1;
+ x = x ^ 3;
+ return x - 2;
+}
+
diff --git a/tests/0031-relop.c b/tests/0031-relop.c
new file mode 100644
index 0000000..643d130
--- /dev/null
+++ b/tests/0031-relop.c
_AT_@ -0,0 +1,25 @@
+
+int
+f()
+{
+ return 100;
+}
+
+int
+main()
+{
+ if (f() > 1000)
+ return 1;
+ if (f() >= 1000)
+ return 1;
+ if (1000 < f())
+ return 1;
+ if (1000 <= f())
+ return 1;
+ if (1000 == f())
+ return 1;
+ if (100 != f())
+ return 1;
+ return 0;
+}
+
diff --git a/tests/0032-indec.c b/tests/0032-indec.c
new file mode 100644
index 0000000..45748eb
--- /dev/null
+++ b/tests/0032-indec.c
_AT_@ -0,0 +1,49 @@
+
+int
+zero()
+{
+ return 0;
+}
+
+int
+one()
+{
+ return 1;
+}
+
+int
+main()
+{
+ int x;
+ int y;
+
+ x = zero();
+ y = ++x;
+ if (x != 1)
+ return 1;
+ if (y != 1)
+ return 1;
+
+ x = one();
+ y = --x;
+ if (x != 0)
+ return 1;
+ if (y != 0)
+ return 1;
+
+ x = zero();
+ y = x++;
+ if (x != 1)
+ return 1;
+ if (y != 0)
+ return 1;
+
+ x = one();
+ y = x--;
+ if (x != 0)
+ return 1;
+ if (y != 1)
+ return 1;
+
+ return 0;
+}
diff --git a/tests/0033-ptrindec.c b/tests/0033-ptrindec.c
new file mode 100644
index 0000000..30d4271
--- /dev/null
+++ b/tests/0033-ptrindec.c
_AT_@ -0,0 +1,32 @@
+
+
+int
+main()
+{
+ int arr[2];
+ int *p;
+
+ arr[0] = 2;
+ arr[1] = 3;
+ p = &arr[0];
+ if(*(p++) != 2)
+ return 1;
+ if(*(p++) != 3)
+ return 2;
+
+ p = &arr[1];
+ if(*(p--) != 3)
+ return 1;
+ if(*(p--) != 2)
+ return 2;
+
+ p = &arr[0];
+ if(*(++p) != 3)
+ return 1;
+
+ p = &arr[1];
+ if(*(--p) != 2)
+ return 1;
+
+ return 0;
+}
diff --git a/tests/0034-logandor.c b/tests/0034-logandor.c
new file mode 100644
index 0000000..5371622
--- /dev/null
+++ b/tests/0034-logandor.c
_AT_@ -0,0 +1,46 @@
+
+int g;
+
+int
+effect()
+{
+ g = 1;
+ return 1;
+}
+
+int
+main()
+{
+ int x;
+
+ g = 0;
+ x = 0;
+ if(x && effect())
+ return 1;
+ if(g)
+ return 2;
+ x = 1;
+ if(x && effect()) {
+ if(g != 1)
+ return 3;
+ } else {
+ return 4;
+ }
+ g = 0;
+ x = 1;
+ if(x || effect()) {
+ if(g)
+ return 5;
+ } else {
+ return 6;
+ }
+ x = 0;
+ if(x || effect()) {
+ if(g != 1)
+ return 7;
+ } else {
+ return 8;
+ }
+ return 0;
+}
+
diff --git a/tests/0035-breakcont.c b/tests/0035-breakcont.c
new file mode 100644
index 0000000..a25ddd4
--- /dev/null
+++ b/tests/0035-breakcont.c
_AT_@ -0,0 +1,33 @@
+
+int
+main()
+{
+ int x;
+
+ x = 0;
+ while(1)
+ break;
+ while(1) {
+ if (x == 5) {
+ break;
+ }
+ x = x + 1;
+ continue;
+ }
+ for (;;) {
+ if (x == 10) {
+ break;
+ }
+ x = x + 1;
+ continue;
+ }
+ do {
+ if (x == 15) {
+ break;
+ }
+ x = x + 1;
+ continue;
+ } while(1);
+ return x - 15;
+}
+
diff --git a/tests/0036-notneg.c b/tests/0036-notneg.c
new file mode 100644
index 0000000..e8bf709
--- /dev/null
+++ b/tests/0036-notneg.c
_AT_@ -0,0 +1,15 @@
+int
+main()
+{
+ int x;
+
+ x = 4;
+ if(!x != 0)
+ return 1;
+ if(!!x != 1)
+ return 1;
+ if(-x != 0 - 4)
+ return 1;
+ return 0;
+}
+
diff --git a/tests/0037-assignop.c b/tests/0037-assignop.c
new file mode 100644
index 0000000..df5cb89
--- /dev/null
+++ b/tests/0037-assignop.c
_AT_@ -0,0 +1,17 @@
+
+int
+main()
+{
+ int x;
+
+ x = 0;
+ x += 2;
+ x += 2;
+ if (x != 4)
+ return 1;
+ x -= 3;
+ if (x != 1)
+ return 2;
+
+ return 0;
+}
diff --git a/tests/0038-ptradd.c b/tests/0038-ptradd.c
new file mode 100644
index 0000000..a353946
--- /dev/null
+++ b/tests/0038-ptradd.c
_AT_@ -0,0 +1,17 @@
+int
+main()
+{
+ int x[2];
+ int *p;
+
+ x[1] = 7;
+ p = &x[0];
+ p = p + 1;
+
+ if(*p != 7)
+ return 1;
+ if(&x[1] - &x[0] != 1)
+ return 1;
+
+ return 0;
+}
diff --git a/tests/0039-sizeof.c b/tests/0039-sizeof.c
new file mode 100644
index 0000000..86cbd6f
--- /dev/null
+++ b/tests/0039-sizeof.c
_AT_@ -0,0 +1,10 @@
+int
+main()
+{
+ int x;
+ if((sizeof (int) - 4))
+ return 1;
+ if((sizeof (&x) - 8))
+ return 1;
+ return 0;
+}
diff --git a/tests/0040-cast.c b/tests/0040-cast.c
new file mode 100644
index 0000000..a2ebba3
--- /dev/null
+++ b/tests/0040-cast.c
_AT_@ -0,0 +1,14 @@
+
+int
+main()
+{
+ void *p;
+ int x;
+
+ x = 2;
+ p = &x;
+
+ if(*((int*)p) != 2)
+ return 1;
+ return 0;
+}
diff --git a/tests/0041-queen.c b/tests/0041-queen.c
new file mode 100644
index 0000000..2cb39e6
--- /dev/null
+++ b/tests/0041-queen.c
_AT_@ -0,0 +1,55 @@
+
+int *calloc(int, int);
+
+int N;
+int *t;
+
+int
+chk(int x, int y)
+{
+ int i;
+ int r;
+
+ for (r=i=0; i<8; i++) {
+ r = r + t[x + 8*i];
+ r = r + t[i + 8*y];
+ if (x+i < 8 & y+i < 8)
+ r = r + t[x+i + 8*(y+i)];
+ if (x+i < 8 & y-i >= 0)
+ r = r + t[x+i + 8*(y-i)];
+ if (x-i >= 0 & y+i < 8)
+ r = r + t[x-i + 8*(y+i)];
+ if (x-i >= 0 & y-i >= 0)
+ r = r + t[x-i + 8*(y-i)];
+ }
+ return r;
+}
+
+int
+go(int n, int x, int y)
+{
+ if (n == 8) {
+ N++;
+ return 0;
+ }
+ for (; y<8; y++) {
+ for (; x<8; x++)
+ if (chk(x, y) == 0) {
+ t[x + 8*y]++;
+ go(n+1, x, y);
+ t[x + 8*y]--;
+ }
+ x = 0;
+ }
+}
+
+int
+main()
+{
+ t = calloc(64, sizeof(int));
+ go(0, 0, 0);
+ if(N != 92)
+ return 1;
+ return 0;
+}
+
diff --git a/tests/0042-prime.c b/tests/0042-prime.c
new file mode 100644
index 0000000..75f2c6b
--- /dev/null
+++ b/tests/0042-prime.c
_AT_@ -0,0 +1,27 @@
+
+int
+main() {
+ int n;
+ int t;
+ int c;
+ int p;
+
+ c = 0;
+ n = 2;
+ while (n < 5000) {
+ t = 2;
+ p = 1;
+ while (t*t <= n) {
+ if (n % t == 0)
+ p = 0;
+ t++;
+ }
+ n++;
+ if (p)
+ c++;
+ }
+ if (c != 669)
+ return 1;
+ return 0;
+}
+
diff --git a/tests/0043-union.c b/tests/0043-union.c
new file mode 100644
index 0000000..c43cff2
--- /dev/null
+++ b/tests/0043-union.c
_AT_@ -0,0 +1,14 @@
+
+
+
+int
+main()
+{
+ union { int a; int b; } u;
+ u.a = 1;
+ u.b = 3;
+
+ if (u.a != 3 || u.b != 3)
+ return 1;
+ return 0;
+}
diff --git a/tests/0044-struct.c b/tests/0044-struct.c
new file mode 100644
index 0000000..895e55b
--- /dev/null
+++ b/tests/0044-struct.c
_AT_@ -0,0 +1,19 @@
+struct s {
+ int x;
+ struct {
+ int y;
+ int z;
+ } nest;
+};
+
+int
+main() {
+ struct s v;
+ v.x = 1;
+ v.nest.y = 2;
+ v.nest.z = 3;
+ if (v.x + v.nest.y + v.nest.z != 6)
+ return 1;
+ return 0;
+}
+
diff --git a/tests/0045-struct.c b/tests/0045-struct.c
new file mode 100644
index 0000000..418a4a1
--- /dev/null
+++ b/tests/0045-struct.c
_AT_@ -0,0 +1,16 @@
+struct T;
+
+struct T {
+ int x;
+};
+
+int
+main()
+{
+ struct T v;
+ { struct T { int z; }; }
+ v.x = 2;
+ if(v.x != 2)
+ return 1;
+ return 0;
+}
diff --git a/tests/0046-inits.c b/tests/0046-inits.c
new file mode 100644
index 0000000..8949f87
--- /dev/null
+++ b/tests/0046-inits.c
_AT_@ -0,0 +1,17 @@
+
+int x = 5;
+long y = 6;
+int *p = &x;
+
+int
+main()
+{
+ if (x != 5)
+ return 1;
+ if (y != 6)
+ return 2;
+ if (*p != 5)
+ return 3;
+ return 0;
+}
+
diff --git a/tests/0047-anonexport.c b/tests/0047-anonexport.c
new file mode 100644
index 0000000..2631df2
--- /dev/null
+++ b/tests/0047-anonexport.c
_AT_@ -0,0 +1,35 @@
+
+typedef struct {
+ int a;
+ union {
+ int b1;
+ int b2;
+ };
+ struct { union { struct { int c; }; struct {}; }; };
+ struct {};
+ struct {
+ int d;
+ };
+} s;
+
+int
+main()
+{
+ s v;
+
+ v.a = 1;
+ v.b1 = 2;
+ v.c = 3;
+ v.d = 4;
+
+ if (v.a != 1)
+ return 1;
+ if (v.b1 != 2 && v.b2 != 2)
+ return 2;
+ if (v.c != 3)
+ return 3;
+ if (v.d != 4)
+ return 4;
+
+ return 0;
+}
diff --git a/tests/0048-inits.c b/tests/0048-inits.c
new file mode 100644
index 0000000..c0208c0
--- /dev/null
+++ b/tests/0048-inits.c
_AT_@ -0,0 +1,15 @@
+
+struct { int a; int b; int c; } s = {1, 2, 3};
+
+int
+main()
+{
+ if (s.a != 1)
+ return 1;
+ if (s.b != 2)
+ return 2;
+ if (s.c != 3)
+ return 3;
+
+ return 0;
+}
diff --git a/tests/0049-inits.c b/tests/0049-inits.c
new file mode 100644
index 0000000..eda8dcf
--- /dev/null
+++ b/tests/0049-inits.c
_AT_@ -0,0 +1,14 @@
+
+
+struct S {int a; int b;};
+struct S s = { .b = 2, .a = 1};
+
+int
+main()
+{
+ if(s.a != 1)
+ return 1;
+ if(s.b != 2)
+ return 2;
+ return 0;
+}
diff --git a/tests/0050-inits.c b/tests/0050-inits.c
new file mode 100644
index 0000000..0206352
--- /dev/null
+++ b/tests/0050-inits.c
_AT_@ -0,0 +1,16 @@
+
+
+int x = 10;
+
+struct S {int a; int *p;};
+struct S s = { .p = &x, .a = 1};
+
+int
+main()
+{
+ if(s.a != 1)
+ return 1;
+ if(*s.p != 10)
+ return 2;
+ return 0;
+}
diff --git a/tests/0051-inits.c b/tests/0051-inits.c
new file mode 100644
index 0000000..face064
--- /dev/null
+++ b/tests/0051-inits.c
_AT_@ -0,0 +1,34 @@
+
+struct S1 {
+ int a;
+ int b;
+};
+
+struct S2 {
+ int a;
+ int b;
+ union {
+ int c;
+ int d;
+ };
+ struct S1 s;
+};
+
+struct S2 v = {1, 2, 3, {4, 5}};
+
+int
+main()
+{
+ if(v.a != 1)
+ return 1;
+ if(v.b != 2)
+ return 2;
+ if(v.c != 3 || v.d != 3)
+ return 3;
+ if(v.s.a != 4)
+ return 4;
+ if(v.s.b != 5)
+ return 5;
+
+ return 0;
+}
diff --git a/tests/0052-switch.c b/tests/0052-switch.c
new file mode 100644
index 0000000..8168ab4
--- /dev/null
+++ b/tests/0052-switch.c
_AT_@ -0,0 +1,38 @@
+int x = 0;
+
+int
+main()
+{
+ switch(x)
+ case 0:
+ ;
+ switch(x)
+ case 0:
+ switch(x) {
+ case 0:
+ goto next;
+ default:
+ return 1;
+ }
+ return 1;
+ next:
+ switch(x)
+ case 1:
+ return 1;
+ switch(x) {
+ {
+ x = 1 + 1;
+ foo:
+ case 1:
+ return 1;
+ }
+ }
+ switch(x) {
+ case 0:
+ return x;
+ case 1:
+ return 1;
+ default:
+ return 1;
+ }
+}
diff --git a/tests/0053-struct.c b/tests/0053-struct.c
new file mode 100644
index 0000000..912bcb6
--- /dev/null
+++ b/tests/0053-struct.c
_AT_@ -0,0 +1,11 @@
+
+int
+main()
+{
+ struct T { int x; };
+ {
+ struct T s;
+ s.x = 0;
+ return s.x;
+ }
+}
diff --git a/tests/0054-struct.c b/tests/0054-struct.c
new file mode 100644
index 0000000..df418eb
--- /dev/null
+++ b/tests/0054-struct.c
_AT_@ -0,0 +1,14 @@
+
+int
+main()
+{
+ struct T { int x; } s1;
+ s1.x = 1;
+ {
+ struct T { int y; } s2;
+ s2.y = 1;
+ if (s1.x - s2.y != 0)
+ return 1;
+ }
+ return 0;
+}
diff --git a/tests/0055-enum.c b/tests/0055-enum.c
new file mode 100644
index 0000000..c35a63d
--- /dev/null
+++ b/tests/0055-enum.c
_AT_@ -0,0 +1,23 @@
+
+enum E {
+ x,
+ y,
+ z,
+};
+
+int
+main()
+{
+ enum E e;
+
+ if(x != 0)
+ return 1;
+ if(y != 1)
+ return 2;
+ if(z != 2)
+ return 3;
+
+ e = x;
+ return e;
+}
+
diff --git a/tests/0056-enum.c b/tests/0056-enum.c
new file mode 100644
index 0000000..2cb7b2a
--- /dev/null
+++ b/tests/0056-enum.c
_AT_@ -0,0 +1,23 @@
+
+enum E {
+ x,
+ y = 2,
+ z,
+};
+
+int
+main()
+{
+ enum E e;
+
+ if(x != 0)
+ return 1;
+ if(y != 2)
+ return 2;
+ if(z != 3)
+ return 3;
+
+ e = x;
+ return e;
+}
+
diff --git a/tests/0057-duff.c b/tests/0057-duff.c
new file mode 100644
index 0000000..6b9aae1
--- /dev/null
+++ b/tests/0057-duff.c
_AT_@ -0,0 +1,31 @@
+
+int main()
+{
+ int count, n;
+ char *from, *to;
+ char a[39], b[39];
+
+ for(n = 0; n < 39; n++) {
+ a[n] = n;
+ b[n] = 0;
+ }
+ from = a;
+ to = b;
+ count = 39;
+ n = (count + 7) / 8;
+ switch (count % 8) {
+ case 0: do { *to++ = *from++;
+ case 7: *to++ = *from++;
+ case 6: *to++ = *from++;
+ case 5: *to++ = *from++;
+ case 4: *to++ = *from++;
+ case 3: *to++ = *from++;
+ case 2: *to++ = *from++;
+ case 1: *to++ = *from++;
+ } while (--n > 0);
+ }
+ for(n = 0; n < 39; n++)
+ if(a[n] != b[n])
+ return 1;
+ return 0;
+}
diff --git a/tests/0058-bug.c b/tests/0058-bug.c
new file mode 100644
index 0000000..8eb87cf
--- /dev/null
+++ b/tests/0058-bug.c
_AT_@ -0,0 +1,10 @@
+
+int
+main()
+{
+ char a[16], b[16];
+
+ if(sizeof(a) != sizeof(b))
+ return 1;
+ return 0;
+}
diff --git a/tests/0059-multistring.c b/tests/0059-multistring.c
new file mode 100644
index 0000000..d0d2638
--- /dev/null
+++ b/tests/0059-multistring.c
_AT_@ -0,0 +1,18 @@
+
+
+
+int main()
+{
+ char * s;
+
+ s = "abc" "def";
+ if(s[0] != 'a') return 1;
+ if(s[1] != 'b') return 2;
+ if(s[2] != 'c') return 3;
+ if(s[3] != 'd') return 4;
+ if(s[4] != 'e') return 5;
+ if(s[5] != 'f') return 6;
+ if(s[6] != 0) return 7;
+
+ return 0;
+}
diff --git a/tests/0060-charlit.c b/tests/0060-charlit.c
new file mode 100644
index 0000000..869c531
--- /dev/null
+++ b/tests/0060-charlit.c
_AT_@ -0,0 +1,9 @@
+
+int
+main()
+{
+ if ('a' != 97)
+ return 1;
+
+ return 0;
+}
diff --git a/tests/0061-comments.c b/tests/0061-comments.c
new file mode 100644
index 0000000..d2f5060
--- /dev/null
+++ b/tests/0061-comments.c
_AT_@ -0,0 +1,11 @@
+// line comment
+
+int
+main()
+{
+ /*
+ multiline
+ comment
+ */
+ return 0;
+}
diff --git a/tests/0062-include.c b/tests/0062-include.c
new file mode 100644
index 0000000..12877fd
--- /dev/null
+++ b/tests/0062-include.c
_AT_@ -0,0 +1,4 @@
+#include \
+"0062-include.h"
+ return 0;
+}
diff --git a/tests/0062-include.h b/tests/0062-include.h
new file mode 100644
index 0000000..a4d76de
--- /dev/null
+++ b/tests/0062-include.h
_AT_@ -0,0 +1,3 @@
+int
+main()
+{
diff --git a/tests/0063-define.c b/tests/0063-define.c
new file mode 100644
index 0000000..c3abf01
--- /dev/null
+++ b/tests/0063-define.c
_AT_@ -0,0 +1,7 @@
+#define FOO 0
+
+int main()
+{
+ return FOO;
+}
+
diff --git a/tests/0064-sysinclude.c b/tests/0064-sysinclude.c
new file mode 100644
index 0000000..51ab801
--- /dev/null
+++ b/tests/0064-sysinclude.c
_AT_@ -0,0 +1,7 @@
+#include <0064-sysinclude.h>
+
+int
+main()
+{
+ return x;
+}
diff --git a/tests/0065-ifdef.c b/tests/0065-ifdef.c
new file mode 100644
index 0000000..be3665e
--- /dev/null
+++ b/tests/0065-ifdef.c
_AT_@ -0,0 +1,26 @@
+
+#ifdef FOO
+ XXX
+#ifdef BAR
+ XXX
+#endif
+ XXX
+#endif
+
+#define FOO 1
+
+#ifdef FOO
+
+#ifdef FOO
+int x = 0;
+#endif
+
+int
+main()
+{
+ return x;
+}
+#endif
+
+
+
diff --git a/tests/0066-cppelse.c b/tests/0066-cppelse.c
new file mode 100644
index 0000000..5020fb2
--- /dev/null
+++ b/tests/0066-cppelse.c
_AT_@ -0,0 +1,20 @@
+#define BAR 0
+#ifdef BAR
+ #ifdef FOO
+ XXX
+ #ifdef FOO
+ XXX
+ #endif
+ #else
+ #define FOO
+ #ifdef FOO
+ int x = BAR;
+ #endif
+ #endif
+#endif
+
+int
+main()
+{
+ return BAR;
+}
diff --git a/tests/0067-define.c b/tests/0067-define.c
new file mode 100644
index 0000000..2b3d701
--- /dev/null
+++ b/tests/0067-define.c
_AT_@ -0,0 +1,7 @@
+#define X 6 / 2
+
+int
+main()
+{
+ return X - 3;
+}
diff --git a/tests/0068-funclikemacro.c b/tests/0068-funclikemacro.c
new file mode 100644
index 0000000..850b6ce
--- /dev/null
+++ b/tests/0068-funclikemacro.c
_AT_@ -0,0 +1,8 @@
+#define ADD(X, Y) (X + Y)
+
+
+int
+main()
+{
+ return ADD(1, 2) - 3;
+}
diff --git a/tests/0069-funclikemacro.c b/tests/0069-funclikemacro.c
new file mode 100644
index 0000000..f4f787c
--- /dev/null
+++ b/tests/0069-funclikemacro.c
_AT_@ -0,0 +1,11 @@
+#define A 3
+#define FOO(X,Y,Z) X + Y + Z
+#define SEMI ;
+
+int
+main()
+{
+ if(FOO(1, 2, A) != 6)
+ return 1 SEMI
+ return FOO(0,0,0);
+}
diff --git a/tests/README b/tests/README
new file mode 100644
index 0000000..1ce79cc
--- /dev/null
+++ b/tests/README
_AT_@ -0,0 +1,3 @@
+These tests are taken from https://github.com/andrewchambers/qc.
+All the credits for this test suite are for Andrew Chambers
+https://github.com/andrewchambers/qc.
diff --git a/tests/chktest.sh b/tests/chktest.sh
new file mode 100755
index 0000000..5eec1d0
--- /dev/null
+++ b/tests/chktest.sh
_AT_@ -0,0 +1,20 @@
+#!/bin/sh
+
+tabs 40
+for i in *.c
+do
+ (set -e
+ rm -f a.out core
+ scc -m qbe $i
+ ./a.out
+ ) 2>/dev/null
+
+ if test $? -eq 0
+ then
+ st=[OK]
+ else
+ st=[FAIL]
+ fi
+ echo $i "\t" $st
+done
+tabs -8
diff --git a/tests/include/0064-sysinclude.h b/tests/include/0064-sysinclude.h
new file mode 100644
index 0000000..fffa928
--- /dev/null
+++ b/tests/include/0064-sysinclude.h
_AT_@ -0,0 +1,2 @@
+int x = 0;
+
Received on Mon Jun 20 2016 - 18:14:01 CEST

This archive was generated by hypermail 2.3.0 : Mon Jun 20 2016 - 18:24:15 CEST