From 5919da6f05a225907a54f239a725e67c7989a2a0 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Mon, 25 Nov 2013 11:25:04 +0800 Subject: Make abitest.c have predictable result stdarg_test in abitest.c relies on a sum of some parameters made by both the caller and the callee to reach the same result. However, the variables used to store the temporary result of the additions are not initialized to 0, leading to uncertainty as to the results. This commit add this needed initialization. --- tests/abitest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/abitest.c b/tests/abitest.c index 7b12144..d3e151f 100644 --- a/tests/abitest.c +++ b/tests/abitest.c @@ -339,8 +339,8 @@ static int stdarg_test(void) { "#include \n" "typedef struct {long long a, b, c;} stdarg_test_struct_type;\n" "void f(int n_int, int n_float, int n_struct, ...) {\n" - " int i, ti;\n" - " double td;\n" + " int i, ti = 0;\n" + " double td = 0.0;\n" " stdarg_test_struct_type ts = {0,0,0}, tmp;\n" " va_list ap;\n" " va_start(ap, n_struct);\n" -- cgit v1.3.1 From f2dbcf7594887ddfdec646ab2a85f4e2358ec209 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Sun, 7 Apr 2013 17:02:57 +0200 Subject: Add ARM aeabi functions needed to run tcctest Add implementation for float / integer conversion functions: __aeabi_d2lz, __aeabi_d2ulz, __aeabi_f2lz, __aeabi_f2ulz, __aeabi_l2d, __aeabi_l2f, __aeabi_ul2d, __aeabi_ul2f Add implementation for long long helper functions: __aeabi_ldivmod, __aeabi_uldivmod, __aeabi_llsl, __aeabi_llsr, __aeabi_lasr Add implementation for integer division functions: __aeabi_uidiv, __aeabi_uidivmod, __aeabi_idiv, __aeabi_idivmod, --- lib/Makefile | 2 +- lib/armeabi.c | 441 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/tcctest.c | 67 +++++++++ 3 files changed, 509 insertions(+), 1 deletion(-) create mode 100644 lib/armeabi.c (limited to 'tests') diff --git a/lib/Makefile b/lib/Makefile index dfd01c3..a8a2b5d 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -45,7 +45,7 @@ cross : TCC = $(TOP)/$(TARGET)-tcc$(EXESUF) I386_O = libtcc1.o alloca86.o alloca86-bt.o $(BCHECK_O) X86_64_O = libtcc1.o alloca86_64.o -ARM_O = libtcc1.o +ARM_O = libtcc1.o armeabi.o WIN32_O = $(I386_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o WIN64_O = $(X86_64_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o diff --git a/lib/armeabi.c b/lib/armeabi.c new file mode 100644 index 0000000..c00ace6 --- /dev/null +++ b/lib/armeabi.c @@ -0,0 +1,441 @@ +#include + +/* We rely on the little endianness and EABI calling convention for this to + work */ + +typedef struct double_unsigned_struct { + unsigned low; + unsigned high; +} double_unsigned_struct; + +typedef struct unsigned_int_struct { + unsigned low; + int high; +} unsigned_int_struct; + +#define REGS_RETURN(name, type) \ + void name ## _return(type ret) {} + + +/* Float helper functions */ + +#define FLOAT_EXP_BITS 8 +#define FLOAT_FRAC_BITS 23 + +#define DOUBLE_EXP_BITS 11 +#define DOUBLE_FRAC_BITS 52 + +#define ONE_EXP(type) ((1 << (type ## _EXP_BITS - 1)) - 1) + +REGS_RETURN(unsigned_int_struct, unsigned_int_struct) +REGS_RETURN(double_unsigned_struct, double_unsigned_struct) + +/* float -> integer: (sign) 1.fraction x 2^(exponent - exp_for_one) */ + + +/* float to [unsigned] long long conversion */ +#define DEFINE__AEABIT_F2XLZ(name, with_sign) \ +void __aeabi_ ## name(unsigned val) \ +{ \ + int exp, high_shift, sign; \ + double_unsigned_struct ret; \ + \ + /* compute sign */ \ + sign = val >> 31; \ + \ + /* compute real exponent */ \ + exp = val >> FLOAT_FRAC_BITS; \ + exp &= (1 << FLOAT_EXP_BITS) - 1; \ + exp -= ONE_EXP(FLOAT); \ + \ + /* undefined behavior if truncated value cannot be represented */ \ + if (with_sign) { \ + if (exp > 62) /* |val| too big, double cannot represent LLONG_MAX */ \ + return; \ + } else { \ + if ((sign && exp >= 0) || exp > 63) /* if val < 0 || val too big */ \ + return; \ + } \ + \ + val &= (1 << FLOAT_FRAC_BITS) - 1; \ + if (exp >= 32) { \ + ret.high = 1 << (exp - 32); \ + if (exp - 32 >= FLOAT_FRAC_BITS) { \ + ret.high |= val << (exp - 32 - FLOAT_FRAC_BITS); \ + ret.low = 0; \ + } else { \ + high_shift = FLOAT_FRAC_BITS - (exp - 32); \ + ret.high |= val >> high_shift; \ + ret.low = val << (32 - high_shift); \ + } \ + } else { \ + ret.high = 0; \ + ret.low = 1 << exp; \ + if (exp > FLOAT_FRAC_BITS) \ + ret.low |= val << (exp - FLOAT_FRAC_BITS); \ + else \ + ret.low = val >> (FLOAT_FRAC_BITS - exp); \ + } \ + \ + /* encode negative integer using 2's complement */ \ + if (with_sign && sign) { \ + ret.low = ~ret.low; \ + ret.high = ~ret.high; \ + if (ret.low == UINT_MAX) { \ + ret.low = 0; \ + ret.high++; \ + } else \ + ret.low++; \ + } \ + \ + double_unsigned_struct_return(ret); \ +} + +/* float to unsigned long long conversion */ +DEFINE__AEABIT_F2XLZ(f2ulz, 0) + +/* float to long long conversion */ +DEFINE__AEABIT_F2XLZ(f2lz, 1) + +/* double to [unsigned] long long conversion */ +#define DEFINE__AEABIT_D2XLZ(name, with_sign) \ +void __aeabi_ ## name(double_unsigned_struct val) \ +{ \ + int exp, high_shift, sign; \ + double_unsigned_struct ret; \ + \ + /* compute sign */ \ + sign = val.high >> 31; \ + \ + /* compute real exponent */ \ + exp = (val.high >> (DOUBLE_FRAC_BITS - 32)); \ + exp &= (1 << DOUBLE_EXP_BITS) - 1; \ + exp -= ONE_EXP(DOUBLE); \ + \ + /* undefined behavior if truncated value cannot be represented */ \ + if (with_sign) { \ + if (exp > 62) /* |val| too big, double cannot represent LLONG_MAX */ \ + return; \ + } else { \ + if ((sign && exp >= 0) || exp > 63) /* if val < 0 || val too big */ \ + return; \ + } \ + \ + val.high &= (1 << (DOUBLE_FRAC_BITS - 32)) - 1; \ + if (exp >= 32) { \ + ret.high = 1 << (exp - 32); \ + if (exp >= DOUBLE_FRAC_BITS) { \ + high_shift = exp - DOUBLE_FRAC_BITS; \ + ret.high |= val.high << high_shift; \ + ret.high |= val.low >> (32 - high_shift); \ + ret.low = val.low << high_shift; \ + } else { \ + high_shift = DOUBLE_FRAC_BITS - exp; \ + ret.high |= val.high >> high_shift; \ + ret.low = val.high << (32 - high_shift); \ + ret.low |= val.low >> high_shift; \ + } \ + } else { \ + ret.high = 0; \ + ret.low = 1 << exp; \ + if (exp > DOUBLE_FRAC_BITS - 32) { \ + high_shift = exp - DOUBLE_FRAC_BITS - 32; \ + ret.low |= val.high << high_shift; \ + ret.low |= val.low >> (32 - high_shift); \ + } else \ + ret.low = val.high >> (DOUBLE_FRAC_BITS - 32 - exp); \ + } \ + \ + /* encode negative integer using 2's complement */ \ + if (with_sign && sign) { \ + ret.low = ~ret.low; \ + ret.high = ~ret.high; \ + if (ret.low == UINT_MAX) { \ + ret.low = 0; \ + ret.high++; \ + } else \ + ret.low++; \ + } \ + \ + double_unsigned_struct_return(ret); \ +} + +/* double to unsigned long long conversion */ +DEFINE__AEABIT_D2XLZ(d2ulz, 0) + +/* double to long long conversion */ +DEFINE__AEABIT_D2XLZ(d2lz, 1) + +/* long long to float conversion */ +#define DEFINE__AEABI_XL2F(name, with_sign) \ +unsigned __aeabi_ ## name(unsigned long long v) \ +{ \ + int s /* shift */, sign = 0; \ + unsigned p = 0 /* power */, ret; \ + double_unsigned_struct val; \ + \ + /* fraction in negative float is encoded in 1's complement */ \ + if (with_sign && (v & (1 << 63))) { \ + sign = 1; \ + v = ~v + 1; \ + } \ + val.low = v; \ + val.high = v >> 32; \ + /* fill fraction bits */ \ + for (s = 31, p = 1 << 31; p && !(val.high & p); s--, p >>= 1); \ + if (p) { \ + ret = val.high & (p - 1); \ + if (s < FLOAT_FRAC_BITS) { \ + ret <<= FLOAT_FRAC_BITS - s; \ + ret |= val.low >> (32 - (FLOAT_FRAC_BITS - s)); \ + } else \ + ret >>= s - FLOAT_FRAC_BITS; \ + s += 32; \ + } else { \ + for (s = 31, p = 1 << 31; p && !(val.low & p); s--, p >>= 1); \ + if (p) { \ + ret = val.low & (p - 1); \ + if (s <= FLOAT_FRAC_BITS) \ + ret <<= FLOAT_FRAC_BITS - s; \ + else \ + ret >>= s - FLOAT_FRAC_BITS; \ + } else \ + return 0; \ + } \ + \ + /* fill exponent bits */ \ + ret |= (s + ONE_EXP(FLOAT)) << FLOAT_FRAC_BITS; \ + \ + /* fill sign bit */ \ + ret |= sign << 31; \ + \ + return ret; \ +} + +/* unsigned long long to float conversion */ +DEFINE__AEABI_XL2F(ul2f, 0) + +/* long long to float conversion */ +DEFINE__AEABI_XL2F(l2f, 0) + +/* long long to double conversion */ +#define __AEABI_XL2D(name, with_sign) \ +void __aeabi_ ## name(unsigned long long v) \ +{ \ + int s, high_shift, sign = 0; \ + unsigned tmp, p = 0; \ + double_unsigned_struct val, ret; \ + \ + /* fraction in negative float is encoded in 1's complement */ \ + if (with_sign && (v & (1ULL << 63))) { \ + sign = 1; \ + v = ~v + 1; \ + } \ + val.low = v; \ + val.high = v >> 32; \ + \ + /* fill fraction bits */ \ + for (s = 31, p = 1 << 31; p && !(val.high & p); s--, p >>= 1); \ + if (p) { \ + tmp = val.high & (p - 1); \ + if (s < DOUBLE_FRAC_BITS - 32) { \ + high_shift = DOUBLE_FRAC_BITS - 32 - s; \ + ret.high = tmp << high_shift; \ + ret.high |= val.low >> (32 - high_shift); \ + ret.low = val.low << high_shift; \ + } else { \ + high_shift = s - (DOUBLE_FRAC_BITS - 32); \ + ret.high = tmp >> high_shift; \ + ret.low = tmp << (32 - high_shift); \ + ret.low |= val.low >> high_shift; \ + } \ + s += 32; \ + } else { \ + for (s = 31, p = 1 << 31; p && !(val.low & p); s--, p >>= 1); \ + if (p) { \ + tmp = val.low & (p - 1); \ + if (s <= DOUBLE_FRAC_BITS - 32) { \ + high_shift = DOUBLE_FRAC_BITS - 32 - s; \ + ret.high = tmp << high_shift; \ + ret.low = 0; \ + } else { \ + high_shift = s - (DOUBLE_FRAC_BITS - 32); \ + ret.high = tmp >> high_shift; \ + ret.low = tmp << (32 - high_shift); \ + } \ + } else { \ + ret.high = ret.low = 0; \ + double_unsigned_struct_return(ret); \ + } \ + } \ + \ + /* fill exponent bits */ \ + ret.high |= (s + ONE_EXP(DOUBLE)) << (DOUBLE_FRAC_BITS - 32); \ + \ + /* fill sign bit */ \ + ret.high |= sign << 31; \ + \ + double_unsigned_struct_return(ret); \ +} + +/* unsigned long long to double conversion */ +__AEABI_XL2D(ul2d, 0) + +/* long long to double conversion */ +__AEABI_XL2D(l2d, 1) + + +/* Long long helper functions */ + +/* TODO: add error in case of den == 0 (see §4.3.1 and §4.3.2) */ + +#define define_aeabi_xdivmod_signed_type(basetype, type) \ +typedef struct type { \ + basetype quot; \ + unsigned basetype rem; \ +} type + +#define define_aeabi_xdivmod_unsigned_type(basetype, type) \ +typedef struct type { \ + basetype quot; \ + basetype rem; \ +} type + +#define AEABI_UXDIVMOD(name,type, rettype, typemacro) \ +static inline rettype aeabi_ ## name (type num, type den) \ +{ \ + rettype ret; \ + type quot = 0; \ + \ + /* Increase quotient while it is less than numerator */ \ + while (num >= den) { \ + type q = 1; \ + \ + /* Find closest power of two */ \ + while ((q << 1) * den <= num && q * den <= typemacro ## _MAX / 2) \ + q <<= 1; \ + \ + /* Compute difference between current quotient and numerator */ \ + num -= q * den; \ + quot += q; \ + } \ + ret.quot = quot; \ + ret.rem = num; \ + return ret; \ +} + +#define __AEABI_XDIVMOD(name, type, uiname, rettype, urettype, typemacro) \ +void __aeabi_ ## name(type numerator, type denominator) \ +{ \ + unsigned type num, den; \ + urettype uxdiv_ret; \ + rettype ret; \ + \ + num = numerator & typemacro ## _MAX; \ + den = denominator & typemacro ## _MAX; \ + uxdiv_ret = aeabi_ ## uiname(num, den); \ + /* signs differ */ \ + if ((numerator & typemacro ## _MIN) != (denominator & typemacro ## _MIN)) \ + ret.quot = uxdiv_ret.quot * -1; \ + else \ + ret.quot = uxdiv_ret.quot; \ + if (numerator & typemacro ## _MIN) \ + ret.rem = uxdiv_ret.rem * -1; \ + else \ + ret.rem = uxdiv_ret.rem; \ + \ + rettype ## _return(ret); \ +} + +define_aeabi_xdivmod_signed_type(long long, lldiv_t); +define_aeabi_xdivmod_unsigned_type(unsigned long long, ulldiv_t); +define_aeabi_xdivmod_signed_type(int, idiv_t); +define_aeabi_xdivmod_unsigned_type(unsigned, uidiv_t); + +REGS_RETURN(lldiv_t, lldiv_t) +REGS_RETURN(ulldiv_t, ulldiv_t) +REGS_RETURN(idiv_t, idiv_t) +REGS_RETURN(uidiv_t, uidiv_t) + +AEABI_UXDIVMOD(uldivmod, unsigned long long, ulldiv_t, ULONG) + +__AEABI_XDIVMOD(ldivmod, long long, uldivmod, lldiv_t, ulldiv_t, LLONG) + +void __aeabi_uldivmod(unsigned long long num, unsigned long long den) +{ + ulldiv_t_return(aeabi_uldivmod(num, den)); +} + +void __aeabi_llsl(double_unsigned_struct val, int shift) +{ + double_unsigned_struct ret; + + if (shift >= 32) { + val.high = val.low; + val.low = 0; + shift -= 32; + } + if (shift > 0) { + ret.low = val.low << shift; + ret.high = (val.high << shift) | (val.low >> (32 - shift)); + double_unsigned_struct_return(ret); + return; + } + double_unsigned_struct_return(val); +} + +#define aeabi_lsr(val, shift, fill, type) \ + type ## _struct ret; \ + \ + if (shift >= 32) { \ + val.low = val.high; \ + val.high = fill; \ + shift -= 32; \ + } \ + if (shift > 0) { \ + ret.high = val.high >> shift; \ + ret.low = (val.high << (32 - shift)) | (val.low >> shift); \ + type ## _struct_return(ret); \ + return; \ + } \ + type ## _struct_return(val); + +void __aeabi_llsr(double_unsigned_struct val, int shift) +{ + aeabi_lsr(val, shift, 0, double_unsigned); +} + +void __aeabi_lasr(unsigned_int_struct val, int shift) +{ + aeabi_lsr(val, shift, val.high >> 31, unsigned_int); +} + + +/* Integer division functions */ + +AEABI_UXDIVMOD(uidivmod, unsigned, uidiv_t, UINT) + +int __aeabi_idiv(int numerator, int denominator) +{ + unsigned num, den; + uidiv_t ret; + + num = numerator & INT_MAX; + den = denominator & INT_MAX; + ret = aeabi_uidivmod(num, den); + if ((numerator & INT_MIN) != (denominator & INT_MIN)) /* signs differ */ + ret.quot *= -1; + return ret.quot; +} + +unsigned __aeabi_uidiv(unsigned num, unsigned den) +{ + return aeabi_uidivmod(num, den).quot; +} + +__AEABI_XDIVMOD(idivmod, int, uidivmod, idiv_t, uidiv_t, INT) + +void __aeabi_uidivmod(unsigned num, unsigned den) +{ + uidiv_t_return(aeabi_uidivmod(num, den)); +} diff --git a/tests/tcctest.c b/tests/tcctest.c index c5a3e73..eb284f0 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -59,6 +59,7 @@ #include "tcclib.h" +void intdiv_test(); void string_test(); void expr_test(); void macro_test(); @@ -167,6 +168,71 @@ int qq(int x) #define wq_spin_lock spin_lock #define TEST2() wq_spin_lock(a) +#define UINT_MAX ((unsigned) -1) + +void intdiv_test(void) +{ + printf("18/21=%u\n", 18/21); + printf("18%21=%u\n", 18%21); + printf("41/21=%u\n", 41/21); + printf("41%21=%u\n", 41%21); + printf("42/21=%u\n", 42/21); + printf("42%21=%u\n", 42%21); + printf("43/21=%u\n", 43/21); + printf("43%21=%u\n", 43%21); + printf("126/21=%u\n", 126/21); + printf("12%/21=%u\n", 126%21); + printf("131/21=%u\n", 131/21); + printf("131%21=%u\n", 131%21); + printf("(UINT_MAX/2+3)/2=%u\n", (UINT_MAX/2+3)/2); + printf("(UINT_MAX/2+3)%2=%u\n", (UINT_MAX/2+3)%2); + + printf("18/-21=%u\n", 18/-21); + printf("18%-21=%u\n", 18%-21); + printf("41/-21=%u\n", 41/-21); + printf("41%-21=%u\n", 41%-21); + printf("42/-21=%u\n", 42/-21); + printf("42%-21=%u\n", 42%-21); + printf("43/-21=%u\n", 43/-21); + printf("43%-21=%u\n", 43%-21); + printf("126/-21=%u\n", 126/-21); + printf("12%/-21=%u\n", 126%-21); + printf("131/-21=%u\n", 131/-21); + printf("131%-21=%u\n", 131%-21); + printf("(UINT_MAX/2+3)/-2=%u\n", (UINT_MAX/2+3)/-2); + printf("(UINT_MAX/2+3)%-2=%u\n", (UINT_MAX/2+3)%-2); + + printf("-18/21=%u\n", -18/21); + printf("-18%21=%u\n", -18%21); + printf("-41/21=%u\n", -41/21); + printf("-41%21=%u\n", -41%21); + printf("-42/21=%u\n", -42/21); + printf("-42%21=%u\n", -42%21); + printf("-43/21=%u\n", -43/21); + printf("-43%21=%u\n", -43%21); + printf("-126/21=%u\n", -126/21); + printf("-12%/21=%u\n", -126%21); + printf("-131/21=%u\n", -131/21); + printf("-131%21=%u\n", -131%21); + printf("-(UINT_MAX/2+3)/2=%u\n", (0-(UINT_MAX/2+3))/2); + printf("-(UINT_MAX/2+3)%2=%u\n", (0-(UINT_MAX/2+3))%2); + + printf("-18/-21=%u\n", -18/-21); + printf("-18%-21=%u\n", -18%-21); + printf("-41/-21=%u\n", -41/-21); + printf("-41%-21=%u\n", -41%-21); + printf("-42/-21=%u\n", -42/-21); + printf("-42%-21=%u\n", -42%-21); + printf("-43/-21=%u\n", -43/-21); + printf("-43%-21=%u\n", -43%-21); + printf("-126/-21=%u\n", -126/-21); + printf("-12%/-21=%u\n", -126%-21); + printf("-131/-21=%u\n", -131/-21); + printf("-131%-21=%u\n", -131%-21); + printf("-(UINT_MAX/2+3)/-2=%u\n", (0-(UINT_MAX/2+3))/-2); + printf("-(UINT_MAX/2+3)%-2=%u\n", (0-(UINT_MAX/2+3))%-2); +} + void macro_test(void) { printf("macro:\n"); @@ -619,6 +685,7 @@ int main(int argc, char **argv) math_cmp_test(); callsave_test(); builtin_frame_address_test(); + intdiv_test(); return 0; } -- cgit v1.3.1 From 2bd0daabbe1fc40e65e4a4631e68f5ca093ea1fb Mon Sep 17 00:00:00 2001 From: grischka Date: Mon, 6 Jan 2014 19:56:26 +0100 Subject: misc. fixes - tccgen: error out for cast to void, as in void foo(void) { return 1; } This avoids an assertion failure in x86_64-gen.c, also. also fix tests2/03_struct.c accordingly - Error: "memory full" - be more specific - Makefiles: remove circular dependencies, lookup tcctest.c from VPATH - tcc.h: cleanup lib, include, crt and libgcc search paths" avoid duplication or trailing slashes with no CONFIG_MULTIARCHDIR (as from 9382d6f1a0e2d0104a82ed805207d9e742c6b068) - tcc.h: remove ";{B}" from PE search path in ce5e12c2f950052d8109b6b7a56d900547705c08 James Lyon wrote: "... I'm not sure this is the right way to fix this problem." And the answer is: No, please. (copying libtcc1.a for tests instead) - win32/build_tcc.bat: do not move away a versioned file --- Makefile | 3 --- lib/Makefile | 3 --- libtcc.c | 4 ++-- tcc.h | 30 +++++++++++++++--------------- tccgen.c | 8 ++++---- tccpp.c | 4 ++-- tests/Makefile | 39 ++++++++++++++++++++------------------- tests/tests2/03_struct.c | 2 +- tests/tests2/Makefile | 3 --- win32/build-tcc.bat | 4 ++-- 10 files changed, 46 insertions(+), 54 deletions(-) (limited to 'tests') diff --git a/Makefile b/Makefile index 24a7c09..5052758 100644 --- a/Makefile +++ b/Makefile @@ -362,9 +362,6 @@ tar: tcc-doc.html rm -rf $(TCC-VERSION) git reset -Makefile: $(top_srcdir)/Makefile - cp $< $@ - .PHONY: all clean tar distclean install uninstall FORCE endif # ifeq ($(TOP),.) diff --git a/lib/Makefile b/lib/Makefile index a8a2b5d..394df67 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -111,6 +111,3 @@ $(DIR)/exists : clean : rm -rfv i386-win32 x86_64-win32 i386 x86_64 - -Makefile: $(top_srcdir)/lib/Makefile - cp $< $@ diff --git a/libtcc.c b/libtcc.c index df201ae..072b77f 100644 --- a/libtcc.c +++ b/libtcc.c @@ -214,7 +214,7 @@ PUB_FUNC void *tcc_malloc(unsigned long size) void *ptr; ptr = malloc(size); if (!ptr && size) - tcc_error("memory full"); + tcc_error("memory full (malloc)"); #ifdef MEM_DEBUG mem_cur_size += malloc_usable_size(ptr); if (mem_cur_size > mem_max_size) @@ -239,7 +239,7 @@ PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size) #endif ptr1 = realloc(ptr, size); if (!ptr1 && size) - tcc_error("memory full"); + tcc_error("memory full (realloc)"); #ifdef MEM_DEBUG /* NOTE: count not correct if alloc error, but not critical */ mem_cur_size += malloc_usable_size(ptr1); diff --git a/tcc.h b/tcc.h index 21957e7..0933b01 100644 --- a/tcc.h +++ b/tcc.h @@ -169,13 +169,18 @@ #ifndef CONFIG_LDDIR # define CONFIG_LDDIR "lib" #endif -#ifndef CONFIG_MULTIARCHDIR -#define CONFIG_MULTIARCHDIR + +#ifdef CONFIG_MULTIARCHDIR +# define USE_MUADIR(s) s "/" CONFIG_MULTIARCHDIR +# define ALSO_MUADIR(s) s "/" CONFIG_MULTIARCHDIR ":" s +#else +# define USE_MUADIR(s) s +# define ALSO_MUADIR(s) s #endif /* path to find crt1.o, crti.o and crtn.o */ #ifndef CONFIG_TCC_CRTPREFIX -# define CONFIG_TCC_CRTPREFIX CONFIG_SYSROOT "/usr/" CONFIG_LDDIR "/" CONFIG_MULTIARCHDIR +# define CONFIG_TCC_CRTPREFIX USE_MUADIR(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) #endif /* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */ @@ -186,10 +191,8 @@ # define CONFIG_TCC_SYSINCLUDEPATHS "{B}/include;{B}/include/winapi" # else # define CONFIG_TCC_SYSINCLUDEPATHS \ - CONFIG_SYSROOT "/usr/local/include/" CONFIG_MULTIARCHDIR \ - ":" CONFIG_SYSROOT "/usr/local/include" \ - ":" CONFIG_SYSROOT "/usr/include/" CONFIG_MULTIARCHDIR \ - ":" CONFIG_SYSROOT "/usr/include" \ + ALSO_MUADIR(CONFIG_SYSROOT "/usr/local/include") \ + ":" ALSO_MUADIR(CONFIG_SYSROOT "/usr/include") \ ":" "{B}/include" # endif #endif @@ -197,15 +200,12 @@ /* library search paths */ #ifndef CONFIG_TCC_LIBPATHS # ifdef TCC_TARGET_PE -# define CONFIG_TCC_LIBPATHS "{B}/lib;{B}" +# define CONFIG_TCC_LIBPATHS "{B}/lib" # else # define CONFIG_TCC_LIBPATHS \ - CONFIG_SYSROOT "/usr/" CONFIG_LDDIR "/" CONFIG_MULTIARCHDIR \ - ":" CONFIG_SYSROOT "/usr/" CONFIG_LDDIR \ - ":" CONFIG_SYSROOT "/" CONFIG_LDDIR "/" CONFIG_MULTIARCHDIR \ - ":" CONFIG_SYSROOT "/" CONFIG_LDDIR \ - ":" CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR "/" CONFIG_MULTIARCHDIR \ - ":" CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR + ALSO_MUADIR(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \ + ":" ALSO_MUADIR(CONFIG_SYSROOT "/" CONFIG_LDDIR) \ + ":" ALSO_MUADIR(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR) # endif #endif @@ -237,7 +237,7 @@ #endif /* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */ -#define TCC_LIBGCC CONFIG_SYSROOT "/" CONFIG_LDDIR "/" CONFIG_MULTIARCHDIR "/libgcc_s.so.1" +#define TCC_LIBGCC USE_MUADIR(CONFIG_SYSROOT "/" CONFIG_LDDIR) "/libgcc_s.so.1" /* -------------------------------------------- */ /* include the target specific definitions */ diff --git a/tccgen.c b/tccgen.c index 8355aae..f23cd07 100644 --- a/tccgen.c +++ b/tccgen.c @@ -309,7 +309,7 @@ static void vsetc(CType *type, int r, CValue *vc) int v; if (vtop >= vstack + (VSTACK_SIZE - 1)) - tcc_error("memory full"); + tcc_error("memory full (vstack)"); /* cannot let cpu flags if other instruction are generated. Also avoid leaving VT_JMP anywhere except on the top of the stack because it would complicate the code generator. */ @@ -483,7 +483,7 @@ ST_FUNC void vswap(void) ST_FUNC void vpushv(SValue *v) { if (vtop >= vstack + (VSTACK_SIZE - 1)) - tcc_error("memory full"); + tcc_error("memory full (vstack)"); vtop++; *vtop = *v; } @@ -2348,8 +2348,8 @@ static void gen_assign_cast(CType *dt) st = &vtop->type; /* source type */ dbt = dt->t & VT_BTYPE; sbt = st->t & VT_BTYPE; - if (sbt == VT_VOID) - tcc_error("Cannot assign void value"); + if (sbt == VT_VOID || dbt == VT_VOID) + tcc_error("cannot cast from/to void"); if (dt->t & VT_CONSTANT) tcc_warning("assignment of read-only location"); switch(dbt) { diff --git a/tccpp.c b/tccpp.c index aeaf6be..e1ccded 100644 --- a/tccpp.c +++ b/tccpp.c @@ -197,7 +197,7 @@ static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len) int i; if (tok_ident >= SYM_FIRST_ANOM) - tcc_error("memory full"); + tcc_error("memory full (symbols)"); /* expand token table if needed */ i = tok_ident - TOK_IDENT; @@ -1528,7 +1528,7 @@ include_done: c = (define_find(tok) != 0) ^ c; do_if: if (s1->ifdef_stack_ptr >= s1->ifdef_stack + IFDEF_STACK_SIZE) - tcc_error("memory full"); + tcc_error("memory full (ifdef)"); *s1->ifdef_stack_ptr++ = c; goto test_skip; case TOK_ELSE: diff --git a/tests/Makefile b/tests/Makefile index 08dfa42..b958a48 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -27,7 +27,7 @@ ifneq ($(ARCH),i386) TESTS := $(filter-out btest,$(TESTS)) endif ifdef CONFIG_WIN32 - TESTS := $(filter-out test3,$(TESTS)) + TESTS := w32-prep $(filter-out test3,$(TESTS)) endif ifeq ($(TARGETOS),Darwin) TESTS := $(filter-out hello-exe test3 btest,$(TESTS)) @@ -84,6 +84,9 @@ moretests: @echo ------------ $@ ------------ $(MAKE) -C tests2 +w32-prep: + cp ../libtcc1.a ../lib + # test.ref - generate using gcc # copy only tcclib.h so GCC's stddef and stdarg will be used test.ref: tcctest.c @@ -91,41 +94,41 @@ test.ref: tcctest.c ./tcctest.gcc > $@ # auto test -test1: test.ref +test1: tcctest.c test.ref @echo ------------ $@ ------------ - $(TCC) -run $(SRCDIR)/tcctest.c > test.out1 + $(TCC) -run $< > test.out1 @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi # iterated test2 (compile tcc then compile tcctest.c !) -test2: test.ref +test2: tcctest.c test.ref @echo ------------ $@ ------------ - $(TCC) $(RUN_TCC) $(RUN_TCC) -run $(SRCDIR)/tcctest.c > test.out2 + $(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2 @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi # iterated test3 (compile tcc then compile tcc then compile tcctest.c !) -test3: test.ref +test3: tcctest.c test.ref @echo ------------ $@ ------------ - $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $(SRCDIR)/tcctest.c > test.out3 + $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3 @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi # binary output test -test4: test.ref +test4: tcctest.c test.ref @echo ------------ $@ ------------ # object + link output - $(TCC) -c -o tcctest3.o $(SRCDIR)/tcctest.c + $(TCC) -c -o tcctest3.o $< $(TCC) -o tcctest3 tcctest3.o ./tcctest3 > test3.out @if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi # dynamic output - $(TCC) -o tcctest1 $(SRCDIR)/tcctest.c + $(TCC) -o tcctest1 $< ./tcctest1 > test1.out @if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi # dynamic output + bound check - $(TCC) -b -o tcctest4 $(SRCDIR)/tcctest.c + $(TCC) -b -o tcctest4 $< ./tcctest4 > test4.out @if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi # static output - $(TCC) -static -o tcctest2 $(SRCDIR)/tcctest.c + $(TCC) -static -o tcctest2 $< ./tcctest2 > test2.out @if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi @@ -161,9 +164,9 @@ speedtest: ex2 ex3 time ./ex3 35 time $(TCC) -run $(top_srcdir)/examples/ex3.c 35 -weaktest: test.ref - $(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS) - $(CC) -c tcctest.c -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS) +weaktest: tcctest.c test.ref + $(TCC) -c $< -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS) + $(CC) -c $< -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS) objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK" @@ -220,7 +223,5 @@ cache: tcc_g clean: $(MAKE) -C tests2 $@ rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \ - hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h - -Makefile: $(SRCDIR)/Makefile - cp $< $@ + hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h \ + ../lib/libtcc1.a diff --git a/tests/tests2/03_struct.c b/tests/tests2/03_struct.c index df0d3e7..c5d48c5 100644 --- a/tests/tests2/03_struct.c +++ b/tests/tests2/03_struct.c @@ -6,7 +6,7 @@ struct fred int natasha; }; -void main() +int main() { struct fred bloggs; diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index 369ed47..51dc38d 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -96,6 +96,3 @@ all test: $(TESTS) clean: rm -vf fred.txt *.output - -Makefile: $(top_srcdir)/tests/tests2/Makefile - cp $< $@ diff --git a/win32/build-tcc.bat b/win32/build-tcc.bat index 772ed26..bd897c4 100644 --- a/win32/build-tcc.bat +++ b/win32/build-tcc.bat @@ -63,5 +63,5 @@ del *.o echo>..\config.texi @set VERSION %VERSION% if not exist doc md doc makeinfo --html --no-split -o doc\tcc-doc.html ../tcc-doc.texi -if exist tcc-win32.txt move tcc-win32.txt doc\ -copy ..\tests\libtcc_test.c examples\ +copy tcc-win32.txt doc +copy ..\tests\libtcc_test.c examples -- cgit v1.3.1 From 767410b8750b45d63805b45ca1a2cf34d7cb4923 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Thu, 9 Jan 2014 17:15:08 +0800 Subject: Various Makefile fixes for cross-compilation - Build libtcc1 for cross-compiler on arm (arm to X cross compilers) - Install libtcc1 and includes for arm to i386 cross compiler - Add basic check of cross-compilers (compile ex1.c) --- Makefile | 9 +++++---- tests/Makefile | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/Makefile b/Makefile index df1d198..78e67f7 100644 --- a/Makefile +++ b/Makefile @@ -135,6 +135,7 @@ else ifeq ($(ARCH),arm) NATIVE_FILES=$(ARM_FILES) PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(C67_CROSS) LIBTCC1=libtcc1.a +LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a lib/i386/libtcc1.a endif PROGS_CROSS_LINK=$(foreach PROG_CROSS,$(PROGS_CROSS),$($(PROG_CROSS)_LINK)) @@ -278,7 +279,7 @@ endif ifdef CONFIG_CROSS mkdir -p "$(tccdir)/win32/lib/32" mkdir -p "$(tccdir)/win32/lib/64" -ifeq ($(ARCH),x86-64) +ifneq ($(ARCH),i386) mkdir -p "$(tccdir)/i386" $(INSTALL) -m644 lib/i386/libtcc1.a "$(tccdir)/i386" cp -r "$(tccdir)/include" "$(tccdir)/i386" @@ -287,7 +288,7 @@ endif $(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/win32/lib/32" $(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/win32/lib/64" cp -r $(top_srcdir)/win32/include/. "$(tccdir)/win32/include" - cp -r $(top_srcdir)/include/. "$(tccdir)/win32/include" + cp -r "$(tccdir)/include" "$(tccdir)/win32" endif uninstall: @@ -300,7 +301,7 @@ uninstall: rm -fv "$(libdir)/libtcc.so*" rm -rf "$(tccdir)/win32" -rmdir $(tccdir)/include -ifeq ($(ARCH),x86-64) +ifneq ($(ARCH),i386) rm -rf "$(tccdir)/i386" endif else @@ -346,7 +347,7 @@ tcc-doc.info: tcc-doc.texi export LIBTCC1 %est: - $(MAKE) -C tests $@ + $(MAKE) -C tests $@ "PROGS_CROSS=$(PROGS_CROSS)" clean: rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.exe libtcc_test$(EXESUF) diff --git a/tests/Makefile b/tests/Makefile index b958a48..62e4f88 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -16,6 +16,9 @@ TESTS = \ abitest \ vla_test-run \ moretests +ifdef CONFIG_CROSS +TESTS += hello-cross +endif # test4 -- problem with -static # asmtest -- minor differences with gcc @@ -50,8 +53,9 @@ endif # run local version of tcc with local libraries and includes TCCFLAGS = -B$(TOP) -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include ifdef CONFIG_WIN32 - TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir) -I$(top_srcdir)/include -I$(TOP) -L$(TOP) + TCCFLAGS = -B$(top_srcdir)/win32 --I$(top_srcdir) -I$(top_srcdir)/include -I$(TOP) -L$(TOP) endif +XTCCFLAGS = -B$(TOP) -B$(top_srcdir)/win32 -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include TCC = $(TOP)/tcc $(TCCFLAGS) RUN_TCC = $(NATIVE_DEFINES) -DONE_SOURCE -run $(top_srcdir)/tcc.c $(TCCFLAGS) @@ -69,6 +73,15 @@ hello-exe: ../examples/ex1.c @echo ------------ $@ ------------ $(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF) +hello-cross: ../examples/ex1.c + @echo ------------ $@ ------------ + for XTCC in $(PROGS_CROSS) ; \ + do echo -n "Test of $$XTCC... "; \ + out=$$($(TOP)/$$XTCC $(XTCCFLAGS) -c $< 2>&1); \ + test $$? -ne 0 && { echo "Failed\n$$out\n" ; $(TOP)/$$XTCC -vv; exit 1; } ; \ + echo "Success"; \ + done + hello-run: ../examples/ex1.c @echo ------------ $@ ------------ $(TCC) -run $< -- cgit v1.3.1 From 05c9b76131e9d0a2e1b011eeb70ad7897efc9084 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Sun, 12 Jan 2014 04:44:27 +0100 Subject: Fix floating point unary minus and plus negate(x) is subtract(-0,x), not subtract(+0,x), which makes a difference with signed zeros. Also +x was expressed as x+0, in order for the integer promotions to happen, but also mangles signed zeros, so just don't do that with floating types. --- tccgen.c | 38 +++++++++++++++++++++----------------- tests/tcctest.c | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tccgen.c b/tccgen.c index 4d7e1fb..6a5ba03 100644 --- a/tccgen.c +++ b/tccgen.c @@ -3702,12 +3702,16 @@ ST_FUNC void unary(void) break; case '+': next(); - /* in order to force cast, we add zero */ unary(); if ((vtop->type.t & VT_BTYPE) == VT_PTR) tcc_error("pointer not accepted for unary plus"); - vpushi(0); - gen_op('+'); + /* In order to force cast, we add zero, except for floating point + where we really need an noop (otherwise -0.0 will be transformed + into +0.0). */ + if (!is_float(vtop->type.t)) { + vpushi(0); + gen_op('+'); + } break; case TOK_SIZEOF: case TOK_ALIGNOF1: @@ -3822,20 +3826,20 @@ ST_FUNC void unary(void) next(); unary(); t = vtop->type.t & VT_BTYPE; - /* handle (-)0.0 */ - if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST && - is_float(t)) { - if (t == VT_FLOAT) - vtop->c.f = -vtop->c.f; - else if (t == VT_DOUBLE) - vtop->c.d = -vtop->c.d; - else - vtop->c.ld = -vtop->c.ld; - } else { - vpushi(0); - vswap(); - gen_op('-'); - } + if (is_float(t)) { + /* In IEEE negate(x) isn't subtract(0,x), but rather + subtract(-0, x). */ + vpush(&vtop->type); + if (t == VT_FLOAT) + vtop->c.f = -0.0f; + else if (t == VT_DOUBLE) + vtop->c.d = -0.0; + else + vtop->c.ld = -0.0; + } else + vpushi(0); + vswap(); + gen_op('-'); break; case TOK_LAND: if (!gnu_ext) diff --git a/tests/tcctest.c b/tests/tcctest.c index eb284f0..d96c5a1 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -1699,6 +1699,29 @@ void prefix ## call(void)\ printf("strto%s: %f\n", #prefix, (double)strto ## prefix("1.2", NULL));\ }\ \ +void prefix ## signed_zeros(void) \ +{\ + type x = 0.0, y = -0.0, n, p;\ + if (x == y)\ + printf ("Test 1.0 / x != 1.0 / y returns %d (should be 1).\n",\ + 1.0 / x != 1.0 / y);\ + else\ + printf ("x != y; this is wrong!\n");\ +\ + n = -x;\ + if (x == n)\ + printf ("Test 1.0 / x != 1.0 / -x returns %d (should be 1).\n",\ + 1.0 / x != 1.0 / n);\ + else\ + printf ("x != -x; this is wrong!\n");\ +\ + p = +y;\ + if (x == p)\ + printf ("Test 1.0 / x != 1.0 / +y returns %d (should be 1).\n",\ + 1.0 / x != 1.0 / p);\ + else\ + printf ("x != +y; this is wrong!\n");\ +}\ void prefix ## test(void)\ {\ printf("testing '%s'\n", #typename);\ @@ -1708,6 +1731,7 @@ void prefix ## test(void)\ prefix ## fcast(234.6);\ prefix ## fcast(-2334.6);\ prefix ## call();\ + prefix ## signed_zeros();\ } FTEST(f, float, float, "%f") -- cgit v1.3.1 From f42a02efda42bad2937f60c5ad98b028ddc2a581 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Sun, 12 Jan 2014 04:53:29 +0100 Subject: tcctest: One more signed zero test This also checks that -(-0.0) is +0.0. --- tests/tcctest.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/tcctest.c b/tests/tcctest.c index d96c5a1..e84f291 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -1721,6 +1721,12 @@ void prefix ## signed_zeros(void) \ 1.0 / x != 1.0 / p);\ else\ printf ("x != +y; this is wrong!\n");\ + 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);\ + else\ + printf ("x != -y; this is wrong!\n");\ }\ void prefix ## test(void)\ {\ -- cgit v1.3.1 From 32a4962593d6a2006cdd725480124717e7f5377d Mon Sep 17 00:00:00 2001 From: grischka Date: Tue, 21 Jan 2014 13:25:14 +0100 Subject: tcctest: add back testXb (self compile with -b) - Thanks to Kirill "tcc -b itself" should work now (was removed in d5f4df09ff4a84dda5b03525285f03be7723376b) Also: - tests/Makefile: - fix spurious --I from 767410b8750b45d63805b45ca1a2cf34d7cb4923 - lookup boundtest.c via VPATH (for out-of-tree build) - test[123]b?: fail on diff error - Windows: test3 now works (from e31579b0769e1f9c0947d12e83316d1149307b1a) - abitest: a libtcc.a made by gcc is not usable for tcc on WIndows - using source instead (libtcc.c) - tccpe: - avoid gcc warning (x86_64) --- Makefile | 4 ++-- tccpe.c | 2 +- tests/Makefile | 40 ++++++++++++++++++++++------------------ 3 files changed, 25 insertions(+), 21 deletions(-) (limited to 'tests') diff --git a/Makefile b/Makefile index 78e67f7..39f10ba 100644 --- a/Makefile +++ b/Makefile @@ -346,8 +346,8 @@ tcc-doc.info: tcc-doc.texi # in tests subdir export LIBTCC1 -%est: - $(MAKE) -C tests $@ "PROGS_CROSS=$(PROGS_CROSS)" +test test% %test : + $(MAKE) -C tests $@ 'PROGS_CROSS=$(PROGS_CROSS)' clean: rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.exe libtcc_test$(EXESUF) diff --git a/tccpe.c b/tccpe.c index ed7cb82..f4a58f7 100644 --- a/tccpe.c +++ b/tccpe.c @@ -1803,7 +1803,7 @@ static void pe_add_runtime(TCCState *s1, struct pe_info *pe) s1->runtime_main = start_symbol; #endif } else { - pe->start_addr = (DWORD)tcc_get_symbol_err(s1, start_symbol); + pe->start_addr = (DWORD)(uintptr_t)tcc_get_symbol_err(s1, start_symbol); } pe->type = pe_type; diff --git a/tests/Makefile b/tests/Makefile index 62e4f88..4d99a46 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -5,7 +5,7 @@ TOP = .. include $(TOP)/Makefile SRCDIR = $(top_srcdir)/tests -VPATH = $(SRCDIR) +VPATH = $(SRCDIR) $(top_srcdir) # what tests to run TESTS = \ @@ -13,27 +13,30 @@ TESTS = \ hello-run \ libtest \ test3 \ + $(BTESTS) \ abitest \ vla_test-run \ moretests + +BTESTS = test1b test3b btest + ifdef CONFIG_CROSS -TESTS += hello-cross + TESTS += hello-cross endif # test4 -- problem with -static # asmtest -- minor differences with gcc # btest -- works on i386 (including win32) -# test3 -- win32 does not know how to printf long doubles # bounds-checking is supported only on i386 ifneq ($(ARCH),i386) - TESTS := $(filter-out btest,$(TESTS)) + TESTS := $(filter-out $(BTESTS),$(TESTS)) endif ifdef CONFIG_WIN32 - TESTS := w32-prep $(filter-out test3,$(TESTS)) + TESTS := w32-prep $(filter-out $(BTESTS),$(TESTS)) endif ifeq ($(TARGETOS),Darwin) - TESTS := $(filter-out hello-exe test3 btest,$(TESTS)) + TESTS := $(filter-out hello-exe test3 $(BTESTS),$(TESTS)) endif ifeq ($(ARCH),i386) else ifneq ($(ARCH),x86-64) @@ -53,7 +56,7 @@ endif # run local version of tcc with local libraries and includes TCCFLAGS = -B$(TOP) -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include ifdef CONFIG_WIN32 - TCCFLAGS = -B$(top_srcdir)/win32 --I$(top_srcdir) -I$(top_srcdir)/include -I$(TOP) -L$(TOP) + TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir) -I$(top_srcdir)/include -I$(TOP) -L$(TOP) endif XTCCFLAGS = -B$(TOP) -B$(top_srcdir)/win32 -I$(TOP) -I$(top_srcdir) -I$(top_srcdir)/include @@ -101,28 +104,29 @@ w32-prep: cp ../libtcc1.a ../lib # test.ref - generate using gcc -# copy only tcclib.h so GCC's stddef and stdarg will be used test.ref: tcctest.c gcc -o tcctest.gcc $< -I$(top_srcdir) $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS) ./tcctest.gcc > $@ # auto test -test1: tcctest.c test.ref +test1 test1b: tcctest.c test.ref @echo ------------ $@ ------------ $(TCC) -run $< > test.out1 - @if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi + @diff -u test.ref test.out1 && echo "Auto Test OK" # iterated test2 (compile tcc then compile tcctest.c !) -test2: tcctest.c test.ref +test2 test2b: tcctest.c test.ref @echo ------------ $@ ------------ $(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2 - @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi + @diff -u test.ref test.out2 && echo "Auto Test2 OK" # iterated test3 (compile tcc then compile tcc then compile tcctest.c !) -test3: tcctest.c test.ref +test3 test3b: tcctest.c test.ref @echo ------------ $@ ------------ $(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3 - @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi + @diff -u test.ref test.out3 && echo "Auto Test3 OK" + +test%b : TCCFLAGS += -b # binary output test test4: tcctest.c test.ref @@ -153,7 +157,7 @@ btest: boundtest.c @echo ------------ $@ ------------ @for i in $(BOUNDS_OK); do \ echo ; echo --- boundtest $$i ---; \ - if $(TCC) -b -run boundtest.c $$i ; then \ + if $(TCC) -b -run $< $$i ; then \ echo succeded as expected; \ else\ echo Failed positive test $$i ; exit 1 ; \ @@ -161,7 +165,7 @@ btest: boundtest.c done ;\ for i in $(BOUNDS_FAIL); do \ echo ; echo --- boundtest $$i ---; \ - if $(TCC) -b -run boundtest.c $$i ; then \ + if $(TCC) -b -run $< $$i ; then \ echo Failed negative test $$i ; exit 1 ;\ else\ echo failed as expected; \ @@ -203,8 +207,8 @@ asmtest: asmtest.ref abitest-cc$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC) $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir) -abitest-tcc$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC) - $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir) +abitest-tcc$(EXESUF): abitest.c libtcc.c + $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE $(LIBS) $(LDFLAGS) -I$(top_srcdir) abitest: abitest-cc$(EXESUF) abitest-tcc$(EXESUF) @echo ------------ $@ ------------ -- cgit v1.3.1 From c88c2706a205ae7e2a050d861a70a4bb61180918 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Sat, 1 Feb 2014 15:26:48 +0800 Subject: Test long long to float conversions --- tests/tcctest.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/tcctest.c b/tests/tcctest.c index e84f291..f302572 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -1670,21 +1670,29 @@ void prefix ## fcast(type a)\ double da;\ LONG_DOUBLE la;\ int ia;\ + long long lla;\ unsigned int ua;\ + unsigned long long llua;\ type b;\ fa = a;\ da = a;\ la = a;\ printf("ftof: %f %f %Lf\n", fa, da, la);\ ia = (int)a;\ + lla = (long long)a;\ ua = (unsigned int)a;\ + llua = (unsigned long long)a;\ printf("ftoi: %d %u\n", ia, ua);\ ia = -1234;\ ua = 0x81234500;\ b = ia;\ printf("itof: " fmt "\n", b);\ + b = lla;\ + printf("lltof: " fmt "\n", b);\ b = ua;\ printf("utof: " fmt "\n", b);\ + b = llua;\ + printf("ulltof: " fmt "\n", b);\ }\ \ float prefix ## retf(type a) { return a; }\ -- cgit v1.3.1 From 1415d7e6b6c41faf735c9aff513ec2fd6c864d38 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Mon, 3 Feb 2014 12:26:49 +0800 Subject: Don't perform builtin_frame_address on ARM --- tests/tcctest.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/tcctest.c b/tests/tcctest.c index f302572..d185111 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -2820,16 +2820,17 @@ void bfa2(ptrdiff_t str_offset) void bfa1(ptrdiff_t str_offset) { printf("bfa1: %s\n", (char *)__builtin_frame_address(1) + str_offset); -#if defined(__arm__) && !defined(__GNUC__) bfa2(str_offset); -#endif } void builtin_frame_address_test(void) { +/* builtin_frame_address fails on ARM with gcc which make test3 fail */ +#ifndef __arm__ char str[] = "__builtin_frame_address"; char *fp0 = __builtin_frame_address(0); printf("str: %s\n", str); bfa1(str-fp0); +#endif } -- cgit v1.3.1 From 02d2ca8ac77e8deaa494199f79624176df6a2b6c Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Wed, 5 Feb 2014 15:26:46 +0800 Subject: Fix and extend *FCAST test in tcctest.c Result of float to unsigned integer conversion is undefined if float is negative. This commit take the absolute value of the float before doing the conversion to unsigned integer and add more float to integer conversion test. --- tests/tcctest.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/tcctest.c b/tests/tcctest.c index d185111..1653927 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -1670,7 +1670,7 @@ void prefix ## fcast(type a)\ double da;\ LONG_DOUBLE la;\ int ia;\ - long long lla;\ + long long llia;\ unsigned int ua;\ unsigned long long llua;\ type b;\ @@ -1679,18 +1679,21 @@ void prefix ## fcast(type a)\ la = a;\ printf("ftof: %f %f %Lf\n", fa, da, la);\ ia = (int)a;\ - lla = (long long)a;\ + llia = (long long)a;\ + a = (a >= 0) ? a : -a;\ ua = (unsigned int)a;\ llua = (unsigned long long)a;\ - printf("ftoi: %d %u\n", ia, ua);\ + printf("ftoi: %d %u %lld %llu\n", ia, ua, llia, llua);\ ia = -1234;\ ua = 0x81234500;\ + llia = -0x123456789012345LL;\ + llua = 0xf123456789012345LLU;\ b = ia;\ printf("itof: " fmt "\n", b);\ - b = lla;\ - printf("lltof: " fmt "\n", b);\ b = ua;\ printf("utof: " fmt "\n", b);\ + b = llia;\ + printf("lltof: " fmt "\n", b);\ b = llua;\ printf("ulltof: " fmt "\n", b);\ }\ -- cgit v1.3.1 From d3d89900f6e0a052f2fc15482fca58ce95cb94d1 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Sun, 9 Mar 2014 22:54:48 +0800 Subject: Don't hardcode gcc in tests Makefile --- .gitignore | 2 +- tests/Makefile | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/.gitignore b/.gitignore index 4ba6761..6e5075f 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,7 @@ p2.c tcctest[1234] test[1234].out tests/tcclib.h -tests/tcctest.gcc +tests/tcctest.cc tests/weaktest.*.o.txt tests/tests2/fred.txt tests/hello diff --git a/tests/Makefile b/tests/Makefile index 4d99a46..0cfefca 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -103,10 +103,10 @@ moretests: w32-prep: cp ../libtcc1.a ../lib -# test.ref - generate using gcc +# test.ref - generate using cc test.ref: tcctest.c - gcc -o tcctest.gcc $< -I$(top_srcdir) $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS) - ./tcctest.gcc > $@ + $(CC) -o tcctest.cc $< -I$(top_srcdir) $(CPPFLAGS) -w $(CFLAGS) $(NATIVE_DEFINES) -std=gnu99 -O0 -fno-omit-frame-pointer $(LDFLAGS) + ./tcctest.cc > $@ # auto test test1 test1b: tcctest.c test.ref @@ -183,10 +183,10 @@ speedtest: ex2 ex3 weaktest: tcctest.c test.ref $(TCC) -c $< -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS) - $(CC) -c $< -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS) + $(CC) -c $< -o weaktest.cc.o -I. $(CPPFLAGS) -w $(CFLAGS) objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt - objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt - diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK" + objdump -t weaktest.cc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.cc.o.txt + diff weaktest.cc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK" ex%: $(top_srcdir)/examples/ex%.c $(CC) -o $@ $< $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) @@ -239,6 +239,6 @@ cache: tcc_g # clean clean: $(MAKE) -C tests2 $@ - rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \ + rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.exe \ hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h \ ../lib/libtcc1.a -- cgit v1.3.1 From f1f45a47ef1c58e52a9599026ef666affc991b44 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Tue, 25 Mar 2014 20:54:19 +0800 Subject: Add test for previous commit * Adapt tests2 Makefile to support testing tcc error reporting * Add test for previous commit --- tests/tests2/56_btype_excess-1.c | 1 + tests/tests2/56_btype_excess-1.expect | 1 + tests/tests2/57_btype_excess-2.c | 1 + tests/tests2/57_btype_excess-2.expect | 1 + tests/tests2/Makefile | 10 ++++++---- 5 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 tests/tests2/56_btype_excess-1.c create mode 100644 tests/tests2/56_btype_excess-1.expect create mode 100644 tests/tests2/57_btype_excess-2.c create mode 100644 tests/tests2/57_btype_excess-2.expect (limited to 'tests') diff --git a/tests/tests2/56_btype_excess-1.c b/tests/tests2/56_btype_excess-1.c new file mode 100644 index 0000000..06eabe7 --- /dev/null +++ b/tests/tests2/56_btype_excess-1.c @@ -0,0 +1 @@ +struct A {} int i; diff --git a/tests/tests2/56_btype_excess-1.expect b/tests/tests2/56_btype_excess-1.expect new file mode 100644 index 0000000..4e6d2d7 --- /dev/null +++ b/tests/tests2/56_btype_excess-1.expect @@ -0,0 +1 @@ +56_btype_excess-1.c:1: error: too many basic types diff --git a/tests/tests2/57_btype_excess-2.c b/tests/tests2/57_btype_excess-2.c new file mode 100644 index 0000000..ab95c3e --- /dev/null +++ b/tests/tests2/57_btype_excess-2.c @@ -0,0 +1 @@ +char int i; diff --git a/tests/tests2/57_btype_excess-2.expect b/tests/tests2/57_btype_excess-2.expect new file mode 100644 index 0000000..c12ef81 --- /dev/null +++ b/tests/tests2/57_btype_excess-2.expect @@ -0,0 +1 @@ +57_btype_excess-2.c:1: error: too many basic types diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index 51dc38d..c1bf5e6 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -67,7 +67,9 @@ TESTS = \ 51_static.test \ 52_unnamed_enum.test \ 54_goto.test \ - 55_lshift_type.test + 55_lshift_type.test \ + 56_btype_excess-1.test \ + 57_btype_excess-2.test # 30_hanoi.test -- seg fault in the code, gcc as well # 34_array_assignment.test -- array assignment is not in C standard @@ -84,9 +86,9 @@ endif %.test: %.c %.expect @echo Test: $*... @if [ "x`echo $* | grep args`" != "x" ]; \ - then $(TCC) $< -norunsrc -run $(notdir $<) - arg1 arg2 arg3 arg4 >$*.output; \ - else $(TCC) -run $< >$*.output; \ - fi + then $(TCC) $< -norunsrc -run $(notdir $<) - arg1 arg2 arg3 arg4 >$*.output 2>&1; \ + else $(TCC) -run $< >$*.output 2>&1; \ + fi || true @if diff -bu $(<:.c=.expect) $*.output ; \ then rm -f $*.output; \ else exit 1; \ -- cgit v1.3.1 From bed865275db3161375b9b082945323c68c4c5b69 Mon Sep 17 00:00:00 2001 From: mingodad Date: Wed, 26 Mar 2014 14:19:22 +0000 Subject: Add the generated executables ending with "-cc" and "-tcc" to the makefile "clean" --- tests/Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/Makefile b/tests/Makefile index 0cfefca..55bf29c 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -239,6 +239,7 @@ cache: tcc_g # clean clean: $(MAKE) -C tests2 $@ - rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.exe \ - hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h \ - ../lib/libtcc1.a + rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc \ + *-cc *-tcc *.exe \ + hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h \ + ../lib/libtcc1.a -- cgit v1.3.1 From 80811671d439e4953961e3bcbe7ce09a34c96d2a Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Sun, 30 Mar 2014 12:55:32 +0800 Subject: Add tests for previous fixes Add tests for the fixes made in commits 76cb1144ef91924c53c57ea71e6f67ce73ce1cc6, a465b7f58fdea15caa1bfb81ff5e985c94c4df4a, 0f522fb32a635dafce30f3ce3ff2cb15bcec809e, 82969f045c99b4d1ef833de35117c17b326b46c0 and 673befd2d7745a90c1c4fcb6d2f0e266c04f8c97. --- tests/tests2/58_function_redefinition.c | 9 +++++++++ tests/tests2/58_function_redefinition.expect | 1 + tests/tests2/59_function_array.c | 1 + tests/tests2/59_function_array.expect | 1 + tests/tests2/60_enum_redefinition.c | 4 ++++ tests/tests2/60_enum_redefinition.expect | 1 + tests/tests2/61_undefined_enum.c | 1 + tests/tests2/61_undefined_enum.expect | 1 + tests/tests2/62_enumerator_redefinition.c | 4 ++++ tests/tests2/62_enumerator_redefinition.expect | 1 + tests/tests2/Makefile | 7 ++++++- 11 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/tests2/58_function_redefinition.c create mode 100644 tests/tests2/58_function_redefinition.expect create mode 100644 tests/tests2/59_function_array.c create mode 100644 tests/tests2/59_function_array.expect create mode 100644 tests/tests2/60_enum_redefinition.c create mode 100644 tests/tests2/60_enum_redefinition.expect create mode 100644 tests/tests2/61_undefined_enum.c create mode 100644 tests/tests2/61_undefined_enum.expect create mode 100644 tests/tests2/62_enumerator_redefinition.c create mode 100644 tests/tests2/62_enumerator_redefinition.expect (limited to 'tests') diff --git a/tests/tests2/58_function_redefinition.c b/tests/tests2/58_function_redefinition.c new file mode 100644 index 0000000..33f16ee --- /dev/null +++ b/tests/tests2/58_function_redefinition.c @@ -0,0 +1,9 @@ +int f(void) +{ + return 0; +} + +int f(void) +{ + return 1; +} diff --git a/tests/tests2/58_function_redefinition.expect b/tests/tests2/58_function_redefinition.expect new file mode 100644 index 0000000..a95a3f0 --- /dev/null +++ b/tests/tests2/58_function_redefinition.expect @@ -0,0 +1 @@ +58_function_redefinition.c:7: error: redefinition of 'f' diff --git a/tests/tests2/59_function_array.c b/tests/tests2/59_function_array.c new file mode 100644 index 0000000..9fcc12d --- /dev/null +++ b/tests/tests2/59_function_array.c @@ -0,0 +1 @@ +int (*fct)[42](int x); diff --git a/tests/tests2/59_function_array.expect b/tests/tests2/59_function_array.expect new file mode 100644 index 0000000..bf62c6e --- /dev/null +++ b/tests/tests2/59_function_array.expect @@ -0,0 +1 @@ +59_function_array.c:1: error: declaration of an array of functions diff --git a/tests/tests2/60_enum_redefinition.c b/tests/tests2/60_enum_redefinition.c new file mode 100644 index 0000000..2601560 --- /dev/null +++ b/tests/tests2/60_enum_redefinition.c @@ -0,0 +1,4 @@ +enum color {RED, GREEN, BLUE}; +enum color {R, G, B}; + +enum color c; diff --git a/tests/tests2/60_enum_redefinition.expect b/tests/tests2/60_enum_redefinition.expect new file mode 100644 index 0000000..5cb41bc --- /dev/null +++ b/tests/tests2/60_enum_redefinition.expect @@ -0,0 +1 @@ +60_enum_redefinition.c:2: error: struct/union/enum already defined diff --git a/tests/tests2/61_undefined_enum.c b/tests/tests2/61_undefined_enum.c new file mode 100644 index 0000000..bc7c6ea --- /dev/null +++ b/tests/tests2/61_undefined_enum.c @@ -0,0 +1 @@ +enum rgb c = 42; diff --git a/tests/tests2/61_undefined_enum.expect b/tests/tests2/61_undefined_enum.expect new file mode 100644 index 0000000..7ccdeca --- /dev/null +++ b/tests/tests2/61_undefined_enum.expect @@ -0,0 +1 @@ +61_undefined_enum.c:1: error: unknown struct/union/enum diff --git a/tests/tests2/62_enumerator_redefinition.c b/tests/tests2/62_enumerator_redefinition.c new file mode 100644 index 0000000..3da85ae --- /dev/null +++ b/tests/tests2/62_enumerator_redefinition.c @@ -0,0 +1,4 @@ +enum color {RED, GREEN, BLUE}; +enum rgb {RED, G, B}; + +enum color c = RED; diff --git a/tests/tests2/62_enumerator_redefinition.expect b/tests/tests2/62_enumerator_redefinition.expect new file mode 100644 index 0000000..3d0e879 --- /dev/null +++ b/tests/tests2/62_enumerator_redefinition.expect @@ -0,0 +1 @@ +62_enumerator_redefinition.c:2: error: redefinition of enumerator 'RED' diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index c1bf5e6..fa564f9 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -69,7 +69,12 @@ TESTS = \ 54_goto.test \ 55_lshift_type.test \ 56_btype_excess-1.test \ - 57_btype_excess-2.test + 57_btype_excess-2.test \ + 58_function_redefinition.test \ + 59_function_array.test \ + 60_enum_redefinition.test \ + 61_undefined_enum.test \ + 62_enumerator_redefinition.test # 30_hanoi.test -- seg fault in the code, gcc as well # 34_array_assignment.test -- array assignment is not in C standard -- cgit v1.3.1 From 3e56584223a67a6c2f41a43cf38e0960e9992238 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Mon, 31 Mar 2014 22:58:17 +0800 Subject: Allow local redefinition of enumerator --- tccgen.c | 2 +- tests/tests2/63_local_enumerator_redefinition.c | 14 ++++++++++++++ tests/tests2/63_local_enumerator_redefinition.expect | 0 tests/tests2/Makefile | 3 ++- 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/tests2/63_local_enumerator_redefinition.c create mode 100644 tests/tests2/63_local_enumerator_redefinition.expect (limited to 'tests') diff --git a/tccgen.c b/tccgen.c index 3171720..84188ad 100644 --- a/tccgen.c +++ b/tccgen.c @@ -2827,7 +2827,7 @@ static void struct_decl(CType *type, int u, int tdef) if (v < TOK_UIDENT) expect("identifier"); ss = sym_find(v); - if (ss) + if (ss && !local_stack) tcc_error("redefinition of enumerator '%s'", get_tok_str(v, NULL)); next(); diff --git a/tests/tests2/63_local_enumerator_redefinition.c b/tests/tests2/63_local_enumerator_redefinition.c new file mode 100644 index 0000000..dd4d8e0 --- /dev/null +++ b/tests/tests2/63_local_enumerator_redefinition.c @@ -0,0 +1,14 @@ +enum { + FOO, + BAR +}; + +int main(void) +{ + enum { + FOO = 2, + BAR + }; + + return BAR - FOO; +} diff --git a/tests/tests2/63_local_enumerator_redefinition.expect b/tests/tests2/63_local_enumerator_redefinition.expect new file mode 100644 index 0000000..e69de29 diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index fa564f9..bd6f2c1 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -74,7 +74,8 @@ TESTS = \ 59_function_array.test \ 60_enum_redefinition.test \ 61_undefined_enum.test \ - 62_enumerator_redefinition.test + 62_enumerator_redefinition.test \ + 63_local_enumerator_redefinition.test # 30_hanoi.test -- seg fault in the code, gcc as well # 34_array_assignment.test -- array assignment is not in C standard -- cgit v1.3.1 From 3d18c9aa64cdf5161453c54ed0302d28019282fe Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Sat, 5 Apr 2014 17:35:00 +0200 Subject: tests2: Build executables as well The individual tests in tests2 are checked only with -run. Build (and check) executables as well, to test also building executables. --- tests/tests2/Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index bd6f2c1..d523b77 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -94,13 +94,18 @@ endif @if [ "x`echo $* | grep args`" != "x" ]; \ then $(TCC) $< -norunsrc -run $(notdir $<) - arg1 arg2 arg3 arg4 >$*.output 2>&1; \ else $(TCC) -run $< >$*.output 2>&1; \ + ($(TCC) -o $*.exe $< -lm && ./$*.exe) >$*.output2 2>&1; \ fi || true @if diff -bu $(<:.c=.expect) $*.output ; \ then rm -f $*.output; \ else exit 1; \ fi + @if test -f $*.output2; then if diff -bu $(<:.c=.expect) $*.output2 ; \ + then rm -f $*.output2; \ + else exit 1; \ + fi; fi all test: $(TESTS) clean: - rm -vf fred.txt *.output + rm -vf fred.txt *.output* *.exe -- cgit v1.3.1 From c4427747e6e5890b65c70e8fad5b30309b2b0279 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Sat, 5 Apr 2014 22:54:11 +0200 Subject: arm: Provide alloca() This provides a simple implementation of alloca for ARM (and enables the associated testcase). As tcc for ARM doesn't contain an assembler, we'll have to resort using gcc for compiling it. --- lib/Makefile | 4 ++-- lib/alloca-arm.S | 11 +++++++++++ tests/tcctest.c | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 lib/alloca-arm.S (limited to 'tests') diff --git a/lib/Makefile b/lib/Makefile index 7ef267f..cf3cd71 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -45,7 +45,7 @@ cross : TCC = $(TOP)/$(TARGET)-tcc$(EXESUF) I386_O = libtcc1.o alloca86.o alloca86-bt.o $(BCHECK_O) X86_64_O = libtcc1.o alloca86_64.o -ARM_O = libtcc1.o armeabi.o +ARM_O = libtcc1.o armeabi.o alloca-arm.o WIN32_O = $(I386_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o WIN64_O = $(X86_64_O) crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o @@ -104,7 +104,7 @@ $(DIR)/libtcc1.a ../libtcc1.a : $(OBJ) $(XAR) $(DIR)/%.o : %.c $(XCC) -c $< -o $@ $(XFLAGS) $(DIR)/%.o : %.S - $(XCC) -c $< -o $@ $(XFLAGS) + $(CC) -c $< -o $@ $(XFLAGS) $(DIR)/%$(EXESUF) : $(TOP)/win32/tools/%.c $(CC) -o $@ $< $(XFLAGS) $(LDFLAGS) diff --git a/lib/alloca-arm.S b/lib/alloca-arm.S new file mode 100644 index 0000000..9deae63 --- /dev/null +++ b/lib/alloca-arm.S @@ -0,0 +1,11 @@ + .text + .align 2 + .global alloca + .type alloca, %function +alloca: + rsb sp, r0, sp + bic sp, sp, #7 + mov r0, sp + mov pc, lr + .size alloca, .-alloca + .section .note.GNU-stack,"",%progbits diff --git a/tests/tcctest.c b/tests/tcctest.c index 1653927..c48c1bc 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -2221,7 +2221,7 @@ void old_style_function(void) void alloca_test() { -#if defined __i386__ || defined __x86_64__ +#if defined __i386__ || defined __x86_64__ || defined __arm__ char *p = alloca(16); strcpy(p,"123456789012345"); printf("alloca: p is %s\n", p); @@ -2794,7 +2794,7 @@ double get100 () { return 100.0; } void callsave_test(void) { -#if defined __i386__ || defined __x86_64__ +#if defined __i386__ || defined __x86_64__ || defined __arm__ int i, s; double *d; double t; s = sizeof (double); printf ("callsavetest: %d\n", s); -- cgit v1.3.1 From 76accfb8d5b16664207fa8ae43d02b015bc8e019 Mon Sep 17 00:00:00 2001 From: grischka Date: Mon, 7 Apr 2014 11:13:19 +0200 Subject: win32: libtcc1.a needs to be built with tcc gcc/mingw produces msvc compatible pecoff objects, tcc only knows ELF. --- lib/Makefile | 7 +++++-- tests/tests2/Makefile | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/lib/Makefile b/lib/Makefile index cf3cd71..e9e12f1 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -6,7 +6,7 @@ TOP = .. include $(TOP)/Makefile VPATH = $(top_srcdir)/lib $(top_srcdir)/win32/lib -ifndef TARGET +ifndef TARGET # native library ifdef CONFIG_WIN64 TARGET = x86_64-win32 else @@ -27,6 +27,7 @@ ifndef TARGET else ifeq ($(ARCH),arm) TARGET = arm + XCC = $(CC) endif endif endif @@ -58,12 +59,14 @@ ifeq "$(TARGET)" "i386-win32" TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE XCC = $(TCC) -B$(top_srcdir)/win32 -I$(top_srcdir)/include XAR = $(DIR)/tiny_libmaker$(EXESUF) + PICFLAGS = else ifeq "$(TARGET)" "x86_64-win32" OBJ = $(addprefix $(DIR)/,$(WIN64_O)) TGT = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE XCC = $(TCC) -B$(top_srcdir)/win32 -I$(top_srcdir)/include XAR = $(DIR)/tiny_libmaker$(EXESUF) + PICFLAGS = else ifeq "$(TARGET)" "i386" OBJ = $(addprefix $(DIR)/,$(I386_O)) @@ -104,7 +107,7 @@ $(DIR)/libtcc1.a ../libtcc1.a : $(OBJ) $(XAR) $(DIR)/%.o : %.c $(XCC) -c $< -o $@ $(XFLAGS) $(DIR)/%.o : %.S - $(CC) -c $< -o $@ $(XFLAGS) + $(XCC) -c $< -o $@ $(XFLAGS) $(DIR)/%$(EXESUF) : $(TOP)/win32/tools/%.c $(CC) -o $@ $< $(XFLAGS) $(LDFLAGS) diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index d523b77..e5790c7 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -1,10 +1,10 @@ TOP = ../.. include $(TOP)/Makefile -VPATH = $(top_srcdir)/tests/tests2 -TCCFLAGS = -B$(TOP) -I$(top_srcdir)/include ifdef CONFIG_WIN32 TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir)/include -L$(TOP) +else + TCCFLAGS = -B$(TOP) -I$(top_srcdir)/include -lm endif ifeq ($(TARGETOS),Darwin) @@ -94,7 +94,7 @@ endif @if [ "x`echo $* | grep args`" != "x" ]; \ then $(TCC) $< -norunsrc -run $(notdir $<) - arg1 arg2 arg3 arg4 >$*.output 2>&1; \ else $(TCC) -run $< >$*.output 2>&1; \ - ($(TCC) -o $*.exe $< -lm && ./$*.exe) >$*.output2 2>&1; \ + ($(TCC) -o $*.exe $< && ./$*.exe) >$*.output2 2>&1; \ fi || true @if diff -bu $(<:.c=.expect) $*.output ; \ then rm -f $*.output; \ -- cgit v1.3.1 From f90bad092510c751afbd9286b9946691a416d2a1 Mon Sep 17 00:00:00 2001 From: grischka Date: Mon, 7 Apr 2014 11:20:45 +0200 Subject: tests2: cleanup - remove -norunsrc switch Meaning and usage (-run -norun...???) look sort of screwed. Also general usefulness is unclear, so it was actually to support exactly one (not even very interesting) test This partially reverts e31579b0769e1f9c0947d12e83316d1149307b1a --- libtcc.c | 9 +-------- tcc.c | 1 - tests/tests2/31_args.c | 2 +- tests/tests2/31_args.expect | 11 +++++------ tests/tests2/Makefile | 35 +++++++++++++++++++---------------- 5 files changed, 26 insertions(+), 32 deletions(-) (limited to 'tests') diff --git a/libtcc.c b/libtcc.c index cc84cd7..5df1949 100644 --- a/libtcc.c +++ b/libtcc.c @@ -1666,7 +1666,6 @@ enum { TCC_OPTION_pedantic, TCC_OPTION_pthread, TCC_OPTION_run, - TCC_OPTION_norunsrc, TCC_OPTION_v, TCC_OPTION_w, TCC_OPTION_pipe, @@ -1709,7 +1708,6 @@ static const TCCOption tcc_options[] = { { "pedantic", TCC_OPTION_pedantic, 0}, { "pthread", TCC_OPTION_pthread, 0}, { "run", TCC_OPTION_run, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, - { "norunsrc", TCC_OPTION_norunsrc, 0 }, { "rdynamic", TCC_OPTION_rdynamic, 0 }, { "r", TCC_OPTION_r, 0 }, { "s", TCC_OPTION_s, 0 }, @@ -1748,7 +1746,6 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) const TCCOption *popt; const char *optarg, *r; int run = 0; - int norunsrc = 0; int pthread = 0; int optind = 0; @@ -1761,8 +1758,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) r = argv[optind++]; if (r[0] != '-' || r[1] == '\0') { /* add a new file */ - if (!run || !norunsrc) - dynarray_add((void ***)&s->files, &s->nb_files, tcc_strdup(r)); + dynarray_add((void ***)&s->files, &s->nb_files, tcc_strdup(r)); if (run) { optind--; /* argv[0] will be this file */ @@ -1888,9 +1884,6 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) tcc_set_options(s, optarg); run = 1; break; - case TCC_OPTION_norunsrc: - norunsrc = 1; - break; case TCC_OPTION_v: do ++s->verbose; while (*optarg++ == 'v'); break; diff --git a/tcc.c b/tcc.c index 9b5ca2e..74a5f1b 100644 --- a/tcc.c +++ b/tcc.c @@ -69,7 +69,6 @@ static void help(void) " -Bdir use 'dir' as tcc internal library and include path\n" " -MD generate target dependencies for make\n" " -MF depfile put generated dependencies here\n" - " -norunsrc Do not compile the file which is the first argument after -run.\n" ); } diff --git a/tests/tests2/31_args.c b/tests/tests2/31_args.c index 275f8cf..dcafed5 100644 --- a/tests/tests2/31_args.c +++ b/tests/tests2/31_args.c @@ -5,7 +5,7 @@ int main(int argc, char **argv) int Count; printf("hello world %d\n", argc); - for (Count = 0; Count < argc; Count++) + for (Count = 1; Count < argc; Count++) printf("arg %d: %s\n", Count, argv[Count]); return 0; diff --git a/tests/tests2/31_args.expect b/tests/tests2/31_args.expect index c392b67..8c60bfc 100644 --- a/tests/tests2/31_args.expect +++ b/tests/tests2/31_args.expect @@ -1,7 +1,6 @@ hello world 6 -arg 0: 31_args.c -arg 1: - -arg 2: arg1 -arg 3: arg2 -arg 4: arg3 -arg 5: arg4 +arg 1: arg1 +arg 2: arg2 +arg 3: arg3 +arg 4: arg4 +arg 5: arg5 diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index e5790c7..4d5546d 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -46,9 +46,11 @@ TESTS = \ 27_sizeof.test \ 28_strings.test \ 29_array_address.test \ + 30_hanoi.test \ 31_args.test \ 32_led.test \ 33_ternary_op.test \ + 34_array_assignment.test \ 35_sizeof.test \ 36_array_initialisers.test \ 37_sprintf.test \ @@ -60,6 +62,7 @@ TESTS = \ 43_void_param.test \ 44_scoped_declarations.test \ 45_empty_for.test \ + 46_grep.test \ 47_switch_return.test \ 48_nested_break.test \ 49_bracket_evaluation.test \ @@ -81,31 +84,31 @@ TESTS = \ # 34_array_assignment.test -- array assignment is not in C standard # 46_grep.test -- does not compile even with gcc +SKIP = 30_hanoi.test 34_array_assignment.test 46_grep.test + # some tests do not pass on all platforms, remove them for now ifeq ($(TARGETOS),Darwin) - TESTS := $(filter-out 40_stdio.test,$(TESTS)) + SKIP += 40_stdio.test endif ifdef CONFIG_WIN32 - TESTS := $(filter-out 24_math_library.test 28_strings.test,$(TESTS)) + SKIP += 24_math_library.test # don't have round() + SKIP += 28_strings.test # don't have r/index() / strings.h endif +# Some tests might need arguments +ARGS = +31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5 + +all test: $(filter-out $(SKIP),$(TESTS)) + %.test: %.c %.expect @echo Test: $*... - @if [ "x`echo $* | grep args`" != "x" ]; \ - then $(TCC) $< -norunsrc -run $(notdir $<) - arg1 arg2 arg3 arg4 >$*.output 2>&1; \ - else $(TCC) -run $< >$*.output 2>&1; \ - ($(TCC) -o $*.exe $< && ./$*.exe) >$*.output2 2>&1; \ - fi || true - @if diff -bu $(<:.c=.expect) $*.output ; \ - then rm -f $*.output; \ - else exit 1; \ - fi - @if test -f $*.output2; then if diff -bu $(<:.c=.expect) $*.output2 ; \ - then rm -f $*.output2; \ - else exit 1; \ - fi; fi -all test: $(TESTS) + @$(TCC) -run $< $(ARGS) >$*.output 2>&1 || true + @diff -bu $*.expect $*.output && rm -f $*.output + + @($(TCC) $< -o $*.exe && ./$*.exe $(ARGS)) >$*.output2 2>&1 || true + @diff -bu $*.expect $*.output2 && rm -f $*.output2 $*.exe clean: rm -vf fred.txt *.output* *.exe -- cgit v1.3.1 From 3e9a7e9d69e3adb0e9ed65d11caf415e74458fe9 Mon Sep 17 00:00:00 2001 From: Vincent Lefevre Date: Mon, 7 Apr 2014 13:31:00 +0200 Subject: Corrected spelling mistakes in comments and strings --- arm-gen.c | 4 ++-- c67-gen.c | 4 ++-- i386-asm.c | 2 +- i386-tok.h | 2 +- include/stddef.h | 2 +- lib/bcheck.c | 2 +- tccasm.c | 2 +- tccgen.c | 4 ++-- tests/Makefile | 2 +- tests/tcctest.c | 2 +- tests/tests2/46_grep.c | 10 +++++----- 11 files changed, 18 insertions(+), 18 deletions(-) (limited to 'tests') diff --git a/arm-gen.c b/arm-gen.c index a9c05fe..680a490 100644 --- a/arm-gen.c +++ b/arm-gen.c @@ -943,7 +943,7 @@ struct plan { Returns the amount of stack space needed for parameter passing Note: this function allocated an array in plan->pplans with tcc_malloc. It - is the responsability of the caller to free this array once used (ie not + is the responsibility of the caller to free this array once used (ie not before copy_params). */ static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo) { @@ -1860,7 +1860,7 @@ void gen_opf(int op) case TOK_UGE: case TOK_ULE: case TOK_UGT: - tcc_error("unsigned comparision on floats?"); + tcc_error("unsigned comparison on floats?"); break; case TOK_LT: op=TOK_Nset; diff --git a/c67-gen.c b/c67-gen.c index 6d9068a..a26dfaa 100644 --- a/c67-gen.c +++ b/c67-gen.c @@ -245,8 +245,8 @@ void gsym(int t) } // these are regs that tcc doesn't really know about, -// but asign them unique values so the mapping routines -// can distinquish them +// but assign them unique values so the mapping routines +// can distinguish them #define C67_A0 105 #define C67_SP 106 diff --git a/i386-asm.c b/i386-asm.c index 8473d06..a524658 100644 --- a/i386-asm.c +++ b/i386-asm.c @@ -1382,7 +1382,7 @@ ST_FUNC void subst_asm_operand(CString *add_str, } } -/* generate prolog and epilog code for asm statment */ +/* generate prolog and epilog code for asm statement */ ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, diff --git a/i386-tok.h b/i386-tok.h index d1e4bf3..6ba865d 100644 --- a/i386-tok.h +++ b/i386-tok.h @@ -191,7 +191,7 @@ DEF_FP(mul) DEF_ASM(fcom) - DEF_ASM(fcom_1) /* non existant op, just to have a regular table */ + DEF_ASM(fcom_1) /* non existent op, just to have a regular table */ DEF_FP1(com) DEF_FP(comp) diff --git a/include/stddef.h b/include/stddef.h index eaf0669..9e43de9 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -31,7 +31,7 @@ void *alloca(size_t size); by __need_wint_t, as otherwise stddef.h isn't allowed to define this type). Note that this must be outside the normal _STDDEF_H guard, so that it works even when we've included the file - already (without requring wint_t). Some other libs define _WINT_T + already (without requiring wint_t). Some other libs define _WINT_T if they've already provided that type, so we can use that as guard. TCC defines __WINT_TYPE__ for us. */ #if defined (__need_wint_t) diff --git a/lib/bcheck.c b/lib/bcheck.c index 968cdf4..76413ad 100644 --- a/lib/bcheck.c +++ b/lib/bcheck.c @@ -635,7 +635,7 @@ int __bound_delete_region(void *p) } /* return the size of the region starting at p, or EMPTY_SIZE if non - existant region. */ + existent region. */ static unsigned long get_region_size(void *p) { unsigned long addr = (unsigned long)p; diff --git a/tccasm.c b/tccasm.c index 9c77960..1c6a65d 100644 --- a/tccasm.c +++ b/tccasm.c @@ -232,7 +232,7 @@ static inline void asm_expr_sum(TCCState *s1, ExprValue *pe) } else { goto cannot_relocate; } - pe->sym = NULL; /* same symbols can be substracted to NULL */ + pe->sym = NULL; /* same symbols can be subtracted to NULL */ } else { cannot_relocate: tcc_error("invalid operation with label"); diff --git a/tccgen.c b/tccgen.c index e6e0fe1..ec92797 100644 --- a/tccgen.c +++ b/tccgen.c @@ -1579,7 +1579,7 @@ static inline int is_integer_btype(int bt) bt == VT_INT || bt == VT_LLONG); } -/* check types for comparison or substraction of pointers */ +/* check types for comparison or subtraction of pointers */ static void check_comparison_pointer_types(SValue *p1, SValue *p2, int op) { CType *type1, *type2, tmp_type1, tmp_type2; @@ -5574,7 +5574,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, if (sym->type.t & VT_EXTERN) { /* if the variable is extern, it was not allocated */ sym->type.t &= ~VT_EXTERN; - /* set array size if it was ommited in extern + /* set array size if it was omitted in extern declaration */ if ((sym->type.t & VT_ARRAY) && sym->type.ref->c < 0 && diff --git a/tests/Makefile b/tests/Makefile index 55bf29c..ee0eafe 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -158,7 +158,7 @@ btest: boundtest.c @for i in $(BOUNDS_OK); do \ echo ; echo --- boundtest $$i ---; \ if $(TCC) -b -run $< $$i ; then \ - echo succeded as expected; \ + echo succeeded as expected; \ else\ echo Failed positive test $$i ; exit 1 ; \ fi ;\ diff --git a/tests/tcctest.c b/tests/tcctest.c index c48c1bc..cc8ffd8 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -2254,7 +2254,7 @@ void c99_vla_test(int size1, int size2) printf("%s\n", (sizeof tab1 == size1 * size2 * 2 * sizeof(int)) ? "PASSED" : "FAILED"); tab1_ptr = tab1; tab2_ptr = tab2; - printf("Test C99 VLA 2 (ptrs substract): "); + printf("Test C99 VLA 2 (ptrs subtract): "); printf("%s\n", (tab2 - tab1 == (tab2_ptr - tab1_ptr) / (sizeof(int) * 2)) ? "PASSED" : "FAILED"); printf("Test C99 VLA 3 (ptr add): "); printf("%s\n", &tab1[5][1] == (tab1_ptr + (5 * 2 + 1) * sizeof(int)) ? "PASSED" : "FAILED"); diff --git a/tests/tests2/46_grep.c b/tests/tests2/46_grep.c index 5f52220..27589a4 100644 --- a/tests/tests2/46_grep.c +++ b/tests/tests2/46_grep.c @@ -29,10 +29,10 @@ char *documentation[] = { "grep searches a file for a given pattern. Execute by", " grep [flags] regular_expression file_list\n", - "Flags are single characters preceeded by '-':", + "Flags are single characters preceded by '-':", " -c Only a count of matching lines is printed", " -f Print file name for matching lines switch, see below", - " -n Each line is preceeded by its line number", + " -n Each line is preceded by its line number", " -v Only print non-matching lines\n", "The file_list is a list of files (wildcards are acceptable on RSX modes).", "\nThe file name is normally printed if there is a file given.", @@ -54,10 +54,10 @@ char *patdoc[] = { "':n' \":n\" matches alphanumerics, \": \" matches spaces, tabs, and", "': ' other control characters, such as new-line.", "'*' An expression followed by an asterisk matches zero or more", - " occurrances of that expression: \"fo*\" matches \"f\", \"fo\"", + " occurrences of that expression: \"fo*\" matches \"f\", \"fo\"", " \"foo\", etc.", "'+' An expression followed by a plus sign matches one or more", - " occurrances of that expression: \"fo+\" matches \"fo\", etc.", + " occurrences of that expression: \"fo+\" matches \"fo\", etc.", "'-' An expression followed by a minus sign optionally matches", " the expression.", "'[]' A string enclosed in square brackets matches any character in", @@ -153,7 +153,7 @@ void compile(char *source) o == STAR || o == PLUS || o == MINUS) - badpat("Illegal occurrance op.", source, s); + badpat("Illegal occurrence op.", source, s); store(ENDPAT); store(ENDPAT); spp = pp; /* Save pattern end */ -- cgit v1.3.1 From 91d4db600bd95318c224100f13b79de9fdd5ca79 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Mon, 7 Apr 2014 23:30:57 +0800 Subject: Add new tests for macro nesting --- tests/tests2/64_macro_nesting.c | 10 ++++++++++ tests/tests2/64_macro_nesting.expect | 1 + tests/tests2/Makefile | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/tests2/64_macro_nesting.c create mode 100644 tests/tests2/64_macro_nesting.expect (limited to 'tests') diff --git a/tests/tests2/64_macro_nesting.c b/tests/tests2/64_macro_nesting.c new file mode 100644 index 0000000..44b582f --- /dev/null +++ b/tests/tests2/64_macro_nesting.c @@ -0,0 +1,10 @@ +#define CAT2(a,b) a##b +#define CAT(a,b) CAT2(a,b) +#define AB(x) CAT(x,y) + +int main(void) +{ + int xy = 42; + printf("%d\n", CAT(A,B)(x)); + return 0; +} diff --git a/tests/tests2/64_macro_nesting.expect b/tests/tests2/64_macro_nesting.expect new file mode 100644 index 0000000..d81cc07 --- /dev/null +++ b/tests/tests2/64_macro_nesting.expect @@ -0,0 +1 @@ +42 diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index 4d5546d..36d84dc 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -78,7 +78,8 @@ TESTS = \ 60_enum_redefinition.test \ 61_undefined_enum.test \ 62_enumerator_redefinition.test \ - 63_local_enumerator_redefinition.test + 63_local_enumerator_redefinition.test \ + 64_macro_nesting.test # 30_hanoi.test -- seg fault in the code, gcc as well # 34_array_assignment.test -- array assignment is not in C standard -- cgit v1.3.1 From a715d7143d9d17da17e67fec6af1c01409a71a31 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Tue, 8 Apr 2014 22:19:48 +0800 Subject: Prevent ## to appear at start or end of macro --- tccpp.c | 14 +++++++++++--- tests/tests2/65_macro_concat_start.c | 2 ++ tests/tests2/65_macro_concat_start.expect | 1 + tests/tests2/66_macro_concat_end.c | 2 ++ tests/tests2/66_macro_concat_end.expect | 1 + tests/tests2/Makefile | 4 +++- 6 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 tests/tests2/65_macro_concat_start.c create mode 100644 tests/tests2/65_macro_concat_start.expect create mode 100644 tests/tests2/66_macro_concat_end.c create mode 100644 tests/tests2/66_macro_concat_end.expect (limited to 'tests') diff --git a/tccpp.c b/tccpp.c index 7144ee4..c8beec5 100644 --- a/tccpp.c +++ b/tccpp.c @@ -1213,9 +1213,9 @@ static void tok_print(int *str) ST_FUNC void parse_define(void) { Sym *s, *first, **ps; - int v, t, varg, is_vaargs, spc; + int v, t, varg, is_vaargs, spc, ptok, macro_list_start; TokenString str; - + v = tok; if (v < TOK_IDENT) tcc_error("invalid macro name '%s'", get_tok_str(tok, &tokc)); @@ -1254,8 +1254,13 @@ ST_FUNC void parse_define(void) tok_str_new(&str); spc = 2; /* EOF testing necessary for '-D' handling */ + ptok = 0; + macro_list_start = 1; while (tok != TOK_LINEFEED && tok != TOK_EOF) { - /* remove spaces around ## and after '#' */ + if (!macro_list_start && spc == 2 && tok == TOK_TWOSHARPS) + tcc_error("'##' invalid at start of macro"); + ptok = tok; + /* remove spaces around ## and after '#' */ if (TOK_TWOSHARPS == tok) { if (1 == spc) --str.len; @@ -1268,7 +1273,10 @@ ST_FUNC void parse_define(void) tok_str_add2(&str, tok, &tokc); skip: next_nomacro_spc(); + macro_list_start = 0; } + if (ptok == TOK_TWOSHARPS) + tcc_error("'##' invalid at end of macro"); if (spc == 1) --str.len; /* remove trailing space */ tok_str_add(&str, 0); diff --git a/tests/tests2/65_macro_concat_start.c b/tests/tests2/65_macro_concat_start.c new file mode 100644 index 0000000..d63d67a --- /dev/null +++ b/tests/tests2/65_macro_concat_start.c @@ -0,0 +1,2 @@ +#define paste(A,B) ##A B +paste(x,y) diff --git a/tests/tests2/65_macro_concat_start.expect b/tests/tests2/65_macro_concat_start.expect new file mode 100644 index 0000000..88ed6c5 --- /dev/null +++ b/tests/tests2/65_macro_concat_start.expect @@ -0,0 +1 @@ +65_macro_concat_start.c:1: error: '##' invalid at start of macro diff --git a/tests/tests2/66_macro_concat_end.c b/tests/tests2/66_macro_concat_end.c new file mode 100644 index 0000000..55dcaef --- /dev/null +++ b/tests/tests2/66_macro_concat_end.c @@ -0,0 +1,2 @@ +#define paste(A,B) A B## +paste(x,y) diff --git a/tests/tests2/66_macro_concat_end.expect b/tests/tests2/66_macro_concat_end.expect new file mode 100644 index 0000000..224e5c9 --- /dev/null +++ b/tests/tests2/66_macro_concat_end.expect @@ -0,0 +1 @@ +66_macro_concat_end.c:2: error: '##' invalid at end of macro diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index 36d84dc..41adb2d 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -79,7 +79,9 @@ TESTS = \ 61_undefined_enum.test \ 62_enumerator_redefinition.test \ 63_local_enumerator_redefinition.test \ - 64_macro_nesting.test + 64_macro_nesting.test \ + 65_macro_concat_start.test \ + 66_macro_concat_end.test # 30_hanoi.test -- seg fault in the code, gcc as well # 34_array_assignment.test -- array assignment is not in C standard -- cgit v1.3.1 From 469ae3a7e57aba6fd0f53afdf2657d8f1a439928 Mon Sep 17 00:00:00 2001 From: minux Date: Sat, 12 Apr 2014 01:10:58 -0400 Subject: build: ignore and properly clean tests/vla_test --- .gitignore | 1 + tests/Makefile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/.gitignore b/.gitignore index ad56048..348aba7 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,7 @@ tests/tests2/fred.txt tests/tests2/*.exe tests/hello tests/abitest-*cc +tests/vla_test .gdb_history tcc.1 tcc.pod diff --git a/tests/Makefile b/tests/Makefile index ee0eafe..e3824ba 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -241,5 +241,5 @@ clean: $(MAKE) -C tests2 $@ rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc \ *-cc *-tcc *.exe \ - hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h \ + hello libtcc_test vla_test tcctest[1234] ex? tcc_g tcclib.h \ ../lib/libtcc1.a -- cgit v1.3.1 From 6e56bb387db8af055ff6de71a23b270de55c3dc8 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Sat, 12 Apr 2014 12:00:13 +0800 Subject: Fix preprocessor concat with empty arg --- tcc.h | 1 + tccpp.c | 42 ++++++++++++++++++++++++++++++++----- tests/tests2/67_macro_concat.c | 14 +++++++++++++ tests/tests2/67_macro_concat.expect | 2 ++ tests/tests2/Makefile | 3 ++- 5 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 tests/tests2/67_macro_concat.c create mode 100644 tests/tests2/67_macro_concat.expect (limited to 'tests') diff --git a/tcc.h b/tcc.h index 9955839..dda2fc1 100644 --- a/tcc.h +++ b/tcc.h @@ -836,6 +836,7 @@ struct TCCState { /* <-- */ #define TOK_TWOSHARPS 0xc0 /* ## preprocessing token */ +#define TOK_PLCHLDR 0xc1 /* placeholder token as defined in C99 */ #define TOK_UMULL 0xc2 /* unsigned 32x32 -> 64 mul */ #define TOK_ADDC1 0xc3 /* add with carry generation */ #define TOK_ADDC2 0xc4 /* add with carry use */ diff --git a/tccpp.c b/tccpp.c index c8beec5..dfdee50 100644 --- a/tccpp.c +++ b/tccpp.c @@ -2565,7 +2565,8 @@ ST_FUNC void next_nomacro(void) } while (is_space(tok)); } -/* substitute args in macro_str and return allocated string */ +/* substitute arguments in replacement lists in macro_str by the values in + args (field d) and return allocated string */ static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args) { int last_tok, t, spc; @@ -2622,7 +2623,7 @@ static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args) if (gnu_ext && s->type.t && last_tok == TOK_TWOSHARPS && str.len >= 2 && str.str[str.len - 2] == ',') { - if (*st == 0) { + if (*st == TOK_PLCHLDR) { /* suppress ',' '##' */ str.len -= 2; } else { @@ -2793,6 +2794,8 @@ static int macro_subst_tok(TokenString *tok_str, tok_str_add2(&str, tok, &tokc); next_nomacro_spc(); } + if (!str.len) + tok_str_add(&str, TOK_PLCHLDR); str.len -= spc; tok_str_add(&str, 0); sa1 = sym_push2(&args, sa->v & ~SYM_FIELD, sa->type.t, 0); @@ -2885,9 +2888,11 @@ static inline int *macro_twosharps(const int *macro_str) TOK_GET(&t, &ptr, &cval); /* We concatenate the two tokens */ cstr_new(&cstr); - cstr_cat(&cstr, get_tok_str(tok, &tokc)); + if (tok != TOK_PLCHLDR) + cstr_cat(&cstr, get_tok_str(tok, &tokc)); n = cstr.size; - cstr_cat(&cstr, get_tok_str(t, &cval)); + if (t != TOK_PLCHLDR || tok == TOK_PLCHLDR) + cstr_cat(&cstr, get_tok_str(t, &cval)); cstr_ccat(&cstr, '\0'); tcc_open_bf(tcc_state, ":paste:", cstr.size); @@ -2904,8 +2909,35 @@ static inline int *macro_twosharps(const int *macro_str) cstr_free(&cstr); } } - if (tok != TOK_NOSUBST) + if (tok != TOK_NOSUBST) { + const int *oldptr; + CValue cval; + + /* Check if a space need to be added after ## concatenation in + order to avoid misinterpreting the newly formed token + followed by the next token as being a single token (see + macro_concat test) */ + cstr_new(&cstr); + cstr_cat(&cstr, get_tok_str(tok, &tokc)); + oldptr = ptr; + TOK_GET(&t, &ptr, &cval); + ptr = oldptr; + cstr_cat(&cstr, get_tok_str(t, &cval)); + cstr_ccat(&cstr, '\0'); + t = tok; + cval = tokc; + tcc_open_bf(tcc_state, ":paste:", cstr.size); + memcpy(file->buffer, cstr.data, cstr.size); + next_nomacro1(); + if (!*file->buf_ptr) { + tok_str_add2(¯o_str1, t, &cval); + tok = ' '; + } + tcc_close(); + cstr_free(&cstr); + start_of_nosubsts = -1; + } tok_str_add2(¯o_str1, tok, &tokc); } tok_str_add(¯o_str1, 0); diff --git a/tests/tests2/67_macro_concat.c b/tests/tests2/67_macro_concat.c new file mode 100644 index 0000000..c580d3a --- /dev/null +++ b/tests/tests2/67_macro_concat.c @@ -0,0 +1,14 @@ +#include + +#define P(A,B) A ## B ; bob +#define Q(A,B) A ## B+ + +int main(void) +{ + int bob, jim = 21; + bob = P(jim,) *= 2; + printf("jim: %d, bob: %d\n", jim, bob); + jim = 60 Q(+,)3; + printf("jim: %d\n", jim); + return 0; +} diff --git a/tests/tests2/67_macro_concat.expect b/tests/tests2/67_macro_concat.expect new file mode 100644 index 0000000..8386c2d --- /dev/null +++ b/tests/tests2/67_macro_concat.expect @@ -0,0 +1,2 @@ +jim: 21, bob: 42 +jim: 63 diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index 41adb2d..a7c8a2f 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -81,7 +81,8 @@ TESTS = \ 63_local_enumerator_redefinition.test \ 64_macro_nesting.test \ 65_macro_concat_start.test \ - 66_macro_concat_end.test + 66_macro_concat_end.test \ + 67_macro_concat.test # 30_hanoi.test -- seg fault in the code, gcc as well # 34_array_assignment.test -- array assignment is not in C standard -- cgit v1.3.1 From 0a51386960bcf116cce03fe61e21effd875cd792 Mon Sep 17 00:00:00 2001 From: minux Date: Sat, 12 Apr 2014 13:37:37 -0400 Subject: tests2: fix 30_hanoi test and enable it. --- tests/tests2/30_hanoi.c | 2 +- tests/tests2/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/tests2/30_hanoi.c b/tests/tests2/30_hanoi.c index b1a1181..7c0893b 100644 --- a/tests/tests2/30_hanoi.c +++ b/tests/tests2/30_hanoi.c @@ -68,7 +68,7 @@ void PrintAll() /* Returns the value moved (not used.) */ int Move(int *source, int *dest) { - int i,j; + int i = 0, j = 0; while (i Date: Sat, 12 Apr 2014 14:04:10 -0400 Subject: tests2: fix and enable 46_grep test. --- tests/tests2/46_grep.c | 13 ++++++++----- tests/tests2/46_grep.expect | 3 +++ tests/tests2/Makefile | 5 ++--- 3 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 tests/tests2/46_grep.expect (limited to 'tests') diff --git a/tests/tests2/46_grep.c b/tests/tests2/46_grep.c index 27589a4..3123bc3 100644 --- a/tests/tests2/46_grep.c +++ b/tests/tests2/46_grep.c @@ -15,6 +15,7 @@ * privileges were granted by DECUS. */ #include +#include /* * grep @@ -25,7 +26,6 @@ * See below for more information. */ -#if 0 char *documentation[] = { "grep searches a file for a given pattern. Execute by", " grep [flags] regular_expression file_list\n", @@ -70,7 +70,6 @@ char *patdoc[] = { " [a-z] matches alphabetics, while [z-a] never matches.", "The concatenation of regular expressions is a regular expression.", 0}; -#endif #define LMAX 512 #define PMAX 256 @@ -97,6 +96,10 @@ char *pp, lbuf[LMAX], pbuf[PMAX]; char *cclass(); char *pmatch(); +void store(int); +void error(char *); +void badpat(char *, char *, char *); +int match(void); /*** Display a file name *******************************/ @@ -300,7 +303,7 @@ void badpat(char *message, char *source, char *stop) /* char *stop; // Pattern end */ { fprintf(stderr, "-GREP-E-%s, pattern is\"%s\"\n", message, source); - fprintf(stderr, "-GREP-E-Stopped at byte %d, '%c'\n", + fprintf(stderr, "-GREP-E-Stopped at byte %ld, '%c'\n", stop-source, stop[-1]); error("?GREP-E-Bad pattern\n"); } @@ -338,7 +341,7 @@ void grep(FILE *fp, char *fn) } /*** Match line (lbuf) with pattern (pbuf) return 1 if match ***/ -void match() +int match() { char *l; /* Line pointer */ @@ -368,7 +371,7 @@ char *pmatch(char *line, char *pattern) p = pattern; while ((op = *p++) != ENDPAT) { if (debug > 1) - printf("byte[%d] = 0%o, '%c', op = 0%o\n", + printf("byte[%ld] = 0%o, '%c', op = 0%o\n", l-line, *l, *l, op); switch(op) { diff --git a/tests/tests2/46_grep.expect b/tests/tests2/46_grep.expect new file mode 100644 index 0000000..e8a6791 --- /dev/null +++ b/tests/tests2/46_grep.expect @@ -0,0 +1,3 @@ +File 46_grep.c: +/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ + diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index 6e0fa34..c47fe0a 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -84,11 +84,9 @@ TESTS = \ 66_macro_concat_end.test \ 67_macro_concat.test -# 30_hanoi.test -- seg fault in the code, gcc as well # 34_array_assignment.test -- array assignment is not in C standard -# 46_grep.test -- does not compile even with gcc -SKIP = 34_array_assignment.test 46_grep.test +SKIP = 34_array_assignment.test # some tests do not pass on all platforms, remove them for now ifeq ($(TARGETOS),Darwin) @@ -102,6 +100,7 @@ endif # Some tests might need arguments ARGS = 31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5 +46_grep.test : ARGS = '[^* ]*[:a:d: ]+\:\*-/: $$' 46_grep.c all test: $(filter-out $(SKIP),$(TESTS)) -- cgit v1.3.1 From 4b50557553a507014b433a5e5f297cbee90d919a Mon Sep 17 00:00:00 2001 From: jiang <30155751@qq.com> Date: Mon, 28 Apr 2014 12:28:56 +0800 Subject: add test for abitest.c --- tests/abitest.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/abitest.c b/tests/abitest.c index d3e151f..488de1e 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)) ? 0 : -1; + 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; } 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)) ? 0 : -1; + 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; } static int ret_2double_test(void) { @@ -130,6 +130,52 @@ 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); + printf("%Lf \n", a.x); + printf("%Lf \n", r.x); + 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. @@ -142,7 +188,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)) ? 0 : -1; + 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; } static int reg_pack_test(void) { @@ -168,7 +214,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)) ? 0 : -1; + 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; } static int reg_pack_longlong_test(void) { @@ -248,7 +294,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) ? 0 : -1; + return ((b.x == a.x*2) && (f(a).x == a.x*2)) ? 0 : -1; } static int two_member_union_test(void) { @@ -441,6 +487,8 @@ 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); + RUN_TEST(ret_longdouble_test2); RUN_TEST(reg_pack_test); RUN_TEST(reg_pack_longlong_test); RUN_TEST(sret_test); -- cgit v1.3.1 From 89f7aea98093b035dd74cfbdd3de41c46ad12b6e Mon Sep 17 00:00:00 2001 From: jiang <30155751@qq.com> Date: Mon, 28 Apr 2014 14:05:55 +0800 Subject: fix abitest.c for x86_64 bug --- tests/abitest.c | 2 -- x86_64-gen.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/abitest.c b/tests/abitest.c index 488de1e..3ad707a 100644 --- a/tests/abitest.c +++ b/tests/abitest.c @@ -138,8 +138,6 @@ static int ret_longdouble_test_callback2(void *ptr) { ret_longdouble_test_type a = {10}; ret_longdouble_test_type r; r = f(a); - printf("%Lf \n", a.x); - printf("%Lf \n", r.x); return ((r.x == a.x*5) && (f(a).x == a.x*5)) ? 0 : -1; } diff --git a/x86_64-gen.c b/x86_64-gen.c index eb201c8..12893a3 100644 --- a/x86_64-gen.c +++ b/x86_64-gen.c @@ -981,7 +981,7 @@ static X86_64_Mode classify_x86_64_inner(CType *ty) return x86_64_mode_memory; mode = x86_64_mode_none; - for (; f; f = f->next) + for (f = f->next; f; f = f->next) mode = classify_x86_64_merge(mode, classify_x86_64_inner(&f->type)); return mode; -- cgit v1.3.1