scc

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

commit 43dd1d697192c9831ef353f9932884f88c0e6f4c
parent 4ca62c431fbcf414f4696123b341454a1f4df0ea
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 28 Jun 2016 10:08:19 +0200

[tests] Import new tests for qc

Diffstat:
Atests/0070-cppif.c | 19+++++++++++++++++++
Atests/0071-cppelif.c | 14++++++++++++++
Atests/0072-cppelif.c | 14++++++++++++++
Atests/0073-ifndef.c | 17+++++++++++++++++
Atests/0074-undef.c | 13+++++++++++++
Atests/0075-ptraddasn.c | 15+++++++++++++++
Atests/0076-ptrsubasn.c | 15+++++++++++++++
Atests/0077-defined.c | 33+++++++++++++++++++++++++++++++++
Atests/0078-dirifexpr.c | 171+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/0079-cond.c | 10++++++++++
Atests/0080-arrays.c | 49+++++++++++++++++++++++++++++++++++++++++++++++++
11 files changed, 370 insertions(+), 0 deletions(-)

diff --git a/tests/0070-cppif.c b/tests/0070-cppif.c @@ -0,0 +1,19 @@ + +#if 1 +int x = 0; +#endif + +#if 0 +int x = 1; +#if 1 + X +#endif +#ifndef AAA + X +#endif +#endif + +int main() +{ + return x; +} diff --git a/tests/0071-cppelif.c b/tests/0071-cppelif.c @@ -0,0 +1,14 @@ + +#if 0 +X +#elif 1 +int x = 0; +#else +X +#endif + +int +main() +{ + return x; +} diff --git a/tests/0072-cppelif.c b/tests/0072-cppelif.c @@ -0,0 +1,14 @@ + +#if 0 +X +#elif 0 +X +#elif 1 +int x = 0; +#endif + +int +main() +{ + return x; +} diff --git a/tests/0073-ifndef.c b/tests/0073-ifndef.c @@ -0,0 +1,17 @@ + + +#ifndef DEF +int x = 0; +#endif + +#define DEF + +#ifndef DEF +X +#endif + +int +main() +{ + return x; +} diff --git a/tests/0074-undef.c b/tests/0074-undef.c @@ -0,0 +1,13 @@ + +#define X 1 +#undef X + +#ifdef X +FAIL +#endif + +int +main() +{ + return 0; +} diff --git a/tests/0075-ptraddasn.c b/tests/0075-ptraddasn.c @@ -0,0 +1,15 @@ + +int +main() +{ + int arr[2]; + int *p; + + p = &arr[0]; + p += 1; + *p = 123; + + if(arr[1] != 123) + return 1; + return 0; +} diff --git a/tests/0076-ptrsubasn.c b/tests/0076-ptrsubasn.c @@ -0,0 +1,15 @@ + +int +main() +{ + int arr[2]; + int *p; + + p = &arr[1]; + p -= 1; + *p = 123; + + if(arr[0] != 123) + return 1; + return 0; +} diff --git a/tests/0077-defined.c b/tests/0077-defined.c @@ -0,0 +1,33 @@ + +#if defined X +X +#endif + +#if defined(X) +X +#endif + +#if X +X +#endif + +#define X 0 + +#if X +X +#endif + +#if defined(X) +int x = 0; +#endif + +#undef X +#define X 1 + +#if X +int +main() +{ + return 0; +} +#endif diff --git a/tests/0078-dirifexpr.c b/tests/0078-dirifexpr.c @@ -0,0 +1,171 @@ + +#if (-2) != -2 +#error fail +#endif + +#if (0 || 0) != 0 +#error fail +#endif + +#if (1 || 0) != 1 +#error fail +#endif + +#if (1 || 1) != 1 +#error fail +#endif + +#if (0 && 0) != 0 +#error fail +#endif + +#if (1 && 0) != 0 +#error fail +#endif + +#if (0 && 1) != 0 +#error fail +#endif + +#if (1 && 1) != 1 +#error fail +#endif + +#if (0xf0 | 1) != 0xf1 +#error fail +#endif + +#if (0xf0 & 1) != 0 +#error fail +#endif + +#if (0xf0 & 0x1f) != 0x10 +#error fail +#endif + +#if (1 ^ 1) != 0 +#error fail +#endif + +#if (1 == 1) != 1 +#error fail +#endif + +#if (1 == 0) != 0 +#error fail +#endif + +#if (1 != 1) != 0 +#error fail +#endif + +#if (0 != 1) != 1 +#error fail +#endif + +#if (0 > 1) != 0 +#error fail +#endif + +#if (0 < 1) != 1 +#error fail +#endif + +#if (0 > -1) != 1 +#error fail +#endif + +#if (0 < -1) != 0 +#error fail +#endif + +#if (0 >= 1) != 0 +#error fail +#endif + +#if (0 <= 1) != 1 +#error fail +#endif + +#if (0 >= -1) != 1 +#error fail +#endif + +#if (0 <= -1) != 0 +#error fail +#endif + +#if (0 < 0) != 0 +#error fail +#endif + +#if (0 <= 0) != 1 +#error fail +#endif + +#if (0 > 0) != 0 +#error fail +#endif + +#if (0 >= 0) != 1 +#error fail +#endif + +#if (1 << 1) != 2 +#error fail +#endif + +#if (2 >> 1) != 1 +#error fail +#endif + +#if (2 + 1) != 3 +#error fail +#endif + +#if (2 - 3) != -1 +#error fail +#endif + +#if (2 * 3) != 6 +#error fail +#endif + +#if (6 / 3) != 2 +#error fail +#endif + +#if (7 % 3) != 1 +#error fail +#endif + +#if (2+2*3+2) != 10 +#error fail +#endif + +#if ((2+2)*(3+2)) != 20 +#error fail +#endif + +#if (2 + 2 + 2 + 2 == 2 + 2 * 3) != 1 +#error fail +#endif + +#if (1,2,3) != 3 +#error fail +#endif + +#if (0 ? 1 : 3) != 3 +#error fail +#endif + +#if (1 ? 3 : 1) != 3 +#error fail +#endif + +int +main() +{ + return 0; +} + diff --git a/tests/0079-cond.c b/tests/0079-cond.c @@ -0,0 +1,10 @@ + +int +main() +{ + if(0 ? 1 : 0) + return 1; + if(1 ? 0 : 1) + return 2; + return 0; +} diff --git a/tests/0080-arrays.c b/tests/0080-arrays.c @@ -0,0 +1,49 @@ + +int +foo(int x[100]) +{ + int y[100]; + int *p; + + y[0] = 2000; + + if(x[0] != 1000) + { + return 1; + } + + p = x; + + if(p[0] != 1000) + { + return 2; + } + + p = y; + + if(p[0] != 2000) + { + return 3; + } + + if(sizeof(x) != sizeof(void*)) + { + return 4; + } + + if(sizeof(y) <= sizeof(x)) + { + return 5; + } + + return 0; +} + +int +main() +{ + int x[100]; + x[0] = 1000; + + return foo(x); +}