diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/Makefile | 2 | ||||
| -rw-r--r-- | tests/abitest.c | 59 | ||||
| -rw-r--r-- | tests/tcctest.c | 270 | ||||
| -rw-r--r-- | tests/tests2/66_macro_concat_end.expect | 2 |
4 files changed, 111 insertions, 222 deletions
diff --git a/tests/Makefile b/tests/Makefile index 9ace5b0..e3824ba 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -70,7 +70,7 @@ ifdef LIBTCC1 LIBTCC1:=$(TOP)/$(LIBTCC1) endif -all test : clean $(TESTS) +all test : $(TESTS) hello-exe: ../examples/ex1.c @echo ------------ $@ ------------ diff --git a/tests/abitest.c b/tests/abitest.c index e2978b0..d3e151f 100644 --- a/tests/abitest.c +++ b/tests/abitest.c @@ -88,7 +88,7 @@ static int ret_2float_test_callback(void *ptr) { ret_2float_test_type a = {10, 35}; ret_2float_test_type r; r = f(a); - return ((r.x == a.x*5) && (r.y == a.y*3) && (f(a).x == a.x*5) && (f(a).y == a.y*3)) ? 0 : -1; + return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1; } static int ret_2float_test(void) { @@ -116,7 +116,7 @@ static int ret_2double_test_callback(void *ptr) { ret_2double_test_type a = {10, 35}; ret_2double_test_type r; r = f(a); - return ((r.x == a.x*5) && (r.y == a.y*3) && (f(a).x == a.x*5) && (f(a).y == a.y*3)) ? 0 : -1; + return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1; } static int ret_2double_test(void) { @@ -130,50 +130,6 @@ static int ret_2double_test(void) { return run_callback(src, ret_2double_test_callback); } -typedef struct ret_longdouble_test_type_s2 {LONG_DOUBLE x;} ret_longdouble_test_type; -typedef ret_longdouble_test_type (*ret_longdouble_test_function_type) (ret_longdouble_test_type); - -static int ret_longdouble_test_callback2(void *ptr) { - ret_longdouble_test_function_type f = (ret_longdouble_test_function_type)ptr; - ret_longdouble_test_type a = {10}; - ret_longdouble_test_type r; - r = f(a); - return ((r.x == a.x*5) && (f(a).x == a.x*5)) ? 0 : -1; -} - -static int ret_longdouble_test2(void) { - const char *src = - "typedef struct ret_longdouble_test_type_s2 {long double x;} ret_longdouble_test_type;" - "ret_longdouble_test_type f(ret_longdouble_test_type a) {\n" - " ret_longdouble_test_type r = {a.x*5};\n" - " return r;\n" - "}\n"; - - return run_callback(src, ret_longdouble_test_callback2); -} - -typedef struct ret_longlong_test_type_s2 {int x[4];} ret_longlong_test_type; -typedef ret_longlong_test_type (*ret_longlong_test_function_type) (ret_longlong_test_type); - -static int ret_longlong_test_callback2(void *ptr) { - ret_longlong_test_function_type f = (ret_longlong_test_function_type)ptr; - ret_longlong_test_type a = {{10,11,12,13}}; - ret_longlong_test_type r; - r = f(a); - return ((r.x[2] == a.x[2]*5) && (f(a).x[2] == a.x[2]*5)) ? 0 : -1; -} - -static int ret_longlong_test2(void) { - const char *src = - "typedef struct ret_longlong_test_type_s2 {int x[4];} ret_longlong_test_type;" - "ret_longlong_test_type f(ret_longlong_test_type a) {\n" - " ret_longlong_test_type r = {.x[2] = a.x[2]*5};\n" - " return r;\n" - "}\n"; - - return run_callback(src, ret_longlong_test_callback2); -} - /* * reg_pack_test: return a small struct which should be packed into * registers (Win32) during return. @@ -186,7 +142,7 @@ static int reg_pack_test_callback(void *ptr) { reg_pack_test_type a = {10, 35}; reg_pack_test_type r; r = f(a); - return ((r.x == a.x*5) && (r.y == a.y*3) && (f(a).x == a.x*5) && (f(a).y == a.y*3)) ? 0 : -1; + return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1; } static int reg_pack_test(void) { @@ -212,7 +168,7 @@ static int reg_pack_longlong_test_callback(void *ptr) { reg_pack_longlong_test_type a = {10, 35}; reg_pack_longlong_test_type r; r = f(a); - return ((r.x == a.x*5) && (r.y == a.y*3) && (f(a).x == a.x*5) && (f(a).y == a.y*3)) ? 0 : -1; + return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1; } static int reg_pack_longlong_test(void) { @@ -292,7 +248,7 @@ static int two_member_union_test_callback(void *ptr) { two_member_union_test_type a, b; a.x = 34; b = f(a); - return ((b.x == a.x*2) && (f(a).x == a.x*2)) ? 0 : -1; + return (b.x == a.x*2) ? 0 : -1; } static int two_member_union_test(void) { @@ -485,11 +441,6 @@ int main(int argc, char **argv) { RUN_TEST(ret_longdouble_test); RUN_TEST(ret_2float_test); RUN_TEST(ret_2double_test); - RUN_TEST(ret_longlong_test2); -#if !defined _WIN32 || !defined __GNUC__ - /* on win32, 'long double' is 10-byte with gcc, but is 'double' with tcc/msvc */ - RUN_TEST(ret_longdouble_test2); -#endif RUN_TEST(reg_pack_test); RUN_TEST(reg_pack_longlong_test); RUN_TEST(sret_test); diff --git a/tests/tcctest.c b/tests/tcctest.c index 22a8278..cc8ffd8 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -155,8 +155,8 @@ static int onetwothree = 123; #define B3 4 #endif -#define __INT64_C(c) c ## LL -#define INT64_MIN (-__INT64_C(9223372036854775807)-1) +#define __INT64_C(c) c ## LL +#define INT64_MIN (-__INT64_C(9223372036854775807)-1) int qq(int x) { @@ -235,7 +235,7 @@ void intdiv_test(void) void macro_test(void) { - printf("macro:\n"); + printf("macro:\n");
pf("N=%d\n", N); printf("aaa=%d\n", AAA); @@ -379,55 +379,6 @@ comment /* And again when the name and parenthes are separated by a comment. */ TEST2 /* the comment */ (); - - /* macro_push and macro_pop test */ - #undef MACRO_TEST - #ifdef MACRO_TEST - printf("define MACRO_TEST\n"); - #else - printf("undef MACRO_TEST\n"); - #endif - - #pragma push_macro("MACRO_TEST") - #define MACRO_TEST - #pragma push_macro("MACRO_TEST") - #undef MACRO_TEST - #pragma push_macro("MACRO_TEST") - - #pragma pop_macro("MACRO_TEST") - #ifdef MACRO_TEST - printf("define MACRO_TEST\n"); - #else - printf("undef MACRO_TEST\n"); - #endif - - #pragma pop_macro("MACRO_TEST") - #ifdef MACRO_TEST - printf("define MACRO_TEST\n"); - #else - printf("undef MACRO_TEST\n"); - #endif - - #pragma pop_macro("MACRO_TEST") - #ifdef MACRO_TEST - printf("define MACRO_TEST\n"); - #else - printf("undef MACRO_TEST\n"); - #endif - - /* pack test */ - #pragma pack(push,8) - #pragma pack(pop) - -/* gcc does not support - #define MACRO_TEST_MACRO "MACRO_TEST" - #pragma push_macro(MACRO_TEST_MACRO) - #undef MACRO_TEST - #define MACRO_TEST "macro_test3\n" - printf(MACRO_TEST); - #pragma pop_macro(MACRO_TEST_MACRO) - printf(MACRO_TEST); -*/ } @@ -1444,30 +1395,30 @@ struct complexinit { const static struct complexinit cix[] = { [0] = { - .a = 2000, - .b = (const struct complexinit0[]) { - { 2001, 2002 }, - { 2003, 2003 }, - {} - } + .a = 2000, + .b = (const struct complexinit0[]) { + { 2001, 2002 }, + { 2003, 2003 }, + {} + } } }; struct complexinit2 { - int a; - int b[]; + int a; + int b[]; }; struct complexinit2 cix20; struct complexinit2 cix21 = { - .a = 3000, - .b = { 3001, 3002, 3003 } + .a = 3000, + .b = { 3001, 3002, 3003 } }; struct complexinit2 cix22 = { - .a = 4000, - .b = { 4001, 4002, 4003, 4004, 4005, 4006 } + .a = 4000, + .b = { 4001, 4002, 4003, 4004, 4005, 4006 } }; void init_test(void) @@ -1564,10 +1515,10 @@ void init_test(void) printf("\n"); /* complex init check */ printf("cix: %d %d %d %d %d %d %d\n", - cix[0].a, - cix[0].b[0].a, cix[0].b[0].b, - cix[0].b[1].a, cix[0].b[1].b, - cix[0].b[2].a, cix[0].b[2].b); + cix[0].a, + cix[0].b[0].a, cix[0].b[0].b, + cix[0].b[1].a, cix[0].b[1].b, + cix[0].b[2].a, cix[0].b[2].b); printf("cix2: %d %d\n", cix21.b[2], cix22.b[5]); printf("sizeof cix20 %d, cix21 %d, sizeof cix22 %d\n", sizeof cix20, sizeof cix21, sizeof cix22); } @@ -1729,6 +1680,7 @@ void prefix ## fcast(type a)\ printf("ftof: %f %f %Lf\n", fa, da, la);\ ia = (int)a;\ llia = (long long)a;\ + a = (a >= 0) ? a : -a;\ ua = (unsigned int)a;\ llua = (unsigned long long)a;\ printf("ftoi: %d %u %lld %llu\n", ia, ua, llia, llua);\ @@ -1758,18 +1710,6 @@ void prefix ## call(void)\ printf("strto%s: %f\n", #prefix, (double)strto ## prefix("1.2", NULL));\ }\ \ -void prefix ## calc(type x, type y)\ -{\ - x=x*x;y=y*y;\ - printf("%d, %d\n", (int)x, (int)y);\ - x=x-y;y=y-x;\ - printf("%d, %d\n", (int)x, (int)y);\ - x=x/y;y=y/x;\ - printf("%d, %d\n", (int)x, (int)y);\ - x=x+x;y=y+y;\ - printf("%d, %d\n", (int)x, (int)y);\ -}\ -\ void prefix ## signed_zeros(void) \ {\ type x = 0.0, y = -0.0, n, p;\ @@ -1792,7 +1732,7 @@ void prefix ## signed_zeros(void) \ 1.0 / x != 1.0 / p);\ else\ printf ("x != +y; this is wrong!\n");\ - p = -y;\ + p = -y;\ if (x == p)\ printf ("Test 1.0 / x != 1.0 / -y returns %d (should be 0).\n",\ 1.0 / x != 1.0 / p);\ @@ -1808,7 +1748,6 @@ void prefix ## test(void)\ prefix ## fcast(234.6);\ prefix ## fcast(-2334.6);\ prefix ## call();\ - prefix ## calc(1, 1.0000000000000001);\ prefix ## signed_zeros();\ } @@ -2216,15 +2155,14 @@ void whitespace_test(void) { char *str; - -#if 1 +
#if 1 pri\ -ntf("whitspace:\n"); +ntf("whitspace:\n");
#endif pf("N=%d\n", 2); #ifdef CORRECT_CR_HANDLING - pri\ + pri\
ntf("aaa=%d\n", 3); #endif @@ -2236,12 +2174,11 @@ ntf("min=%d\n", 4); printf("len1=%d\n", strlen(" ")); #ifdef CORRECT_CR_HANDLING - str = " + str = "
"; printf("len1=%d str[0]=%d\n", strlen(str), str[0]); #endif - printf("len1=%d\n", strlen(" -a + printf("len1=%d\n", strlen("
a ")); #endif /* ACCEPT_CR_IN_STRINGS */ } @@ -2466,21 +2403,21 @@ static char * strncat1(char * dest,const char * src,size_t count) { int d0, d1, d2, d3; __asm__ __volatile__( - "repne\n\t" - "scasb\n\t" - "decl %1\n\t" - "movl %8,%3\n" - "1:\tdecl %3\n\t" - "js 2f\n\t" - "lodsb\n\t" - "stosb\n\t" - "testb %%al,%%al\n\t" - "jne 1b\n" - "2:\txorl %2,%2\n\t" - "stosb" - : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3) - : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count) - : "memory"); + "repne\n\t" + "scasb\n\t" + "decl %1\n\t" + "movl %8,%3\n" + "1:\tdecl %3\n\t" + "js 2f\n\t" + "lodsb\n\t" + "stosb\n\t" + "testb %%al,%%al\n\t" + "jne 1b\n" + "2:\txorl %2,%2\n\t" + "stosb" + : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3) + : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count) + : "memory"); return dest; } @@ -2488,20 +2425,20 @@ static char * strncat2(char * dest,const char * src,size_t count) { int d0, d1, d2, d3; __asm__ __volatile__( - "repne scasb\n\t" /* one-line repne prefix + string op */ - "decl %1\n\t" - "movl %8,%3\n" - "1:\tdecl %3\n\t" - "js 2f\n\t" - "lodsb\n\t" - "stosb\n\t" - "testb %%al,%%al\n\t" - "jne 1b\n" - "2:\txorl %2,%2\n\t" - "stosb" - : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3) - : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count) - : "memory"); + "repne scasb\n\t" /* one-line repne prefix + string op */ + "decl %1\n\t" + "movl %8,%3\n" + "1:\tdecl %3\n\t" + "js 2f\n\t" + "lodsb\n\t" + "stosb\n\t" + "testb %%al,%%al\n\t" + "jne 1b\n" + "2:\txorl %2,%2\n\t" + "stosb" + : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3) + : "0" (src),"1" (dest),"2" (0),"3" (0xffffffff), "g" (count) + : "memory"); return dest; } @@ -2509,17 +2446,17 @@ static inline void * memcpy1(void * to, const void * from, size_t n) { int d0, d1, d2; __asm__ __volatile__( - "rep ; movsl\n\t" - "testb $2,%b4\n\t" - "je 1f\n\t" - "movsw\n" - "1:\ttestb $1,%b4\n\t" - "je 2f\n\t" - "movsb\n" - "2:" - : "=&c" (d0), "=&D" (d1), "=&S" (d2) - :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from) - : "memory"); + "rep ; movsl\n\t" + "testb $2,%b4\n\t" + "je 1f\n\t" + "movsw\n" + "1:\ttestb $1,%b4\n\t" + "je 2f\n\t" + "movsb\n" + "2:" + : "=&c" (d0), "=&D" (d1), "=&S" (d2) + :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from) + : "memory"); return (to); } @@ -2527,38 +2464,38 @@ static inline void * memcpy2(void * to, const void * from, size_t n) { int d0, d1, d2; __asm__ __volatile__( - "rep movsl\n\t" /* one-line rep prefix + string op */ - "testb $2,%b4\n\t" - "je 1f\n\t" - "movsw\n" - "1:\ttestb $1,%b4\n\t" - "je 2f\n\t" - "movsb\n" - "2:" - : "=&c" (d0), "=&D" (d1), "=&S" (d2) - :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from) - : "memory"); + "rep movsl\n\t" /* one-line rep prefix + string op */ + "testb $2,%b4\n\t" + "je 1f\n\t" + "movsw\n" + "1:\ttestb $1,%b4\n\t" + "je 2f\n\t" + "movsb\n" + "2:" + : "=&c" (d0), "=&D" (d1), "=&S" (d2) + :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from) + : "memory"); return (to); } static __inline__ void sigaddset1(unsigned int *set, int _sig) { - __asm__("btsl %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc"); + __asm__("btsl %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc"); } static __inline__ void sigdelset1(unsigned int *set, int _sig) { - asm("btrl %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc"); + asm("btrl %1,%0" : "=m"(*set) : "Ir"(_sig - 1) : "cc"); } static __inline__ __const__ unsigned int swab32(unsigned int x) { - __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */ - "rorl $16,%0\n\t" /* swap words */ - "xchgb %b0,%h0" /* swap higher bytes */ - :"=q" (x) - : "0" (x)); - return x; + __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */ + "rorl $16,%0\n\t" /* swap words */ + "xchgb %b0,%h0" /* swap higher bytes */ + :"=q" (x) + : "0" (x)); + return x; } static __inline__ unsigned long long mul64(unsigned int a, unsigned int b) @@ -2635,6 +2572,7 @@ int constant_p_var; void builtin_test(void) { +#if GCC_MAJOR >= 3 COMPAT_TYPE(int, int); COMPAT_TYPE(int, unsigned int); COMPAT_TYPE(int, char); @@ -2644,9 +2582,9 @@ void builtin_test(void) COMPAT_TYPE(int *, void *); COMPAT_TYPE(int *, const int *); COMPAT_TYPE(char *, unsigned char *); - COMPAT_TYPE(char, unsigned char); /* space is needed because tcc preprocessor introduces a space between each token */ - COMPAT_TYPE(char **, void *); + COMPAT_TYPE(char * *, void *); +#endif printf("res = %d\n", __builtin_constant_p(1)); printf("res = %d\n", __builtin_constant_p(1 + 2)); printf("res = %d\n", __builtin_constant_p(&constant_p_var)); @@ -2686,23 +2624,23 @@ int weak_toolate() { return 0; } void __attribute__((weak)) weak_test(void) { - printf("weak_f1=%d\n", weak_f1 ? weak_f1() : 123); - printf("weak_f2=%d\n", weak_f2 ? weak_f2() : 123); - printf("weak_f3=%d\n", weak_f3 ? weak_f3() : 123); - printf("weak_v1=%d\n",&weak_v1 ? weak_v1 : 123); - printf("weak_v2=%d\n",&weak_v2 ? weak_v2 : 123); - printf("weak_v3=%d\n",&weak_v3 ? weak_v3 : 123); + printf("weak_f1=%d\n", weak_f1 ? weak_f1() : 123); + printf("weak_f2=%d\n", weak_f2 ? weak_f2() : 123); + printf("weak_f3=%d\n", weak_f3 ? weak_f3() : 123); + printf("weak_v1=%d\n",&weak_v1 ? weak_v1 : 123); + printf("weak_v2=%d\n",&weak_v2 ? weak_v2 : 123); + printf("weak_v3=%d\n",&weak_v3 ? weak_v3 : 123); - printf("weak_fpa=%d\n",&weak_fpa ? weak_fpa() : 123); - printf("weak_fpb=%d\n",&weak_fpb ? weak_fpb() : 123); - printf("weak_fpc=%d\n",&weak_fpc ? weak_fpc() : 123); - - printf("weak_asm_f1=%d\n", weak_asm_f1 != NULL); - printf("weak_asm_f2=%d\n", weak_asm_f2 != NULL); - printf("weak_asm_f3=%d\n", weak_asm_f3 != NULL); - printf("weak_asm_v1=%d\n",&weak_asm_v1 != NULL); - printf("weak_asm_v2=%d\n",&weak_asm_v2 != NULL); - printf("weak_asm_v3=%d\n",&weak_asm_v3 != NULL); + printf("weak_fpa=%d\n",&weak_fpa ? weak_fpa() : 123); + printf("weak_fpb=%d\n",&weak_fpb ? weak_fpb() : 123); + printf("weak_fpc=%d\n",&weak_fpc ? weak_fpc() : 123); + + printf("weak_asm_f1=%d\n", weak_asm_f1 != NULL); + printf("weak_asm_f2=%d\n", weak_asm_f2 != NULL); + printf("weak_asm_f3=%d\n", weak_asm_f3 != NULL); + printf("weak_asm_v1=%d\n",&weak_asm_v1 != NULL); + printf("weak_asm_v2=%d\n",&weak_asm_v2 != NULL); + printf("weak_asm_v3=%d\n",&weak_asm_v3 != NULL); } int __attribute__((weak)) weak_f2() { return 222; } diff --git a/tests/tests2/66_macro_concat_end.expect b/tests/tests2/66_macro_concat_end.expect index 8dbf5bb..224e5c9 100644 --- a/tests/tests2/66_macro_concat_end.expect +++ b/tests/tests2/66_macro_concat_end.expect @@ -1 +1 @@ -66_macro_concat_end.c:1: error: '##' invalid at end of macro +66_macro_concat_end.c:2: error: '##' invalid at end of macro |
