originally, this was meant to avoid 'void' values leak to the gen-xxx.c generators which would otherwise try to load void from/to registers. Also catch invalid types such as 'unsigned bool' eariler. tccgen.c: - expr_cond()/gexpr(): ignore VT_VOID - gen_cast(): set float reg with static initializers to make backends happier with invalid input - init_putv(): improve static compound literal initializers Also: - ignore "missing prototype" and "might return no value" for old style K&R functions tcc.c, libtcc.c: - tcc_set_output_type(): return errors from loading crt1.o tcc.h/tccpp.c: - fix horrible longstanding mistake with sizeof SValue.tab. Must have place for sizeof (long double) rather than the target's LDOUBLE_SIZE. tccdefs.h: - add a fake __[u]int128_t for all platforms arm-gen.c: - gen_cvt_ftof() must load to reg always arm64-gen.c: - simplify arm64_pcs() a bit i386/x86_64-gen.c: - do not assume char is signed (for cross compilation arm->x86) tccelf/macho linker message: - instead of "undefined symbol 'X'" now say "unresolved reference to 'X'" which makes it more clear that it is a _linker_error_. tccasm.c: - .align/p2align: use 'nop's in exec sections
Unified · Split
| @@ -2283,8 +2283,9 @@ void gen_cvt_ftoi(int t) · 2282 unmodified lines | ||
| 2283 | 2283 | void gen_cvt_ftof(int t) |
| 2284 | 2284 | { |
| 2285 | 2285 | #ifdef TCC_ARM_VFP |
| 2286 | + uint32_t r = gv(RC_FLOAT); | |
| 2286 | 2287 | if(((vtop->type.t & VT_BTYPE) == VT_FLOAT) != ((t & VT_BTYPE) == VT_FLOAT)) { |
| 2287 | − uint32_t r = vfpr(gv(RC_FLOAT)); | |
| 2288 | + r = vfpr(r); | |
| 2288 | 2289 | o(0xEEB70AC0|(r<<12)|r|T2CPR(vtop->type.t)); |
| 2289 | 2290 | } |
| 2290 | 2291 | #else |
| @@ -278,7 +278,6 @@ static int arm64_type_size(int t) · 277 unmodified lines | ||
| 278 | 278 | case VT_DOUBLE: return 3; |
| 279 | 279 | case VT_LDOUBLE: return 4; |
| 280 | 280 | case VT_BOOL: return 0; |
| 281 | − case VT_VOID: return 0; | |
| 282 | 281 | } |
| 283 | 282 | assert(0); |
| 284 | 283 | return 0; |
| @@ -832,11 +831,10 @@ static unsigned long arm64_pcs_aux(int variadic, int n, CType **type, unsigned l · 547 unmodified lines | ||
| 832 | 831 | |
| 833 | 832 | for (i = 0; i < n; i++) { |
| 834 | 833 | int hfa = arm64_hfa(type[i], 0); |
| 835 | − int win_vararg_float = 0; | |
| 836 | − int size, align; | |
| 834 | + int size, align, bt; | |
| 837 | 835 | |
| 838 | − if ((type[i]->t & VT_ARRAY) || | |
| 839 | − (type[i]->t & VT_BTYPE) == VT_FUNC) | |
| 836 | + bt = type[i]->t & VT_BTYPE; | |
| 837 | + if (bt == VT_PTR || bt == VT_FUNC) | |
| 840 | 838 | size = align = 8; |
| 841 | 839 | else |
| 842 | 840 | size = type_size(type[i], &align); |
| @@ -848,13 +846,10 @@ static unsigned long arm64_pcs_aux(int variadic, int n, CType **type, unsigned l · 5 unmodified lines | ||
| 848 | 846 | } |
| 849 | 847 | |
| 850 | 848 | #elif defined(TCC_TARGET_PE) |
| 851 | − if (variadic && i >= variadic && (hfa || is_float(type[i]->t))) { | |
| 849 | + if (variadic && i >= variadic) { | |
| 852 | 850 | hfa = 0; |
| 853 | − if (is_float(type[i]->t)) { | |
| 854 | − win_vararg_float = 1; | |
| 855 | − size = 8; | |
| 856 | − align = 8; | |
| 857 | − } | |
| 851 | + if (is_float(bt)) | |
| 852 | + bt = VT_INT, size = align = 8; | |
| 858 | 853 | } |
| 859 | 854 | #endif |
| 860 | 855 | if (hfa) |
| @@ -871,12 +866,12 @@ static unsigned long arm64_pcs_aux(int variadic, int n, CType **type, unsigned l · 10 unmodified lines | ||
| 871 | 866 | } |
| 872 | 867 | continue; |
| 873 | 868 | } |
| 874 | − else if ((type[i]->t & VT_BTYPE) == VT_STRUCT) | |
| 869 | + else if (bt == VT_STRUCT) | |
| 875 | 870 | // B.4 |
| 876 | 871 | size = (size + 7) & ~7; |
| 877 | 872 | |
| 878 | 873 | // C.1 |
| 879 | − if (!win_vararg_float && is_float(type[i]->t) && nv < 8) { | |
| 874 | + if (is_float(bt) && nv < 8) { | |
| 880 | 875 | a[i] = 16 + (nv++ << 1); |
| 881 | 876 | continue; |
| 882 | 877 | } |
| @@ -895,24 +890,24 @@ static unsigned long arm64_pcs_aux(int variadic, int n, CType **type, unsigned l · 12 unmodified lines | ||
| 895 | 890 | } |
| 896 | 891 | |
| 897 | 892 | // C.4 |
| 898 | − if (hfa || (type[i]->t & VT_BTYPE) == VT_LDOUBLE) { | |
| 893 | + if (hfa || bt == VT_LDOUBLE) { | |
| 899 | 894 | ns = (ns + 7) & ~7; |
| 900 | 895 | ns = (ns + align - 1) & -align; |
| 901 | 896 | } |
| 902 | 897 | |
| 903 | 898 | // C.5 |
| 904 | − if ((type[i]->t & VT_BTYPE) == VT_FLOAT) | |
| 899 | + if (bt == VT_FLOAT) | |
| 905 | 900 | size = 8; |
| 906 | 901 | |
| 907 | 902 | // C.6 |
| 908 | − if (!win_vararg_float && (hfa || is_float(type[i]->t))) { | |
| 903 | + if (hfa || is_float(bt)) { | |
| 909 | 904 | a[i] = ns; |
| 910 | 905 | ns += size; |
| 911 | 906 | continue; |
| 912 | 907 | } |
| 913 | 908 | |
| 914 | 909 | // C.7 |
| 915 | − if ((type[i]->t & VT_BTYPE) != VT_STRUCT && size <= 8 && nx < 8) { | |
| 910 | + if (bt != VT_STRUCT && size <= 8 && nx < 8) { | |
| 916 | 911 | a[i] = nx++ << 1; |
| 917 | 912 | continue; |
| 918 | 913 | } |
| @@ -922,14 +917,14 @@ static unsigned long arm64_pcs_aux(int variadic, int n, CType **type, unsigned l · 3 unmodified lines | ||
| 922 | 917 | nx = (nx + 1) & ~1; |
| 923 | 918 | |
| 924 | 919 | // C.9 |
| 925 | − if ((type[i]->t & VT_BTYPE) != VT_STRUCT && size == 16 && nx < 7) { | |
| 920 | + if (bt != VT_STRUCT && size == 16 && nx < 7) { | |
| 926 | 921 | a[i] = nx << 1; |
| 927 | 922 | nx += 2; |
| 928 | 923 | continue; |
| 929 | 924 | } |
| 930 | 925 | |
| 931 | 926 | // C.10 |
| 932 | − if ((type[i]->t & VT_BTYPE) == VT_STRUCT && size <= (8 - nx) * 8) { | |
| 927 | + if (bt == VT_STRUCT && size <= (8 - nx) * 8) { | |
| 933 | 928 | a[i] = nx << 1; |
| 934 | 929 | nx += (size + 7) >> 3; |
| 935 | 930 | continue; |
| @@ -943,7 +938,7 @@ static unsigned long arm64_pcs_aux(int variadic, int n, CType **type, unsigned l · 7 unmodified lines | ||
| 943 | 938 | ns = (ns + align - 1) & -align; |
| 944 | 939 | |
| 945 | 940 | // C.13 |
| 946 | − if ((type[i]->t & VT_BTYPE) == VT_STRUCT) { | |
| 941 | + if (bt == VT_STRUCT) { | |
| 947 | 942 | a[i] = ns; |
| 948 | 943 | ns += size; |
| 949 | 944 | continue; |
| @@ -974,11 +969,11 @@ static unsigned long arm64_pcs(int variadic, int n, CType **type, unsigned long · 24 unmodified lines | ||
| 974 | 969 | } |
| 975 | 970 | |
| 976 | 971 | // Argument types: |
| 977 | − stack = arm64_pcs_aux(variadic, n, type + 1, a + 1); | |
| 972 | + stack = arm64_pcs_aux(variadic, n - 1, type + 1, a + 1); | |
| 978 | 973 | |
| 979 | 974 | if (0) { |
| 980 | 975 | int i; |
| 981 | − for (i = 0; i <= n; i++) { | |
| 976 | + for (i = 0; i < n; i++) { | |
| 982 | 977 | if (!i) |
| 983 | 978 | printf("arm64_pcs return: "); |
| 984 | 979 | else |
| @@ -1076,9 +1071,9 @@ ST_FUNC void gfunc_call(int nb_args) · 91 unmodified lines | ||
| 1076 | 1071 | |
| 1077 | 1072 | stack = arm64_pcs( |
| 1078 | 1073 | #ifdef TCC_TARGET_PE |
| 1079 | − old_style ? -1 : | |
| 1074 | + old_style ? /* all args like varargs in K&R style */ -1 : | |
| 1080 | 1075 | #endif |
| 1081 | − var_nb_arg, nb_args, t, a); | |
| 1076 | + var_nb_arg, nb_args + 1, t, a); | |
| 1082 | 1077 | |
| 1083 | 1078 | // Allocate space for structs replaced by pointer: |
| 1084 | 1079 | for (i = nb_args; i; i--) |
| @@ -1258,7 +1253,6 @@ ST_FUNC void gfunc_prolog(Sym *func_sym) · 173 unmodified lines | ||
| 1258 | 1253 | CType *func_type = &func_sym->type; |
| 1259 | 1254 | int n = 0; |
| 1260 | 1255 | int i = 0; |
| 1261 | − int pcs_n; | |
| 1262 | 1256 | Sym *sym; |
| 1263 | 1257 | CType **t; |
| 1264 | 1258 | unsigned long *a; |
| @@ -1266,35 +1260,32 @@ ST_FUNC void gfunc_prolog(Sym *func_sym) · 1 unmodified line | ||
| 1266 | 1260 | int last_int = 0; |
| 1267 | 1261 | int last_float = 0; |
| 1268 | 1262 | int variadic = func_sym->type.ref->f.func_type == FUNC_ELLIPSIS; |
| 1269 | − int var_nb_arg = n_func_args(&func_sym->type); | |
| 1270 | − int c; | |
| 1263 | + int var_nb_arg = variadic ? n_func_args(&func_sym->type) : 0; | |
| 1271 | 1264 | |
| 1272 | 1265 | func_vc = 144; // offset of where x8 is stored |
| 1273 | 1266 | |
| 1274 | 1267 | for (sym = func_type->ref; sym; sym = sym->next) |
| 1275 | 1268 | ++n; |
| 1276 | 1269 | |
| 1277 | − pcs_n = n - 1; | |
| 1278 | − c = n + variadic; | |
| 1279 | − t = tcc_malloc(c * sizeof(*t)); | |
| 1280 | − a = tcc_malloc(c * sizeof(*a)); | |
| 1270 | +#ifdef TCC_TARGET_PE | |
| 1271 | + n += variadic; | |
| 1272 | +#endif | |
| 1281 | 1273 | |
| 1274 | + t = tcc_malloc(n * sizeof(*t)); | |
| 1275 | + a = tcc_malloc(n * sizeof(*a)); | |
| 1282 | 1276 | for (sym = func_type->ref; sym; sym = sym->next) |
| 1283 | 1277 | t[i++] = &sym->type; |
| 1284 | 1278 | |
| 1285 | 1279 | #ifdef TCC_TARGET_PE |
| 1286 | − if (variadic) { | |
| 1287 | − t[i++] = &int_type; | |
| 1288 | − ++pcs_n; | |
| 1289 | − } | |
| 1280 | + if (variadic) | |
| 1281 | + t[i] = &int_type; | |
| 1290 | 1282 | #endif |
| 1291 | 1283 | |
| 1292 | − arm64_func_va_list_stack = arm64_pcs(variadic ? var_nb_arg : 0, | |
| 1293 | − pcs_n, t, a); | |
| 1284 | + arm64_func_va_list_stack = arm64_pcs(var_nb_arg, n, t, a); | |
| 1294 | 1285 | |
| 1295 | 1286 | #ifdef TCC_TARGET_PE |
| 1296 | 1287 | if (variadic) |
| 1297 | − arm64_func_va_list_stack = arm64_pe_param_off(a[n]); | |
| 1288 | + arm64_func_va_list_stack = arm64_pe_param_off(a[n - 1]); | |
| 1298 | 1289 | #endif |
| 1299 | 1290 | |
| 1300 | 1291 | #if !defined(TCC_TARGET_MACHO) |
| @@ -1304,6 +1295,7 @@ ST_FUNC void gfunc_prolog(Sym *func_sym) · 3 unmodified lines | ||
| 1304 | 1295 | last_float = 4; |
| 1305 | 1296 | } |
| 1306 | 1297 | #endif |
| 1298 | + | |
| 1307 | 1299 | if (a && a[0] == 1) |
| 1308 | 1300 | use_x8 = 1; |
| 1309 | 1301 | for (i = 1, sym = func_type->ref->next; sym; i++, sym = sym->next) { |
| @@ -1563,7 +1555,8 @@ ST_FUNC void gfunc_return(CType *func_type) · 253 unmodified lines | ||
| 1563 | 1555 | CType *t = func_type; |
| 1564 | 1556 | unsigned long a; |
| 1565 | 1557 | |
| 1566 | − arm64_pcs(0, 0, &t, &a); | |
| 1558 | + arm64_pcs(0, 1, &t, &a); | |
| 1559 | + | |
| 1567 | 1560 | switch (a) { |
| 1568 | 1561 | case -1: |
| 1569 | 1562 | break; |
| @@ -271,7 +271,7 @@ static void gen_modrm(int opc, int op_r2, int r, Sym *sym, int c) · 270 unmodified lines | ||
| 271 | 271 | } else if ((r & VT_VALMASK) == VT_LOCAL) { |
| 272 | 272 | o(opc); |
| 273 | 273 | /* currently, we use only ebp as base */ |
| 274 | − if (c == (char)c) { | |
| 274 | + if (c == (signed char)c) { | |
| 275 | 275 | /* short reference */ |
| 276 | 276 | o(0x45 | op_reg); |
| 277 | 277 | g(c); |
| @@ -439,7 +439,7 @@ ST_FUNC void store(int r, SValue *v) · 161 unmodified lines | ||
| 439 | 439 | |
| 440 | 440 | static void gadd_sp(int val) |
| 441 | 441 | { |
| 442 | − if (val == (char)val) { | |
| 442 | + if (val == (signed char)val) { | |
| 443 | 443 | o(0xc483); |
| 444 | 444 | g(val); |
| 445 | 445 | } else { |
| @@ -774,7 +774,7 @@ ST_FUNC void gjmp_addr(int a) · 328 unmodified lines | ||
| 774 | 774 | { |
| 775 | 775 | int r; |
| 776 | 776 | r = a - ind - 2; |
| 777 | − if (r == (char)r) { | |
| 777 | + if (r == (signed char)r) { | |
| 778 | 778 | g(0xeb); |
| 779 | 779 | g(r); |
| 780 | 780 | } else { |
| @@ -787,7 +787,7 @@ ST_FUNC void gjmp_addr(int a) · 6 unmodified lines | ||
| 787 | 787 | ST_FUNC void gjmp_cond_addr(int a, int op) |
| 788 | 788 | { |
| 789 | 789 | int r = a - ind - 2; |
| 790 | − if (r == (char)r) | |
| 790 | + if (r == (signed char)r) | |
| 791 | 791 | g(op - 32), g(r); |
| 792 | 792 | else |
| 793 | 793 | g(0x0f), gjmp2(op - 16, r - 4); |
| @@ -830,7 +830,7 @@ ST_FUNC void gen_opi(int op) · 36 unmodified lines | ||
| 830 | 830 | r = gv(RC_INT); |
| 831 | 831 | vswap(); |
| 832 | 832 | c = vtop->c.i; |
| 833 | − if (c == (char)c) { | |
| 833 | + if (c == (signed char)c) { | |
| 834 | 834 | /* generate inc and dec for smaller code */ |
| 835 | 835 | if ((c == 1 || c == -1) && (op == '+' || op == '-')) { |
| 836 | 836 | opc = (c == 1) ^ (op == '+'); |
| @@ -90,8 +90,6 @@ · 89 unmodified lines | ||
| 90 | 90 | #define __NO_TLS 1 |
| 91 | 91 | #define __RUNETYPE_INTERNAL 1 |
| 92 | 92 | # if __SIZEOF_POINTER__ == 8 |
| 93 | − /* FIXME, __int128_t is used by setjump */ | |
| 94 | − #define __int128_t struct { unsigned char _dummy[16] __attribute((aligned(16))); } | |
| 95 | 93 | #define __SIZEOF_SIZE_T__ 8 |
| 96 | 94 | #define __SIZEOF_PTRDIFF_T__ 8 |
| 97 | 95 | #else |
| @@ -142,12 +140,6 @@ · 44 unmodified lines | ||
| 142 | 140 | #endif |
| 143 | 141 | #define __INT32_TYPE__ int |
| 144 | 142 | |
| 145 | −#if defined __aarch64__ | |
| 146 | − /* GCC's __uint128_t appears in some Linux/OSX header files. Make it a | |
| 147 | − synonym for long double to get the size and alignment right. */ | |
| 148 | − #define __uint128_t long double | |
| 149 | −#endif | |
| 150 | − | |
| 151 | 143 | #if !defined _WIN32 |
| 152 | 144 | /* glibc defines. We do not support __USER_NAME_PREFIX__ */ |
| 153 | 145 | #define __REDIRECT(name, proto, alias) name proto __asm__ (#alias) |
| @@ -187,6 +179,12 @@ · 33 unmodified lines | ||
| 187 | 179 | # endif |
| 188 | 180 | #endif |
| 189 | 181 | |
| 182 | + /* GCC's __uint128_t appears in some Linux/OSX header files. | |
| 183 | + Just make it some type with same size and alignment. */ | |
| 184 | + struct __uint128__ { char x[16]; } __attribute((__aligned__(16))); | |
| 185 | + #define __int128_t struct __uint128__ | |
| 186 | + #define __uint128_t struct __uint128__ | |
| 187 | + | |
| 190 | 188 | /* __builtin_va_list */ |
| 191 | 189 | #if defined __x86_64__ |
| 192 | 190 | #if !defined _WIN32 |
| @@ -252,7 +252,7 @@ static void *default_reallocator(void *ptr, unsigned long size) · 251 unmodified lines | ||
| 252 | 252 | else { |
| 253 | 253 | ptr1 = realloc(ptr, size); |
| 254 | 254 | if (!ptr1) { |
| 255 | − fprintf(stderr, "memory full\n"); | |
| 255 | + fprintf(stderr, "tcc: memory full\n"); | |
| 256 | 256 | exit (1); |
| 257 | 257 | } |
| 258 | 258 | } |
| @@ -1003,9 +1003,9 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 744 unmodified lines | ||
| 1003 | 1003 | /* paths for crt objects */ |
| 1004 | 1004 | tcc_split_path(s, &s->crt_paths, &s->nb_crt_paths, CONFIG_TCC_CRTPREFIX); |
| 1005 | 1005 | if (output_type != TCC_OUTPUT_MEMORY && !s->nostdlib) |
| 1006 | − tccelf_add_crtbegin(s); | |
| 1006 | + tccelf_add_crtbegin(s); /* may produce errors */ | |
| 1007 | 1007 | #endif |
| 1008 | − return 0; | |
| 1008 | + return s->nb_errors ? -1 : 0; | |
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | 1011 | LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname) |
| @@ -35,7 +35,7 @@ static const char help[] = · 34 unmodified lines | ||
| 35 | 35 | "General options:\n" |
| 36 | 36 | " -c compile only - generate an object file\n" |
| 37 | 37 | " -o outfile set output filename\n" |
| 38 | − " -run run compiled source [with custom stdin: -rstdin FILE]\n" | |
| 38 | + " -run run compiled source\n" | |
| 39 | 39 | " -fflag set or reset (with 'no-' prefix) 'flag' (see tcc -hh)\n" |
| 40 | 40 | " -Wwarning set or reset (with 'no-' prefix) 'warning' (see tcc -hh)\n" |
| 41 | 41 | " -w disable all warnings\n" |
| @@ -105,6 +105,7 @@ static const char help2[] = · 63 unmodified lines | ||
| 105 | 105 | " -static link to static libraries (not recommended)\n" |
| 106 | 106 | " -dumpversion print version\n" |
| 107 | 107 | " -print-search-dirs print search paths\n" |
| 108 | + " -rstdin file with -run: use 'file' as custom stdin\n" | |
| 108 | 109 | " -dt with -run/-E: auto-define 'test_...' macros\n" |
| 109 | 110 | "Ignored options:\n" |
| 110 | 111 | " -arch -C --param -pedantic -pipe -s -traditional\n" |
| @@ -354,9 +355,10 @@ redo: · 243 unmodified lines | ||
| 354 | 355 | set_environment(s); |
| 355 | 356 | if (s->output_type == 0) |
| 356 | 357 | s->output_type = TCC_OUTPUT_EXE; |
| 357 | − tcc_set_output_type(s, s->output_type); | |
| 358 | + ret = tcc_set_output_type(s, s->output_type); | |
| 358 | 359 | if (ppfp) |
| 359 | 360 | s->ppfp = ppfp; |
| 361 | + | |
| 360 | 362 | if ((s->output_type == TCC_OUTPUT_MEMORY |
| 361 | 363 | || s->output_type == TCC_OUTPUT_PREPROCESS) |
| 362 | 364 | && (s->dflag & 16)) { /* -dt option */ |
| @@ -369,7 +371,7 @@ redo: · 6 unmodified lines | ||
| 369 | 371 | |
| 370 | 372 | /* compile or add each files or library */ |
| 371 | 373 | first_file = NULL; |
| 372 | − do { | |
| 374 | + while (0 == ret) { | |
| 373 | 375 | struct filespec *f = s->files[n]; |
| 374 | 376 | s->filetype = f->type; |
| 375 | 377 | if (f->type & AFF_TYPE_LIB) { |
| @@ -381,9 +383,11 @@ redo: · 5 unmodified lines | ||
| 381 | 383 | first_file = f->name; |
| 382 | 384 | ret = tcc_add_file(s, f->name); |
| 383 | 385 | } |
| 384 | − } while (++n < s->nb_files | |
| 385 | − && 0 == ret | |
| 386 | − && (s->output_type != TCC_OUTPUT_OBJ || s->option_r)); | |
| 386 | + if (++n == s->nb_files) | |
| 387 | + break; | |
| 388 | + if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r) | |
| 389 | + break; | |
| 390 | + } | |
| 387 | 391 | |
| 388 | 392 | if (s->do_bench) |
| 389 | 393 | end_time = getclock_ms(); |
| @@ -475,6 +475,9 @@ typedef struct CType { · 474 unmodified lines | ||
| 475 | 475 | struct Sym *ref; |
| 476 | 476 | } CType; |
| 477 | 477 | |
| 478 | +/* long double words on host(!) platform */ | |
| 479 | +#define LDOUBLE_WORDS ((sizeof(long double)+3)/4) | |
| 480 | + | |
| 478 | 481 | /* constant value */ |
| 479 | 482 | typedef union CValue { |
| 480 | 483 | long double ld; |
| @@ -485,7 +488,7 @@ typedef union CValue { · 4 unmodified lines | ||
| 485 | 488 | char *data; |
| 486 | 489 | int size; |
| 487 | 490 | } str; |
| 488 | − int tab[LDOUBLE_SIZE/4]; | |
| 491 | + int tab[LDOUBLE_WORDS]; | |
| 489 | 492 | } CValue; |
| 490 | 493 | |
| 491 | 494 | /* value on stack */ |
| @@ -1446,8 +1449,8 @@ ST_DATA int nocode_wanted; /* true if no code generation wanted for an expressio · 954 unmodified lines | ||
| 1446 | 1449 | ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */ |
| 1447 | 1450 | ST_DATA CType func_vt; /* current function return type (used by return instruction) */ |
| 1448 | 1451 | ST_DATA int func_var; /* true if current function is variadic */ |
| 1449 | −ST_DATA int func_vc; | |
| 1450 | −ST_DATA int func_ind; | |
| 1452 | +ST_DATA int func_vc; /* stack address for implicit struct return storage */ | |
| 1453 | +ST_DATA int func_ind; /* function start address */ | |
| 1451 | 1454 | ST_DATA const char *funcname; |
| 1452 | 1455 | |
| 1453 | 1456 | ST_FUNC void tccgen_init(TCCState *s1); |
| @@ -510,7 +510,7 @@ static void pop_section(TCCState *s1) · 509 unmodified lines | ||
| 510 | 510 | |
| 511 | 511 | static void asm_parse_directive(TCCState *s1, int global) |
| 512 | 512 | { |
| 513 | − int n, offset, v, size, tok1; | |
| 513 | + int n, offset, v, size, tok1, c; | |
| 514 | 514 | Section *sec; |
| 515 | 515 | uint8_t *ptr; |
| 516 | 516 | |
| @@ -540,18 +540,25 @@ static void asm_parse_directive(TCCState *s1, int global) · 23 unmodified lines | ||
| 540 | 540 | /* the section must have a compatible alignment */ |
| 541 | 541 | if (sec->sh_addralign < n) |
| 542 | 542 | sec->sh_addralign = n; |
| 543 | + c = sec->sh_flags & SHF_EXECINSTR; | |
| 543 | 544 | } else { |
| 544 | 545 | if (n < 0) |
| 545 | 546 | n = 0; |
| 546 | − size = n; | |
| 547 | + size = n, c = 0; | |
| 547 | 548 | } |
| 548 | 549 | v = 0; |
| 549 | 550 | if (tok == ',') { |
| 550 | 551 | next(); |
| 551 | − v = asm_int_expr(s1); | |
| 552 | + v = asm_int_expr(s1), c = 0; | |
| 552 | 553 | } |
| 553 | 554 | zero_pad: |
| 555 | + if ((uint64_t)ind + size >= 1<<30) | |
| 556 | + tcc_error("too much data"); | |
| 554 | 557 | if (sec->sh_type != SHT_NOBITS) { |
| 558 | + if (c) { | |
| 559 | + gen_fill_nops(size); | |
| 560 | + break; | |
| 561 | + } | |
| 555 | 562 | sec->data_offset = ind; |
| 556 | 563 | ptr = section_ptr_add(sec, size); |
| 557 | 564 | memset(ptr, v, size); |
| @@ -706,11 +713,9 @@ static void asm_parse_directive(TCCState *s1, int global) · 148 unmodified lines | ||
| 706 | 713 | expect("constant or same-section symbol"); |
| 707 | 714 | n += esym->st_value; |
| 708 | 715 | } |
| 709 | − if (n < 0 || n > 0x100000) | |
| 710 | − tcc_error(".org out of range"); | |
| 711 | 716 | if (n < ind) |
| 712 | 717 | tcc_error("attempt to .org backwards"); |
| 713 | − v = 0; | |
| 718 | + v = c = 0; | |
| 714 | 719 | size = n - ind; |
| 715 | 720 | goto zero_pad; |
| 716 | 721 | } |
| @@ -1106,7 +1106,7 @@ ST_FUNC void relocate_syms(TCCState *s1, Section *symtab, int do_resolve) · 1105 unmodified lines | ||
| 1106 | 1106 | if (sym_bind == STB_WEAK) |
| 1107 | 1107 | sym->st_value = 0; |
| 1108 | 1108 | else |
| 1109 | − tcc_error_noabort("undefined symbol '%s'", name); | |
| 1109 | + tcc_error_noabort("unresolved reference to '%s'", name); | |
| 1110 | 1110 | |
| 1111 | 1111 | } else if (sh_num < SHN_LORESERVE) { |
| 1112 | 1112 | /* add section base */ |
| @@ -2074,7 +2074,7 @@ static void bind_exe_dynsyms(TCCState *s1, int is_PIE) · 961 unmodified lines | ||
| 2074 | 2074 | if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK || |
| 2075 | 2075 | !strcmp(name, "_fp_hw")) { |
| 2076 | 2076 | } else { |
| 2077 | − tcc_error_noabort("undefined symbol '%s'", name); | |
| 2077 | + tcc_error_noabort("unresolved reference to '%s'", name); | |
| 2078 | 2078 | } |
| 2079 | 2079 | } |
| 2080 | 2080 | } |
| @@ -2105,7 +2105,7 @@ static void bind_libs_dynsyms(TCCState *s1) · 24 unmodified lines | ||
| 2105 | 2105 | if (esym->st_shndx == SHN_UNDEF) { |
| 2106 | 2106 | /* weak symbols can stay undefined */ |
| 2107 | 2107 | if (ELFW(ST_BIND)(esym->st_info) != STB_WEAK) |
| 2108 | − tcc_warning("undefined dynamic symbol '%s'", name); | |
| 2108 | + tcc_warning("unresolved dynamic reference to '%s'", name); | |
| 2109 | 2109 | } |
| 2110 | 2110 | } |
| 2111 | 2111 | } |
| @@ -3301,6 +3301,8 @@ invalid: · 1189 unmodified lines | ||
| 3301 | 3301 | continue; |
| 3302 | 3302 | if (sh->sh_type != s->sh_type |
| 3303 | 3303 | && strcmp (s->name, ".eh_frame") |
| 3304 | + /* some crt1.o seem to have two ".note.GNU-stack" (SHT_NOTE & SHT_PROGBITS) */ | |
| 3305 | + && strcmp (s->name, ".note.GNU-stack") | |
| 3304 | 3306 | ) { |
| 3305 | 3307 | tcc_error_noabort("section type conflict: %s %02x <> %02x", s->name, sh->sh_type, s->sh_type); |
| 3306 | 3308 | goto the_end; |
| @@ -70,8 +70,9 @@ ST_DATA int nocode_wanted; /* no code generation wanted */ · 69 unmodified lines | ||
| 70 | 70 | ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */ |
| 71 | 71 | ST_DATA CType func_vt; /* current function return type (used by return instruction) */ |
| 72 | 72 | ST_DATA int func_var; /* true if current function is variadic (used by return instruction) */ |
| 73 | −ST_DATA int func_vc; | |
| 74 | −ST_DATA int func_ind; | |
| 73 | +ST_DATA int func_vc; /* stack address for implicit struct return storage */ | |
| 74 | +ST_DATA int func_ind; /* function start address */ | |
| 75 | +static int func_old; | |
| 75 | 76 | ST_DATA const char *funcname; |
| 76 | 77 | ST_DATA CType int_type, func_old_type, char_type, char_pointer_type; |
| 77 | 78 | static CString initstr; |
| @@ -1385,7 +1386,7 @@ static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad) · 1307 unmodified lines | ||
| 1385 | 1386 | /* make sure that type->ref is on global stack */ |
| 1386 | 1387 | move_ref_to_global(s); |
| 1387 | 1388 | /* put into local scope */ |
| 1388 | − s = sym_copy(s, &local_stack); | |
| 1389 | + sym_copy(s, &local_stack); | |
| 1389 | 1390 | } |
| 1390 | 1391 | return s; |
| 1391 | 1392 | } |
| @@ -1906,6 +1907,8 @@ ST_FUNC int gv(int rc) · 514 unmodified lines | ||
| 1906 | 1907 | #endif |
| 1907 | 1908 | |
| 1908 | 1909 | bt = vtop->type.t & VT_BTYPE; |
| 1910 | + if (bt == VT_VOID || bt == VT_STRUCT) /* should not happen */ | |
| 1911 | + return vtop->r; | |
| 1909 | 1912 | |
| 1910 | 1913 | #ifdef TCC_TARGET_RISCV64 |
| 1911 | 1914 | /* XXX mega hack */ |
| @@ -2929,7 +2932,8 @@ static int combine_types(CType *dest, SValue *op1, SValue *op2, int op) · 1017 unmodified lines | ||
| 2929 | 2932 | type.ref = NULL; |
| 2930 | 2933 | |
| 2931 | 2934 | if (bt1 == VT_VOID || bt2 == VT_VOID) { |
| 2932 | − ret = op == '?' ? 1 : 0; | |
| 2935 | + if (op != '?') | |
| 2936 | + tcc_error("operation on void value"); | |
| 2933 | 2937 | /* NOTE: as an extension, we accept void on only one side */ |
| 2934 | 2938 | type.t = VT_VOID; |
| 2935 | 2939 | } else if (bt1 == VT_PTR || bt2 == VT_PTR) { |
| @@ -3176,7 +3180,7 @@ op_err: · 240 unmodified lines | ||
| 3176 | 3180 | } |
| 3177 | 3181 | // Make sure that we have converted to an rvalue: |
| 3178 | 3182 | if (vtop->r & VT_LVAL) |
| 3179 | − gv(is_float(vtop->type.t & VT_BTYPE) ? RC_FLOAT : RC_INT); | |
| 3183 | + gv(RC_TYPE(vtop->type.t)); | |
| 3180 | 3184 | } |
| 3181 | 3185 | |
| 3182 | 3186 | #if defined TCC_TARGET_ARM64 || defined TCC_TARGET_RISCV64 || defined TCC_TARGET_ARM |
| @@ -3281,8 +3285,10 @@ again: · 98 unmodified lines | ||
| 3281 | 3285 | df = is_float(dbt); |
| 3282 | 3286 | dbt_bt = dbt & VT_BTYPE; |
| 3283 | 3287 | sbt_bt = sbt & VT_BTYPE; |
| 3284 | − if (dbt_bt == VT_VOID) | |
| 3288 | + if (dbt_bt == VT_VOID) { | |
| 3289 | + vtop->r = vtop->r2 = VT_CONST; | |
| 3285 | 3290 | goto done; |
| 3291 | + } | |
| 3286 | 3292 | if (sbt_bt == VT_VOID) { |
| 3287 | 3293 | error: |
| 3288 | 3294 | cast_error(&vtop->type, type); |
| @@ -3361,8 +3367,11 @@ error: · 72 unmodified lines | ||
| 3361 | 3367 | } |
| 3362 | 3368 | |
| 3363 | 3369 | /* cannot generate code for global or static initializers */ |
| 3364 | − if (nocode_wanted & DATA_ONLY_WANTED) | |
| 3370 | + if (nocode_wanted & DATA_ONLY_WANTED) { | |
| 3371 | + if (df) | |
| 3372 | + vtop->r = get_reg(RC_FLOAT); /* don't confuse backends */ | |
| 3365 | 3373 | goto done; |
| 3374 | + } | |
| 3366 | 3375 | |
| 3367 | 3376 | /* non constant case: generate code */ |
| 3368 | 3377 | if (dbt == VT_BOOL) { |
| @@ -4753,6 +4762,8 @@ static int parse_btype(CType *type, AttributeDef *ad, int ignore_label) · 1384 unmodified lines | ||
| 4753 | 4762 | } else { |
| 4754 | 4763 | if (bt != -1 || (st != -1 && u != VT_INT)) |
| 4755 | 4764 | goto tmbt; |
| 4765 | + if ((t & VT_DEFSIGN) && (u == VT_VOID || u > VT_LLONG)) | |
| 4766 | + goto tmbt; | |
| 4756 | 4767 | bt = u; |
| 4757 | 4768 | } |
| 4758 | 4769 | if (u != VT_INT) |
| @@ -6112,6 +6123,7 @@ special_math_val: · 1353 unmodified lines | ||
| 6112 | 6123 | tcc_error("'%s' undeclared", name); |
| 6113 | 6124 | /* for simple function calls, we tolerate undeclared |
| 6114 | 6125 | external reference to int() function */ |
| 6126 | + if (!func_old) | |
| 6115 | 6127 | tcc_warning_c(warn_implicit_function_declaration)( |
| 6116 | 6128 | "implicit declaration of function '%s'", name); |
| 6117 | 6129 | s = external_global_sym(t, &func_old_type); |
| @@ -6660,7 +6672,7 @@ static void expr_cond(void) · 542 unmodified lines | ||
| 6660 | 6672 | |
| 6661 | 6673 | /* keep structs lvalue by transforming `(expr ? a : b)` to `*(expr ? &a : &b)` so |
| 6662 | 6674 | that `(expr ? a : b).mem` does not error with "lvalue expected" */ |
| 6663 | − islv = (vtop->r & VT_LVAL) && (sv.r & VT_LVAL) && VT_STRUCT == (type.t & VT_BTYPE); | |
| 6675 | + islv = VT_STRUCT == (type.t & VT_BTYPE); | |
| 6664 | 6676 | |
| 6665 | 6677 | /* now we convert second operand */ |
| 6666 | 6678 | if (c != 1) { |
| @@ -6668,8 +6680,7 @@ static void expr_cond(void) · 1 unmodified line | ||
| 6668 | 6680 | if (islv) { |
| 6669 | 6681 | mk_pointer(&vtop->type); |
| 6670 | 6682 | gaddrof(); |
| 6671 | − } else if (VT_STRUCT == (vtop->type.t & VT_BTYPE)) | |
| 6672 | − gaddrof(); | |
| 6683 | + } | |
| 6673 | 6684 | } |
| 6674 | 6685 | |
| 6675 | 6686 | rc = RC_TYPE(type.t); |
| @@ -6680,7 +6691,8 @@ static void expr_cond(void) · 4 unmodified lines | ||
| 6680 | 6691 | |
| 6681 | 6692 | tt = r2 = 0; |
| 6682 | 6693 | if (c < 0) { |
| 6683 | − r2 = gv(rc); | |
| 6694 | + if (type.t != VT_VOID) | |
| 6695 | + r2 = gv(rc); | |
| 6684 | 6696 | tt = gjmp(0); |
| 6685 | 6697 | } |
| 6686 | 6698 | gsym(u); |
| @@ -6695,14 +6707,15 @@ static void expr_cond(void) · 8 unmodified lines | ||
| 6695 | 6707 | if (islv) { |
| 6696 | 6708 | mk_pointer(&vtop->type); |
| 6697 | 6709 | gaddrof(); |
| 6698 | − } else if (VT_STRUCT == (vtop->type.t & VT_BTYPE)) | |
| 6699 | − gaddrof(); | |
| 6710 | + } | |
| 6700 | 6711 | } |
| 6701 | 6712 | |
| 6702 | 6713 | if (c < 0) { |
| 6703 | − r1 = gv(rc); | |
| 6704 | − move_reg(r2, r1, islv ? VT_PTR : type.t); | |
| 6705 | − vtop->r = r2; | |
| 6714 | + if (type.t != VT_VOID) { | |
| 6715 | + r1 = gv(rc); | |
| 6716 | + move_reg(r2, r1, islv ? VT_PTR : type.t); | |
| 6717 | + vtop->r = r2; | |
| 6718 | + } | |
| 6706 | 6719 | gsym(tt); |
| 6707 | 6720 | } |
| 6708 | 6721 | |
| @@ -6745,7 +6758,8 @@ ST_FUNC void gexpr(void) · 36 unmodified lines | ||
| 6745 | 6758 | |
| 6746 | 6759 | /* make builtin_constant_p((1,2)) return 0 (like on gcc) */ |
| 6747 | 6760 | if ((vtop->r & VT_VALMASK) == VT_CONST && nocode_wanted && !CONST_WANTED) |
| 6748 | − gv(RC_TYPE(vtop->type.t)); | |
| 6761 | + if (vtop->type.t != VT_VOID && (vtop->type.t & VT_BTYPE) != VT_STRUCT) | |
| 6762 | + gv(RC_TYPE(vtop->type.t)); | |
| 6749 | 6763 | } |
| 6750 | 6764 | } |
| 6751 | 6765 | |
| @@ -6855,11 +6869,10 @@ static void check_func_return(void) · 103 unmodified lines | ||
| 6855 | 6869 | { |
| 6856 | 6870 | if ((func_vt.t & VT_BTYPE) == VT_VOID) |
| 6857 | 6871 | return; |
| 6858 | − if (!strcmp (funcname, "main") | |
| 6872 | + if ((!strcmp(funcname, "main") || func_old) | |
| 6859 | 6873 | && (func_vt.t & VT_BTYPE) == VT_INT) { |
| 6860 | 6874 | /* main returns 0 by default */ |
| 6861 | 6875 | vpushi(0); |
| 6862 | − gen_assign_cast(&func_vt); | |
| 6863 | 6876 | gfunc_return(&func_vt); |
| 6864 | 6877 | } else { |
| 6865 | 6878 | tcc_warning("function might return no value: '%s'", funcname); |
| @@ -7242,6 +7255,8 @@ again: · 376 unmodified lines | ||
| 7242 | 7255 | tcc_warning("void function returns a value"); |
| 7243 | 7256 | vtop--; |
| 7244 | 7257 | } |
| 7258 | + } else if (b && func_old && (func_vt.t & VT_BTYPE) == VT_INT) { | |
| 7259 | + vpushi(0); | |
| 7245 | 7260 | } else if (b) { |
| 7246 | 7261 | tcc_warning("'return' with no value"); |
| 7247 | 7262 | b = 0; |
| @@ -7806,21 +7821,12 @@ static void init_putv(init_params *p, CType *type, unsigned long c) · 558 unmodified lines | ||
| 7806 | 7821 | ptr = sec->data + c; |
| 7807 | 7822 | val = vtop->c.i; |
| 7808 | 7823 | |
| 7809 | − /* XXX: make code faster ? */ | |
| 7810 | − if ((vtop->r & (VT_SYM|VT_CONST)) == (VT_SYM|VT_CONST) && | |
| 7811 | − vtop->sym->v >= SYM_FIRST_ANOM && | |
| 7812 | − /* XXX This rejects compound literals like | |
| 7813 | − '(void *){ptr}'. The problem is that '&sym' is | |
| 7814 | − represented the same way, which would be ruled out | |
| 7815 | − by the SYM_FIRST_ANOM check above, but also '"string"' | |
| 7816 | − in 'char *p = "string"' is represented the same | |
| 7817 | − with the type being VT_PTR and the symbol being an | |
| 7818 | − anonymous one. That is, there's no difference in vtop | |
| 7819 | − between '(void *){x}' and '&(void *){x}'. Ignore | |
| 7820 | − pointer typed entities here. Hopefully no real code | |
| 7821 | − will ever use compound literals with scalar type. */ | |
| 7822 | − (vtop->type.t & VT_BTYPE) != VT_PTR) { | |
| 7823 | − /* These come from compound literals, memcpy stuff over. */ | |
| 7824 | + if ((vtop->r & (VT_SYM|VT_CONST)) == (VT_SYM|VT_CONST) | |
| 7825 | + && vtop->sym->v >= SYM_FIRST_ANOM | |
| 7826 | + && ((vtop->r & VT_LVAL) /* compound literal */ | |
| 7827 | + || bt == VT_STRUCT /* designator */ | |
| 7828 | + )) { | |
| 7829 | + /* memcpy stuff over. */ | |
| 7824 | 7830 | Section *ssec; |
| 7825 | 7831 | ElfSym *esym; |
| 7826 | 7832 | ElfW_Rel *rel; |
| @@ -8072,6 +8078,8 @@ static void decl_initializer(init_params *p, CType *type, unsigned long c, int f · 245 unmodified lines | ||
| 8072 | 8078 | } |
| 8073 | 8079 | } |
| 8074 | 8080 | } |
| 8081 | + if (tok == ',' && !no_oblock) /* static const char s[] = { "123", }; */ | |
| 8082 | + next(); | |
| 8075 | 8083 | } else { |
| 8076 | 8084 | |
| 8077 | 8085 | do_init_array: |
| @@ -8528,6 +8536,7 @@ static void gen_function(Sym *sym) · 450 unmodified lines | ||
| 8528 | 8536 | func_ind = ind; |
| 8529 | 8537 | func_vt = sym->type.ref->type; |
| 8530 | 8538 | func_var = sym->type.ref->f.func_type == FUNC_ELLIPSIS; |
| 8539 | + func_old = sym->type.ref->f.func_type == FUNC_OLD; | |
| 8531 | 8540 | |
| 8532 | 8541 | /* NOTE: we patch the symbol size later */ |
| 8533 | 8542 | put_extern_sym(sym, cur_text_section, ind, 0); |
| @@ -702,7 +702,7 @@ static void check_relocs(TCCState *s1, struct macho *mo) · 701 unmodified lines | ||
| 702 | 702 | goti = tcc_realloc(goti, (mo->n_got + 1) * sizeof(*goti)); |
| 703 | 703 | if (ELFW(ST_BIND)(sym->st_info) == STB_LOCAL) { |
| 704 | 704 | if (sym->st_shndx == SHN_UNDEF) |
| 705 | − tcc_error("undefined local symbo: '%s'", | |
| 705 | + tcc_error("unresolved local reference to '%s'", | |
| 706 | 706 | (char *) symtab_section->link->data + sym->st_name); |
| 707 | 707 | goti[mo->n_got++] = INDIRECT_SYMBOL_LOCAL; |
| 708 | 708 | } else { |
| @@ -859,7 +859,7 @@ static void check_relocs(TCCState *s1, struct macho *mo) · 150 unmodified lines | ||
| 859 | 859 | goti = tcc_realloc(goti, (mo->n_got + 1) * sizeof(*goti)); |
| 860 | 860 | if (ELFW(ST_BIND)(sym->st_info) == STB_LOCAL) { |
| 861 | 861 | if (sym->st_shndx == SHN_UNDEF) |
| 862 | − tcc_error("undefined local symbo: '%s'", | |
| 862 | + tcc_error("unresolved local reference to '%s'", | |
| 863 | 863 | (char *) symtab_section->link->data + sym->st_name); |
| 864 | 864 | goti[mo->n_got++] = INDIRECT_SYMBOL_LOCAL; |
| 865 | 865 | } else { |
| @@ -1042,7 +1042,7 @@ static int check_symbols(TCCState *s1, struct macho *mo) · 176 unmodified lines | ||
| 1042 | 1042 | sym->st_shndx = SHN_FROMDLL; |
| 1043 | 1043 | continue; |
| 1044 | 1044 | } |
| 1045 | − tcc_error_noabort("undefined symbol '%s'", name); | |
| 1045 | + tcc_error_noabort("unresolved reference to '%s'", name); | |
| 1046 | 1046 | ret = -1; |
| 1047 | 1047 | } |
| 1048 | 1048 | } |
| @@ -987,11 +987,7 @@ static inline int tok_size(const int *p) · 986 unmodified lines | ||
| 987 | 987 | case TOK_CULLONG: |
| 988 | 988 | return 1 + 2; |
| 989 | 989 | case TOK_CLDOUBLE: |
| 990 | −#ifdef TCC_USING_DOUBLE_FOR_LDOUBLE | |
| 991 | − return 1 + 8 / 4; | |
| 992 | −#else | |
| 993 | − return 1 + LDOUBLE_SIZE / 4; | |
| 994 | −#endif | |
| 990 | + return 1 + LDOUBLE_WORDS; | |
| 995 | 991 | default: |
| 996 | 992 | return 1 + 0; |
| 997 | 993 | } |
| @@ -1130,22 +1126,12 @@ static void tok_str_add2(TokenString *s, int t, CValue *cv) · 132 unmodified lines | ||
| 1130 | 1126 | str[len++] = cv->tab[1]; |
| 1131 | 1127 | break; |
| 1132 | 1128 | case TOK_CLDOUBLE: |
| 1133 | −#if LDOUBLE_SIZE == 8 || defined TCC_USING_DOUBLE_FOR_LDOUBLE | |
| 1134 | − str[len++] = cv->tab[0]; | |
| 1135 | − str[len++] = cv->tab[1]; | |
| 1136 | −#elif LDOUBLE_SIZE == 12 | |
| 1137 | − str[len++] = cv->tab[0]; | |
| 1138 | − str[len++] = cv->tab[1]; | |
| 1139 | − str[len++] = cv->tab[2]; | |
| 1140 | −#elif LDOUBLE_SIZE == 16 | |
| 1141 | 1129 | str[len++] = cv->tab[0]; |
| 1142 | 1130 | str[len++] = cv->tab[1]; |
| 1131 | + if (LDOUBLE_WORDS >= 3) | |
| 1143 | 1132 | str[len++] = cv->tab[2]; |
| 1133 | + if (LDOUBLE_WORDS >= 4) | |
| 1144 | 1134 | str[len++] = cv->tab[3]; |
| 1145 | −#else | |
| 1146 | −#error add long double size support | |
| 1147 | −#endif | |
| 1148 | − break; | |
| 1149 | 1135 | default: |
| 1150 | 1136 | break; |
| 1151 | 1137 | } |
| @@ -1219,15 +1205,7 @@ static inline void tok_get(int *t, const int **pp, CValue *cv) · 67 unmodified lines | ||
| 1219 | 1205 | n = 2; |
| 1220 | 1206 | goto copy; |
| 1221 | 1207 | case TOK_CLDOUBLE: |
| 1222 | −#if LDOUBLE_SIZE == 8 || defined TCC_USING_DOUBLE_FOR_LDOUBLE | |
| 1223 | − n = 2; | |
| 1224 | −#elif LDOUBLE_SIZE == 12 | |
| 1225 | − n = 3; | |
| 1226 | −#elif LDOUBLE_SIZE == 16 | |
| 1227 | − n = 4; | |
| 1228 | −#else | |
| 1229 | −# error add long double size support | |
| 1230 | −#endif | |
| 1208 | + n = LDOUBLE_WORDS; | |
| 1231 | 1209 | copy: |
| 1232 | 1210 | do |
| 1233 | 1211 | *tab++ = *p++; |
| @@ -1465,17 +1465,37 @@ static int tab_reinit[10]; · 1464 unmodified lines | ||
| 1465 | 1465 | static int tentative_ar[]; |
| 1466 | 1466 | static int tentative_ar[] = {1,2,3}; |
| 1467 | 1467 | |
| 1468 | −//int cinit1; /* a global variable can be defined several times without error ! */ | |
| 1469 | −int cinit1; | |
| 1468 | +int cinit1; /* a global variable can be defined several times without error ! */ | |
| 1470 | 1469 | int cinit1; |
| 1471 | 1470 | int cinit1 = 0; |
| 1472 | 1471 | int *cinit2 = (int []){3, 2, 1}; |
| 1472 | +uintptr_t cinit3 = (uintptr_t)"AA"; | |
| 1473 | +char const * const cinit8[] = { [0 ... 1] = "BB", [2 ... 4] = "CC" }; | |
| 1474 | +void *cinit52 = &(void*){ (void*) 52 }; | |
| 1475 | + | |
| 1476 | +#if __TINYC__ || __GNUC__ >= 6 | |
| 1477 | +int cinit4 = (int){44}; | |
| 1478 | +void *cinit51 = (void*){ (void*) 51 }; | |
| 1479 | +struct _c6 { int a,b; } cinit6 = (struct _c6){61,62}, *cinit7 = &(struct _c6){71,72}; | |
| 1480 | +#else | |
| 1481 | +int cinit4 = 44; | |
| 1482 | +void *cinit51 = (void*)51; | |
| 1483 | +struct _c6 { int a,b; } cinit6 = { 61,62 }, cinit70 = {71,72}, *cinit7 = &cinit70; | |
| 1484 | +#endif | |
| 1473 | 1485 | |
| 1474 | 1486 | void compound_literal_test(void) |
| 1475 | 1487 | { |
| 1476 | 1488 | int *p, i; |
| 1477 | 1489 | char *q, *q3; |
| 1478 | 1490 | |
| 1491 | + printf("cinit3 : %s\n", cinit3); | |
| 1492 | + printf("cinit4 : %d\n", cinit4); | |
| 1493 | + printf("cinit51 : %d\n", (int)cinit51); | |
| 1494 | + printf("cinit52 : %d\n", *(int*)cinit52); | |
| 1495 | + printf("cinit6 : %d %d\n", cinit6.a, cinit6.b); | |
| 1496 | + printf("cinit7 : %d %d\n", cinit7->a, cinit7->b); | |
| 1497 | + printf("cinit8 : %s %s %s %s %s\n", cinit8[0], cinit8[1], cinit8[2], cinit8[3], cinit8[4]); | |
| 1498 | + | |
| 1479 | 1499 | p = (int []){1, 2, 3}; |
| 1480 | 1500 | for(i=0;i<3;i++) |
| 1481 | 1501 | printf(" %d", p[i]); |
| @@ -421,7 +421,7 @@ int f() { return v(); } · 420 unmodified lines | ||
| 421 | 421 | #elif defined test_switch_W4 |
| 422 | 422 | #pragma comment(option, "-Wunsupported -Wno-error=implicit-function-declaration -Werror") |
| 423 | 423 | #endif |
| 424 | −void func() | |
| 424 | +void func(void) | |
| 425 | 425 | { |
| 426 | 426 | char *ccp = "123"; |
| 427 | 427 | fink(); |
| @@ -314,7 +314,7 @@ static void gen_modrm_impl(int op_reg, int r, Sym *sym, int c, int is_got) · 313 unmodified lines | ||
| 314 | 314 | } |
| 315 | 315 | } else if ((r & VT_VALMASK) == VT_LOCAL) { |
| 316 | 316 | /* currently, we use only ebp as base */ |
| 317 | − if (c == (char)c) { | |
| 317 | + if (c == (signed char)c) { | |
| 318 | 318 | /* short reference */ |
| 319 | 319 | o(0x45 | op_reg); |
| 320 | 320 | g(c); |
| @@ -436,8 +436,7 @@ void load(int r, SValue *sv) · 115 unmodified lines | ||
| 436 | 436 | b = 0xdb, r = 5; /* fldt */ |
| 437 | 437 | } else if ((ft & VT_TYPE) == VT_BYTE || (ft & VT_TYPE) == VT_BOOL) { |
| 438 | 438 | b = 0xbe0f; /* movsbl */ |
| 439 | − } else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED) || | |
| 440 | − (ft & VT_TYPE) == (VT_BOOL | VT_UNSIGNED)) { | |
| 439 | + } else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) { | |
| 441 | 440 | b = 0xb60f; /* movzbl */ |
| 442 | 441 | } else if ((ft & VT_TYPE) == VT_SHORT) { |
| 443 | 442 | b = 0xbf0f; /* movswl */ |
| @@ -532,8 +531,7 @@ void load(int r, SValue *sv) · 88 unmodified lines | ||
| 532 | 531 | o(0x44 + REG_VALUE(r)*8); /* %xmmN */ |
| 533 | 532 | o(0xf024); |
| 534 | 533 | } else { |
| 535 | − if (!nocode_wanted) | |
| 536 | − assert((v >= TREG_XMM0) && (v <= TREG_XMM7)); | |
| 534 | + assert((v >= TREG_XMM0) && (v <= TREG_XMM7)); | |
| 537 | 535 | if ((ft & VT_BTYPE) == VT_FLOAT) { |
| 538 | 536 | o(0x100ff3); |
| 539 | 537 | } else { |
| @@ -543,8 +541,7 @@ void load(int r, SValue *sv) · 3 unmodified lines | ||
| 543 | 541 | o(0xc0 + REG_VALUE(v) + REG_VALUE(r)*8); |
| 544 | 542 | } |
| 545 | 543 | } else if (r == TREG_ST0) { |
| 546 | − if (!nocode_wanted) | |
| 547 | − assert((v >= TREG_XMM0) && (v <= TREG_XMM7)); | |
| 544 | + assert((v >= TREG_XMM0) && (v <= TREG_XMM7)); | |
| 548 | 545 | /* gen_cvt_ftof(VT_LDOUBLE); */ |
| 549 | 546 | /* movsd %xmmN,-0x10(%rsp) */ |
| 550 | 547 | o(0x110ff2); |
| @@ -749,7 +746,7 @@ static int arg_prepare_reg(int idx) { · 198 unmodified lines | ||
| 749 | 746 | static void gen_offs_sp(int b, int r, int d) |
| 750 | 747 | { |
| 751 | 748 | orex(1,0,r & 0x100 ? 0 : r, b); |
| 752 | − if (d == (char)d) { | |
| 749 | + if (d == (signed char)d) { | |
| 753 | 750 | o(0x2444 | (REG_VALUE(r) << 3)); |
| 754 | 751 | g(d); |
| 755 | 752 | } else { |
| @@ -1052,7 +1049,7 @@ void gfunc_epilog(void) · 296 unmodified lines | ||
| 1052 | 1049 | |
| 1053 | 1050 | static void gadd_sp(int val) |
| 1054 | 1051 | { |
| 1055 | − if (val == (char)val) { | |
| 1052 | + if (val == (signed char)val) { | |
| 1056 | 1053 | o(0xc48348); |
| 1057 | 1054 | g(val); |
| 1058 | 1055 | } else { |
| @@ -1635,7 +1632,7 @@ void gjmp_addr(int a) · 576 unmodified lines | ||
| 1635 | 1632 | { |
| 1636 | 1633 | int r; |
| 1637 | 1634 | r = a - ind - 2; |
| 1638 | − if (r == (char)r) { | |
| 1635 | + if (r == (signed char)r) { | |
| 1639 | 1636 | g(0xeb); |
| 1640 | 1637 | g(r); |
| 1641 | 1638 | } else { |
| @@ -1704,7 +1701,7 @@ void gen_opi(int op) · 62 unmodified lines | ||
| 1704 | 1701 | r = gv(RC_INT); |
| 1705 | 1702 | vswap(); |
| 1706 | 1703 | c = vtop->c.i; |
| 1707 | − if (c == (char)c) { | |
| 1704 | + if (c == (signed char)c) { | |
| 1708 | 1705 | /* XXX: generate inc and dec for smaller code ? */ |
| 1709 | 1706 | orex(ll, r, 0, 0x83); |
| 1710 | 1707 | o(0xc0 | (opc << 3) | REG_VALUE(r)); |