diff --git a/Makefile b/Makefile index c980a4eb..33f2cd69 100644 --- a/Makefile +++ b/Makefile @@ -25,13 +25,14 @@ CFLAGS += $(CPPFLAGS) VPATH = $(TOPSRC) ifdef CONFIG_WIN32 + CFG = -win ifneq ($(CONFIG_static),yes) LIBTCC = libtcc$(DLLSUF) LIBTCCDEF = libtcc.def endif - CFGWIN = -win NATIVE_TARGET = $(ARCH)-win$(if $(findstring arm,$(ARCH)),ce,32) else + CFG = -unx LIBS=-lm -lpthread ifneq ($(CONFIG_ldl),no) LIBS+=-ldl @@ -44,21 +45,21 @@ else LINK_LIBTCC += -Wl,-rpath,"$(libdir)" endif endif - CFGWIN =-unx NATIVE_TARGET = $(ARCH) ifdef CONFIG_OSX NATIVE_TARGET = $(ARCH)-osx - ifneq ($(CC),tcc) + ifneq ($(CC_NAME),tcc) LDFLAGS += -flat_namespace -undefined warning endif export MACOSX_DEPLOYMENT_TARGET := 10.6 + export DYLD_LIBRARY_PATH := $(CURDIR)/$(TOP) endif endif # run local version of tcc with local libraries and includes TCCFLAGS-unx = -B$(TOP) -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) TCCFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include -I$(TOPSRC) -I$(TOP) -L$(TOP) -TCCFLAGS = $(TCCFLAGS$(CFGWIN)) +TCCFLAGS = $(TCCFLAGS$(CFG)) TCC = $(TOP)/tcc$(EXESUF) $(TCCFLAGS) # cross compiler targets to build @@ -110,9 +111,9 @@ cross: $(LIBTCC1_CROSS) $(PROGS_CROSS) # build specific cross compiler & lib cross-%: %-tcc$(EXESUF) %-libtcc1.a ; -install: ; @$(MAKE) --no-print-directory install$(CFGWIN) -install-strip: ; @$(MAKE) --no-print-directory install$(CFGWIN) CONFIG_strip=yes -uninstall: ; @$(MAKE) --no-print-directory uninstall$(CFGWIN) +install: ; @$(MAKE) --no-print-directory install$(CFG) +install-strip: ; @$(MAKE) --no-print-directory install$(CFG) CONFIG_strip=yes +uninstall: ; @$(MAKE) --no-print-directory uninstall$(CFG) ifdef CONFIG_cross all : cross @@ -228,11 +229,7 @@ tcc_p$(EXESUF): $($T_FILES) # static libtcc library libtcc.a: $(LIBTCC_OBJ) -ifeq ($(CC),tcc) - $(CC) -ar rcs $@ $^ -else $S$(AR) rcs $@ $^ -endif # dynamic libtcc library libtcc.so: $(LIBTCC_OBJ) diff --git a/arm-gen.c b/arm-gen.c index 44c7d8b3..011ba4d5 100644 --- a/arm-gen.c +++ b/arm-gen.c @@ -943,8 +943,6 @@ struct avail_regs { int first_free_reg; /* next free register in the sequence, hole excluded */ }; -#define AVAIL_REGS_INITIALIZER (struct avail_regs) { { 0, 0, 0}, 0, 0, 0 } - /* Find suitable registers for a VFP Co-Processor Register Candidate (VFP CPRC param) according to the rules described in the procedure call standard for the ARM architecture (AAPCS). If found, the registers are assigned to this @@ -1060,14 +1058,16 @@ struct param_plan { struct plan { struct param_plan *pplans; /* array of all the param plans */ struct param_plan *clsplans[NB_CLASSES]; /* per class lists of param plans */ + int nb_plans; }; -#define add_param_plan(plan,pplan,class) \ - do { \ - pplan.prev = plan->clsplans[class]; \ - plan->pplans[plan ## _nb] = pplan; \ - plan->clsplans[class] = &plan->pplans[plan ## _nb++]; \ - } while(0) +static void add_param_plan(struct plan* plan, int cls, int start, int end, SValue *v) +{ + struct param_plan *p = &plan->pplans[plan->nb_plans++]; + p->prev = plan->clsplans[cls]; + plan->clsplans[cls] = p; + p->start = start, p->end = end, p->sval = v; +} /* Assign parameters to registers and stack with alignment according to the rules in the procedure call standard for the ARM architecture (AAPCS). @@ -1090,14 +1090,11 @@ static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo) { int i, size, align; int ncrn /* next core register number */, nsaa /* next stacked argument address*/; - int plan_nb = 0; - struct param_plan pplan; - struct avail_regs avregs = AVAIL_REGS_INITIALIZER; + struct avail_regs avregs = {{0}}; ncrn = nsaa = 0; *todo = 0; - plan->pplans = nb_args ? tcc_malloc(nb_args * sizeof(*plan->pplans)) : NULL; - memset(plan->clsplans, 0, sizeof(plan->clsplans)); + for(i = nb_args; i-- ;) { int j, start_vfpreg = 0; CType type = vtop[-i].type; @@ -1120,11 +1117,8 @@ static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo) start_vfpreg = assign_vfpreg(&avregs, align, size); end_vfpreg = start_vfpreg + ((size - 1) >> 2); if (start_vfpreg >= 0) { - pplan = (struct param_plan) {start_vfpreg, end_vfpreg, &vtop[-i]}; - if (is_hfa) - add_param_plan(plan, pplan, VFP_STRUCT_CLASS); - else - add_param_plan(plan, pplan, VFP_CLASS); + add_param_plan(plan, is_hfa ? VFP_STRUCT_CLASS : VFP_CLASS, + start_vfpreg, end_vfpreg, &vtop[-i]); continue; } else break; @@ -1137,8 +1131,7 @@ static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo) * CORE_STRUCT_CLASS or the first of STACK_CLASS. */ for (j = ncrn; j < 4 && j < ncrn + size / 4; j++) *todo|=(1< 4) nsaa = (ncrn - 4) * 4; @@ -1156,24 +1149,18 @@ static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo) if (ncrn == 4) break; } - pplan = (struct param_plan) {ncrn, ncrn, &vtop[-i]}; - ncrn++; - if (is_long) - pplan.end = ncrn++; - add_param_plan(plan, pplan, CORE_CLASS); + add_param_plan(plan, CORE_CLASS, ncrn, ncrn + is_long, &vtop[-i]); + ncrn += 1 + is_long; continue; } } nsaa = (nsaa + (align - 1)) & ~(align - 1); - pplan = (struct param_plan) {nsaa, nsaa + size, &vtop[-i]}; - add_param_plan(plan, pplan, STACK_CLASS); + add_param_plan(plan, STACK_CLASS, nsaa, nsaa + size, &vtop[-i]); nsaa += size; /* size already rounded up before */ } return nsaa; } -#undef add_param_plan - /* Copy parameters to their final destination (core reg, VFP reg or stack) for function call. @@ -1378,6 +1365,10 @@ void gfunc_call(int nb_args) if (r == VT_CMP || (r & ~1) == VT_JMP) gv(RC_INT); + memset(&plan, 0, sizeof plan); + if (nb_args) + plan.pplans = tcc_malloc(nb_args * sizeof(*plan.pplans)); + args_size = assign_regs(nb_args, float_abi, &plan, &todo); #ifdef TCC_ARM_EABI @@ -1420,7 +1411,7 @@ void gfunc_prolog(Sym *func_sym) CType ret_type; #ifdef TCC_ARM_EABI - struct avail_regs avregs = AVAIL_REGS_INITIALIZER; + struct avail_regs avregs = {{0}}; #endif sym = func_type->ref; @@ -1471,7 +1462,7 @@ void gfunc_prolog(Sym *func_sym) #ifdef TCC_ARM_EABI if (float_abi == ARM_HARD_FLOAT) { func_vc += nf * 4; - avregs = AVAIL_REGS_INITIALIZER; + memset(&avregs, 0, sizeof avregs); } #endif pn = struct_ret, sn = 0; diff --git a/arm-link.c b/arm-link.c index 0d0fa3cf..9227b229 100644 --- a/arm-link.c +++ b/arm-link.c @@ -98,6 +98,7 @@ int gotplt_entry_type (int reloc_type) return -1; } +#ifndef TCC_TARGET_PE ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr) { Section *plt = s1->plt; @@ -160,6 +161,7 @@ ST_FUNC void relocate_plt(TCCState *s1) } } } +#endif void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val) { diff --git a/arm64-gen.c b/arm64-gen.c index fdb71bbe..3cadcdf0 100644 --- a/arm64-gen.c +++ b/arm64-gen.c @@ -802,7 +802,7 @@ static int arm64_hfa_aux(CType *type, int *fsize, int num) return -1; } -static int arm64_hfa(CType *type, int *fsize) +static int arm64_hfa(CType *type, unsigned *fsize) { if ((type->t & VT_BTYPE) == VT_STRUCT || ((type->t & VT_ARRAY) && ((type->t & VT_BTYPE) != VT_PTR))) { @@ -1086,7 +1086,7 @@ ST_FUNC void gfunc_call(int nb_args) else if (a[i] < 32) { // value in floating-point registers if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) { - uint32_t j, sz, n = arm64_hfa(&vtop->type, (int *)&sz); + uint32_t j, sz, n = arm64_hfa(&vtop->type, &sz); vtop->type.t = VT_PTR; gaddrof(); gv(RC_R30); @@ -1137,7 +1137,7 @@ ST_FUNC void gfunc_call(int nb_args) } else if (a[0] == 16) { - uint32_t j, sz, n = arm64_hfa(return_type, (int *)&sz); + uint32_t j, sz, n = arm64_hfa(return_type, &sz); for (j = 0; j < n; j++) o(0x3d000100 | (sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 | @@ -1213,7 +1213,7 @@ ST_FUNC void gfunc_prolog(Sym *func_sym) // HFAs of float and double need to be written differently: if (16 <= a[i] && a[i] < 32 && (sym->type.t & VT_BTYPE) == VT_STRUCT) { - uint32_t j, sz, k = arm64_hfa(&sym->type, (int *)&sz); + uint32_t j, sz, k = arm64_hfa(&sym->type, &sz); if (sz < 16) for (j = 0; j < k; j++) { o(0x3d0003e0 | -(sz & 8) << 27 | (sz & 4) << 29 | @@ -1277,7 +1277,7 @@ ST_FUNC void gen_va_start(void) ST_FUNC void gen_va_arg(CType *t) { int align, size = type_size(t, &align); - int fsize, hfa = arm64_hfa(t, (int *)&fsize); + unsigned fsize, hfa = arm64_hfa(t, &fsize); uint32_t r0, r1; if (is_float(t->t)) { @@ -1387,7 +1387,7 @@ ST_FUNC void gfunc_return(CType *func_type) } case 16: if ((func_type->t & VT_BTYPE) == VT_STRUCT) { - uint32_t j, sz, n = arm64_hfa(&vtop->type, (int *)&sz); + uint32_t j, sz, n = arm64_hfa(&vtop->type, &sz); gaddrof(); gv(RC_R(0)); for (j = 0; j < n; j++) diff --git a/configure b/configure index de55672e..5673d178 100755 --- a/configure +++ b/configure @@ -48,7 +48,8 @@ cpu= cpuver= gcc_major=0 gcc_minor=0 -gcc_name="gcc" +cc_name="gcc" +ar_set= # OS specific targetos=`uname` @@ -110,7 +111,7 @@ for opt do ;; --cc=*) cc=`echo $opt | cut -d '=' -f 2` ;; - --ar=*) ar=`echo $opt | cut -d '=' -f 2` + --ar=*) ar=`echo $opt | cut -d '=' -f 2` ; ar_set="yes" ;; --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}" ;; @@ -226,9 +227,6 @@ if test "$mingw32" = "yes" ; then if test "$source_path_used" = "no"; then source_path="." fi - if test "${cc%% *}" = "gcc"; then - test -z "$LDFLAGS" && LDFLAGS="-static" - fi test -z "$prefix" && prefix="C:/Program Files/tcc" test -z "$tccdir" && tccdir="${prefix}" test -z "$bindir" && bindir="${tccdir}" @@ -323,17 +321,17 @@ if test -z "$cross_prefix" ; then if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then echo "configure: error: '$cc' failed to compile conftest.c." else + cc_name="$($CONFTEST compiler)" gcc_major="$($CONFTEST version)" gcc_minor="$($CONFTEST minor)" - gcc_name="$($CONFTEST compiler)" + bigendian="$($CONFTEST bigendian)" + _triplet="$($CONFTEST triplet)" fi - bigendian="$($CONFTEST bigendian)" if test "$mingw32" = "no" ; then if test -z "$triplet"; then - tt="$($CONFTEST triplet)" - if test -n "$tt" -a -f "/usr/lib/$tt/crti.o" ; then - triplet="$tt" + if test -n "$_triplet" -a -f "/usr/lib/$_triplet/crti.o" ; then + triplet="$_triplet" fi fi @@ -364,6 +362,11 @@ if test -z "$cross_prefix" ; then echo "Perhaps you want ./configure --config-musl" fi fi + else # mingw32 = yes + if test "$cc_name" = "gcc"; then + # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll' + test -z "$LDFLAGS" && LDFLAGS="-static" + fi fi else # if cross compiling, cannot launch a program, so make a static guess @@ -377,11 +380,11 @@ if test "$bigendian" = "yes" ; then fi # a final configuration tuning -if ! echo "$cc" | grep -q "tcc"; then +if test "$cc_name" != "tcc"; then OPT1="-Wdeclaration-after-statement -fno-strict-aliasing" # we want -Wno- but gcc does not always reject unknown -Wno- options OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation" - if $cc --version 2>&1 | grep -q "clang"; then + if test "$cc_name" = "clang"; then OPT1="$OPT1 -fheinous-gnu-extensions" OPT2="$OPT2 -Wstring-plus-int" fi @@ -395,6 +398,8 @@ if ! echo "$cc" | grep -q "tcc"; then # cat cc_msg.txt # echo $CFLAGS rm -f cc_msg.txt a.out +else # cc is tcc + test "$ar_set" || ar="$cc -ar" fi fcho() { if test -n "$2"; then echo "$1$2"; fi } @@ -427,6 +432,7 @@ mandir=\$(DESTDIR)$mandir infodir=\$(DESTDIR)$infodir docdir=\$(DESTDIR)$docdir CC=$cc +CC_NAME=$cc_name GCC_MAJOR=$gcc_major GCC_MINOR=$gcc_minor AR=$ar @@ -502,6 +508,7 @@ fi cat >>$TMPH </dev/null 2>&1 diff --git a/conftest.c b/conftest.c index 404871a3..f3b6ea65 100644 --- a/conftest.c +++ b/conftest.c @@ -61,48 +61,57 @@ int main(int argc, char *argv[]) _setmode(_fileno(stdout), _O_BINARY); /* don't translate \n to \r\n */ #endif switch(argc == 2 ? argv[1][0] : 0) { - case 'b': + case 'b'://igendian { volatile unsigned foo = 0x01234567; puts(*(unsigned char*)&foo == 0x67 ? "no" : "yes"); break; } #if defined(__clang__) - case 'm': + case 'm'://inor printf("%d\n", __clang_minor__); break; - case 'v': + case 'v'://ersion printf("%d\n", __clang_major__); break; #elif defined(__TINYC__) - case 'v': + case 'v'://ersion puts("0"); break; - case 'm': + case 'm'://inor printf("%d\n", __TINYC__); break; +#elif defined(_MSC_VER) + case 'v'://ersion + puts("0"); + break; + case 'm'://inor + printf("%d\n", _MSC_VER); + break; #elif defined(__GNUC__) && defined(__GNUC_MINOR__) /* GNU comes last as other compilers may add 'GNU' compatibility */ - case 'm': + case 'm'://inor printf("%d\n", __GNUC_MINOR__); break; - case 'v': + case 'v'://ersion printf("%d\n", __GNUC__); break; #else - case 'm': - case 'v': + case 'm'://inor + case 'v'://ersion puts("0"); break; #endif - case 't': + case 't'://riplet puts(TRIPLET); break; - case 'c': + case 'c'://ompiler #if defined(__clang__) puts("clang"); #elif defined(__TINYC__) puts("tcc"); +#elif defined(_MSC_VER) + puts("msvc"); #elif defined(__GNUC__) puts("gcc"); #else diff --git a/lib/Makefile b/lib/Makefile index 11b8efe4..bc57be7f 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -8,11 +8,7 @@ VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown) X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-) -ifdef CONFIG_OSX -XTCC ?= DYLD_LIBRARY_PATH=$(TOP) $(TOP)/$(X)tcc$(EXESUF) -else XTCC ?= $(TOP)/$(X)tcc$(EXESUF) -endif XCC = $(XTCC) XAR = $(XTCC) -ar XFLAGS-unx = -B$(TOPSRC) diff --git a/riscv64-gen.c b/riscv64-gen.c index 391386f6..0907b5c7 100644 --- a/riscv64-gen.c +++ b/riscv64-gen.c @@ -578,7 +578,7 @@ static void reg_pass(CType *type, int *prc, int *fieldofs, int named) ST_FUNC void gfunc_call(int nb_args) { int i, align, size, areg[2]; - int info[nb_args ? nb_args : 1]; + int *info = tcc_malloc((nb_args + 1) * sizeof (int)); int stack_adj = 0, tempspace = 0, stack_add, ofs, splitofs = 0; SValue *sv; Sym *sa; @@ -775,6 +775,7 @@ ST_FUNC void gfunc_call(int nb_args) else EI(0x13, 0, 2, 2, stack_add); // addi sp, sp, adj } + tcc_free(info); } static int func_sub_sp_offset, num_va_regs, func_va_list_ofs; diff --git a/tccasm.c b/tccasm.c index ec665937..911052de 100644 --- a/tccasm.c +++ b/tccasm.c @@ -57,8 +57,8 @@ static int asm2cname(int v, int *addeddot) v = tok_alloc(name + 1, strlen(name) - 1)->tok; } else if (!strchr(name, '.')) { int n = strlen(name) + 2; - char newname[n]; - snprintf(newname, n, ".%s", name); + char newname[256]; + snprintf(newname, sizeof newname, ".%s", name); v = tok_alloc(newname, n - 1)->tok; *addeddot = 1; } diff --git a/tccgen.c b/tccgen.c index 4f82e7e4..c6ed80e3 100644 --- a/tccgen.c +++ b/tccgen.c @@ -4978,7 +4978,7 @@ the_end: bt = t & (VT_BTYPE|VT_LONG); if (bt == VT_LONG) t |= LONG_SIZE == 8 ? VT_LLONG : VT_INT; -#ifdef TCC_TARGET_PE +#if defined TCC_TARGET_PE || (defined _WIN32 && defined _MSC_VER) if (bt == VT_LDOUBLE) t = (t & ~(VT_BTYPE|VT_LONG)) | (VT_DOUBLE|VT_LONG); #endif diff --git a/tccmacho.c b/tccmacho.c index 9a1c01c0..fc8d598c 100644 --- a/tccmacho.c +++ b/tccmacho.c @@ -530,15 +530,20 @@ struct { uint32_t flags; char *name; } skinfo[sk_last] = { - [sk_text] = { 1, S_REGULAR | S_ATTR_PURE_INSTRUCTIONS + /*[sk_unknown] =*/ { 0 }, + /*[sk_discard] =*/ { 0 }, + /*[sk_text] =*/ { 1, S_REGULAR | S_ATTR_PURE_INSTRUCTIONS | S_ATTR_SOME_INSTRUCTIONS, "__text" }, - [sk_ro_data] = { 1, S_REGULAR, "__rodata" }, - [sk_nl_ptr] = { 2, S_NON_LAZY_SYMBOL_POINTERS, "__got" }, - [sk_init] = { 2, S_MOD_INIT_FUNC_POINTERS, "__mod_init_func" }, - [sk_fini] = { 2, S_MOD_TERM_FUNC_POINTERS, "__mod_term_func" }, - [sk_rw_data] = { 2, S_REGULAR, "__data" }, - [sk_bss] = { 2, S_ZEROFILL, "__bss" }, - [sk_linkedit] = { 3, S_REGULAR, NULL }, + /*[sk_stubs] =*/ { 0 }, + /*[sk_ro_data] =*/ { 1, S_REGULAR, "__rodata" }, + /*[sk_uw_info] =*/ { 0 }, + /*[sk_nl_ptr] =*/ { 2, S_NON_LAZY_SYMBOL_POINTERS, "__got" }, + /*[sk_la_ptr] =*/ { 0 }, + /*[sk_init] =*/ { 2, S_MOD_INIT_FUNC_POINTERS, "__mod_init_func" }, + /*[sk_fini] =*/ { 2, S_MOD_TERM_FUNC_POINTERS, "__mod_term_func" }, + /*[sk_rw_data] =*/ { 2, S_REGULAR, "__data" }, + /*[sk_bss] =*/ { 2, S_ZEROFILL, "__bss" }, + /*[sk_linkedit] =*/ { 3, S_REGULAR, NULL }, }; static void collect_sections(TCCState *s1, struct macho *mo) @@ -663,7 +668,7 @@ static void collect_sections(TCCState *s1, struct macho *mo) } if (sec) sec->align = al; - al = 1U << al; + al = 1ULL << al; if (al > 4096) tcc_warning("alignment > 4096"), sec->align = 12, al = 4096; curaddr = (curaddr + al - 1) & -al; @@ -779,7 +784,7 @@ ST_FUNC int macho_output_file(TCCState *s1, const char *filename) int fd, mode, file_type; FILE *fp; int i, ret = -1; - struct macho mo = {}; + struct macho mo = {0}; file_type = s1->output_type; if (file_type == TCC_OUTPUT_OBJ) @@ -912,8 +917,8 @@ ST_FUNC int macho_load_dll(TCCState *s1, int fd, const char *filename, int lev) { struct dylib_command *dc = (struct dylib_command*)lc; char *name = (char*)lc + dc->name; - dprintf(" REEXPORT %s\n", name); int subfd = open(name, O_RDONLY | O_BINARY); + dprintf(" REEXPORT %s\n", name); if (subfd < 0) tcc_warning("can't open %s (reexported from %s)", name, filename); else { diff --git a/tests/Makefile b/tests/Makefile index b62ddba9..67f1a020 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -73,6 +73,9 @@ ifeq ($(ARCH),i386) # by GCC in 32bit mode when PIC is enabled. test.ref: CFLAGS+=-fno-PIC -fno-PIE endif +ifeq ($(CC_NAME),msvc) +test.ref abitest : CC = gcc +endif RUN_TCC = $(NATIVE_DEFINES) -run $(TOPSRC)/tcc.c $(TCCFLAGS) DISAS = objdump -d @@ -302,7 +305,7 @@ clean: rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234] rm -f asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF) - rm -f ex? tcc_g weaktest.*.txt *.def libtcc_test_mt + rm -f ex? tcc_g weaktest.*.txt *.def *.pdb *.obj libtcc_test_mt @$(MAKE) -C tests2 $@ @$(MAKE) -C pp $@ diff --git a/tests/tcctest.c b/tests/tcctest.c index c90c02da..d158950e 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -2,6 +2,10 @@ * TCC auto test program */ #include "config.h" +#define CC_gcc 1 +#define CC_clang 2 +#define CC_tcc 3 +#define CC_msvc 4 /* cannot compile this file */ /* Unfortunately, gcc version < 3 does not handle that! */ #define ALL_ISOC99 @@ -1829,11 +1833,13 @@ void cast_test() printf("sizeof(-(char)'a') = %d\n", sizeof(-(char)'a')); printf("sizeof(~(char)'a') = %d\n", sizeof(-(char)'a')); +#if CC_NAME != CC_clang /* doesn't like non-portable conversions */ /* from pointer to integer types */ printf("%d %d %ld %ld %lld %lld\n", - (int)(long)p, (unsigned int)(long)p, + (int)p, (unsigned int)p, (long)p, (unsigned long)p, - (long long)(long)p, (unsigned long long)(long)p); + (long long)p, (unsigned long long)p); +#endif /* from integers to pointers */ printf("%p %p %p %p\n", diff --git a/tests/tests2/114_bound_signal.c b/tests/tests2/114_bound_signal.c index da88cb4b..e36ee639 100644 --- a/tests/tests2/114_bound_signal.c +++ b/tests/tests2/114_bound_signal.c @@ -8,52 +8,6 @@ #include #include -#if defined(__APPLE__) -/* - * clock_nanosleep is missing on all macOS version, add emulation. - */ - -/* scale factors */ -#define TIMING_GIGA 1000000000 -#define TIMER_ABSTIME 0 /* not used */ - -/* timespec difference (monotonic) right - left */ -static inline void -timespec_monodiff_rml(struct timespec *ts_out, const struct timespec *ts_in) { - /* - * out = in - out, - * where in > out - */ - ts_out->tv_sec = ts_in->tv_sec - ts_out->tv_sec; - ts_out->tv_nsec = ts_in->tv_nsec - ts_out->tv_nsec; - if (ts_out->tv_sec < 0) { - ts_out->tv_sec = 0; - ts_out->tv_nsec = 0; - } else if (ts_out->tv_nsec < 0) { - if (ts_out->tv_sec == 0) { - ts_out->tv_sec = 0; - ts_out->tv_nsec = 0; - } else { - ts_out->tv_sec = ts_out->tv_sec - 1; - ts_out->tv_nsec = ts_out->tv_nsec + TIMING_GIGA; - } - } -} - -static inline int -clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *req, struct timespec *remain) { - struct timespec ts_delta; - int retval = clock_gettime(clock_id, &ts_delta); - (void)remain; - (void)flags; - if (retval == 0) { - timespec_monodiff_rml(&ts_delta, req); - retval = nanosleep(&ts_delta, NULL); - } - return retval; -} -#endif - static volatile int run = 1; static int dummy[10]; static sem_t sem; @@ -116,7 +70,6 @@ main (void) int i; pthread_t id1, id2; struct sigaction act; - struct timespec request; sigjmp_buf sj; sigset_t m; @@ -125,17 +78,16 @@ main (void) act.sa_flags = 0; sigemptyset (&act.sa_mask); sigaction (SIGUSR1, &act, NULL); + sem_init (&sem, 1, 0); pthread_create(&id1, NULL, high_load, NULL); pthread_create(&id2, NULL, do_signal, NULL); - clock_gettime (CLOCK_MONOTONIC, &request); - request.tv_sec += 1; - request.tv_nsec += 0; + printf ("start\n"); - while (clock_nanosleep (CLOCK_MONOTONIC, TIMER_ABSTIME, &request, NULL)) { - } - printf ("end\n"); + sleep(1); run = 0; + printf ("end\n"); + pthread_join(id1, NULL); pthread_join(id2, NULL); sem_destroy (&sem); diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index b53622e6..6fb1d262 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -43,9 +43,7 @@ ifeq (-$(CONFIG_WIN32)-$(CONFIG_i386)$(CONFIG_arm)-,--yes-) endif ifeq (-$(CONFIG_WIN32)-,-yes-) SKIP += 106_pthread.test # No pthread support -endif -ifneq (-$(CONFIG_WIN32)-$(findstring $(GCC_MAJOR),3 4)-,---) - SKIP += 114_bound_signal.test # not on windows or older linuxes + SKIP += 114_bound_signal.test # No pthread support endif # Some tests might need arguments diff --git a/x86_64-gen.c b/x86_64-gen.c index d2931ca7..ee0b18e6 100644 --- a/x86_64-gen.c +++ b/x86_64-gen.c @@ -1289,11 +1289,11 @@ void gfunc_call(int nb_args) { X86_64_Mode mode; CType type; - int size, align, r, args_size, stack_adjust, i, reg_count; + int size, align, r, args_size, stack_adjust, i, reg_count, k; int nb_reg_args = 0; int nb_sse_args = 0; int sse_reg, gen_reg; - char _onstack[nb_args ? nb_args : 1], *onstack = _onstack; + char *onstack = tcc_malloc((nb_args + 1) * sizeof (char)); #ifdef CONFIG_TCC_BCHECK if (tcc_state->do_bounds_check) @@ -1339,9 +1339,9 @@ void gfunc_call(int nb_args) sse_reg = nb_sse_args; args_size = 0; stack_adjust &= 15; - for (i = 0; i < nb_args;) { + for (i = k = 0; i < nb_args;) { mode = classify_x86_64_arg(&vtop[-i].type, NULL, &size, &align, ®_count); - if (!onstack[i]) { + if (!onstack[i + k]) { ++i; continue; } @@ -1354,7 +1354,7 @@ void gfunc_call(int nb_args) args_size += 8; stack_adjust = 0; } - if (onstack[i] == 2) + if (onstack[i + k] == 2) stack_adjust = 1; vrotb(i+1); @@ -1404,9 +1404,11 @@ void gfunc_call(int nb_args) vpop(); --nb_args; - onstack++; + k++; } + tcc_free(onstack); + /* XXX This should be superfluous. */ save_regs(0); /* save used temporary registers */