History

tccgen: void values, etc...

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

grischka committed 10 months ago

Commit 7e01b201 parent 016087c15 files · +161 −151Browse files

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t