History

tccgen: nodata_wanted

The existing variable 'nocode_wanted' is now used to control output of static data too. So... (nocode_wanted == 0) code and data (normal within functions) (nocode_wanted < 0) means: no code, but data (global or static data) (nocode_wanted > 0) means: no code and no data (code and data suppressed) (nocode_wanted & 0xC0000000) means: we're in declaration of static data Also: new option '-dT' to be used with -run tcc -dT -run file.c This will look in file.c for certain comment-boundaries: /*-* test-xxx: ...some description */ and then for each test below run it from memory. This way various features and error messages can be tested with one single file. See 96_nodata_wanted.c for an example.

grischka committed 9 years ago

Commit 7f1ab9b1 parent 69a137f10 files · +329 −85Browse files

Unified · Split

10 files
  1. libtcc.c +2 −2
  2. tcc.c +2 −0
  3. tcc.h +1 −0
  4. tccgen.c +61 −34
  5. tcctools.c +105 −0
  6. tests/tests2/95_bitfields.c +1 −1
  7. tests/tests2/95_bitfields_ms.expect +8 −8
  8. tests/tests2/96_nodata_wanted.c +74 −0
  9. tests/tests2/96_nodata_wanted.expect +24 −0
  10. tests/tests2/Makefile +51 −40
libtcc.c+2−2
@@ -634,11 +634,9 @@ static int tcc_compile(TCCState *s1) · 633 unmodified lines
634634
635635 preprocess_start(s1);
636636 tccgen_start(s1);
637−
638637 #ifdef INC_DEBUG
639638 printf("%s: **** new file\n", file->filename);
640639 #endif
641−
642640 ch = file->buf_ptr[0];
643641 tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
644642 parse_flags = PARSE_FLAG_PREPROCESS | PARSE_FLAG_TOK_NUM | PARSE_FLAG_TOK_STR;
@@ -1801,6 +1799,8 @@ reparse: · 1156 unmodified lines
18011799 s->dflag = 3;
18021800 else if (*optarg == 'M')
18031801 s->dflag = 7;
1802+ else if (*optarg == 'T')
1803+ s->do_test = argc;
18041804 else if (isnum(*optarg))
18051805 g_debug = atoi(optarg);
18061806 else
tcc.c+2−0
@@ -282,6 +282,8 @@ redo: · 281 unmodified lines
282282 n = s->nb_files;
283283 if (n == 0)
284284 tcc_error("no input files\n");
285+ if (s->do_test)
286+ tcc_tool_test(s, argc, argv); /* maybe never returns */
285287
286288 if (s->output_type == TCC_OUTPUT_PREPROCESS) {
287289 if (!s->outfile) {
tcc.h+1−0
@@ -813,6 +813,7 @@ struct TCCState { · 812 unmodified lines
813813 int option_pthread; /* -pthread option */
814814 int argc;
815815 char **argv;
816+ int do_test;
816817 };
817818
818819 struct filespec {
tccgen.c+61−34
@@ -50,7 +50,9 @@ ST_DATA int vla_sp_loc; /* Pointer to variable holding location to store stack p · 49 unmodified lines
5050 ST_DATA SValue __vstack[1+VSTACK_SIZE], *vtop, *pvtop;
5151
5252 ST_DATA int const_wanted; /* true if constant wanted */
53−ST_DATA int nocode_wanted; /* true if no code generation wanted for an expression */
53+ST_DATA int nocode_wanted; /* no code generation wanted */
54+#define NODATA_WANTED (nocode_wanted > 0) /* no static data output wanted either */
55+#define STATIC_DATA_WANTED (nocode_wanted & 0xC0000000) /* only static data output */
5456 ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */
5557 ST_DATA CType func_vt; /* current function return type (used by return instruction) */
5658 ST_DATA int func_var; /* true if current function is variadic (used by return instruction) */
@@ -230,7 +232,7 @@ ST_FUNC void tccgen_start(TCCState *s1) · 173 unmodified lines
230232 anon_sym = SYM_FIRST_ANOM;
231233 section_sym = 0;
232234 const_wanted = 0;
233− nocode_wanted = 1;
235+ nocode_wanted = 0x80000000;
234236
235237 /* define some often used types */
236238 int_type.t = VT_INT;
@@ -1206,14 +1208,12 @@ ST_FUNC int gv(int rc) · 969 unmodified lines
12061208 } else {
12071209 if (is_float(vtop->type.t) &&
12081210 (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
1209− unsigned long offset;
12101211 /* CPUs usually cannot use float constants, so we store them
12111212 generically in data segment */
12121213 size = type_size(&vtop->type, &align);
1213− offset = section_add(data_section, size, align);
1214− vpush_ref(&vtop->type, data_section, offset, size);
1214+ vpush_ref(&vtop->type, data_section, data_section->data_offset, size);
12151215 vswap();
1216− init_putv(&vtop->type, data_section, offset);
1216+ init_putv(&vtop->type, data_section, data_section->data_offset);
12171217 vtop->r |= VT_LVAL;
12181218 }
12191219 #ifdef CONFIG_TCC_BCHECK
@@ -2329,6 +2329,11 @@ static void gen_cvt_ftoi1(int t) · 1109 unmodified lines
23292329 static void force_charshort_cast(int t)
23302330 {
23312331 int bits, dbt;
2332+
2333+ /* cannot cast static initializers */
2334+ if (STATIC_DATA_WANTED)
2335+ return;
2336+
23322337 dbt = t & VT_BTYPE;
23332338 /* XXX: add optimization if lvalue : just change type and offset */
23342339 if (dbt == VT_BYTE)
@@ -3405,12 +3410,9 @@ static void struct_layout(CType *type, AttributeDef *ad) · 1070 unmodified lines
34053410 //#define BF_DEBUG
34063411
34073412 for (f = type->ref->next; f; f = f->next) {
3408− if (f->type.t & VT_BITFIELD) {
3413+ if (f->type.t & VT_BITFIELD)
34093414 bit_size = BIT_SIZE(f->type.t);
3410− /* in pcc mode, long long bitfields have type int if they fit */
3411− if (pcc && (f->type.t & VT_BTYPE) == VT_LLONG && bit_size <= 32)
3412− f->type.t = (f->type.t & ~VT_BTYPE) | VT_INT;
3413− } else
3415+ else
34143416 bit_size = -1;
34153417 size = type_size(&f->type, &align);
34163418 a = f->a.aligned ? 1 << (f->a.aligned - 1) : 0;
@@ -3479,6 +3481,10 @@ static void struct_layout(CType *type, AttributeDef *ad) · 62 unmodified lines
34793481 goto new_field;
34803482 }
34813483
3484+ /* in pcc mode, long long bitfields have type int if they fit */
3485+ if (size == 8 && bit_size <= 32)
3486+ f->type.t = (f->type.t & ~VT_BTYPE) | VT_INT, size = 4;
3487+
34823488 while (bit_pos >= align * 8)
34833489 c += align, bit_pos -= align * 8;
34843490 offset = c;
@@ -4558,8 +4564,10 @@ ST_FUNC void unary(void) · 1073 unmodified lines
45584564 type.t |= VT_ARRAY;
45594565 type.ref->c = len;
45604566 vpush_ref(&type, data_section, data_section->data_offset, len);
4561− ptr = section_ptr_add(data_section, len);
4562− memcpy(ptr, funcname, len);
4567+ if (!NODATA_WANTED) {
4568+ ptr = section_ptr_add(data_section, len);
4569+ memcpy(ptr, funcname, len);
4570+ }
45634571 next();
45644572 }
45654573 break;
@@ -6314,7 +6322,7 @@ static int decl_designator(CType *type, Section *sec, unsigned long c, · 1748 unmodified lines
63146322 vstore();
63156323 }
63166324 vpop();
6317− } else {
6325+ } else if (!NODATA_WANTED) {
63186326 c_end = c + nb_elems * elem_size;
63196327 if (c_end > sec->data_allocated)
63206328 section_realloc(sec, c_end);
@@ -6348,9 +6356,25 @@ static void init_putv(CType *type, Section *sec, unsigned long c) · 27 unmodified lines
63486356 /* XXX: generate error if incorrect relocation */
63496357 gen_assign_cast(&dtype);
63506358 bt = type->t & VT_BTYPE;
6359+
6360+ if ((vtop->r & VT_SYM)
6361+ && bt != VT_PTR
6362+ && bt != VT_FUNC
6363+ && (bt != (PTR_SIZE == 8 ? VT_LLONG : VT_INT)
6364+ || (type->t & VT_BITFIELD))
6365+ && !((vtop->r & VT_CONST) && vtop->sym->v >= SYM_FIRST_ANOM)
6366+ )
6367+ tcc_error("initializer element is not computable at load time");
6368+
6369+ if (NODATA_WANTED) {
6370+ vtop--;
6371+ return;
6372+ }
6373+
63516374 size = type_size(type, &align);
63526375 section_reserve(sec, c + size);
63536376 ptr = sec->data + c;
6377+
63546378 /* XXX: make code faster ? */
63556379 if ((vtop->r & (VT_SYM|VT_CONST)) == (VT_SYM|VT_CONST) &&
63566380 vtop->sym->v >= SYM_FIRST_ANOM &&
@@ -6404,20 +6428,6 @@ static void init_putv(CType *type, Section *sec, unsigned long c) · 47 unmodified lines
64046428 }
64056429 }
64066430 } else {
6407− if ((vtop->r & VT_SYM) &&
6408− (bt == VT_BYTE ||
6409− bt == VT_SHORT ||
6410− bt == VT_DOUBLE ||
6411− bt == VT_LDOUBLE ||
6412−#if PTR_SIZE == 8
6413− bt == VT_INT ||
6414−#else
6415− bt == VT_LLONG ||
6416−#endif
6417− (type->t & VT_BITFIELD)
6418− ))
6419− tcc_error("initializer element is not computable at load time");
6420−
64216431 if (type->t & VT_BITFIELD) {
64226432 int bit_pos, bit_size, bits, n;
64236433 unsigned char *p, v, m;
@@ -6598,7 +6608,8 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 174 unmodified lines
65986608 string in global variable, we handle it
65996609 specifically */
66006610 if (sec && tok == TOK_STR && size1 == 1) {
6601− memcpy(sec->data + c + len, tokc.str.data, nb);
6611+ if (!NODATA_WANTED)
6612+ memcpy(sec->data + c + len, tokc.str.data, nb);
66026613 } else {
66036614 for(i=0;i<nb;i++) {
66046615 if (tok == TOK_STR)
@@ -6714,6 +6725,13 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 109 unmodified lines
67146725 Section *sec;
67156726 Sym *flexible_array;
67166727 Sym *sym = NULL;
6728+ int saved_nocode_wanted = nocode_wanted;
6729+#ifdef CONFIG_TCC_BCHECK
6730+ int bcheck = tcc_state->do_bounds_check && !NODATA_WANTED;
6731+#endif
6732+
6733+ if (type->t & VT_STATIC)
6734+ nocode_wanted |= NODATA_WANTED ? 0x40000000 : 0x80000000;
67176735
67186736 flexible_array = NULL;
67196737 if ((type->t & VT_BTYPE) == VT_STRUCT) {
@@ -6779,10 +6797,14 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 59 unmodified lines
67796797 } else if (ad->a.packed) {
67806798 align = 1;
67816799 }
6800+
6801+ if (NODATA_WANTED)
6802+ size = 0, align = 1;
6803+
67826804 if ((r & VT_VALMASK) == VT_LOCAL) {
67836805 sec = NULL;
67846806 #ifdef CONFIG_TCC_BCHECK
6785− if (tcc_state->do_bounds_check && (type->t & VT_ARRAY)) {
6807+ if (bcheck && (type->t & VT_ARRAY)) {
67866808 loc--;
67876809 }
67886810 #endif
@@ -6792,7 +6814,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 3 unmodified lines
67926814 /* handles bounds */
67936815 /* XXX: currently, since we do only one pass, we cannot track
67946816 '&' operators, so we add only arrays */
6795− if (tcc_state->do_bounds_check && (type->t & VT_ARRAY)) {
6817+ if (bcheck && (type->t & VT_ARRAY)) {
67966818 addr_t *bounds_ptr;
67976819 /* add padding between regions */
67986820 loc--;
@@ -6860,7 +6882,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 61 unmodified lines
68606882 addr = section_add(sec, size, align);
68616883 #ifdef CONFIG_TCC_BCHECK
68626884 /* add padding if bound check */
6863− if (tcc_state->do_bounds_check)
6885+ if (bcheck)
68646886 section_add(sec, 1, 1);
68656887 #endif
68666888 } else {
@@ -6888,7 +6910,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 21 unmodified lines
68886910 #ifdef CONFIG_TCC_BCHECK
68896911 /* handles bounds now because the symbol must be defined
68906912 before for the relocation */
6891− if (tcc_state->do_bounds_check) {
6913+ if (bcheck) {
68926914 addr_t *bounds_ptr;
68936915
68946916 greloca(bounds_section, sym, bounds_section->data_offset, R_DATA_PTR, 0);
@@ -6903,6 +6925,9 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 8 unmodified lines
69036925 if (type->t & VT_VLA) {
69046926 int a;
69056927
6928+ if (NODATA_WANTED)
6929+ goto no_alloc;
6930+
69066931 /* save current stack pointer */
69076932 if (vlas_in_scope == 0) {
69086933 if (vla_sp_root_loc == -1)
@@ -6935,6 +6960,8 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 26 unmodified lines
69356960 end_macro();
69366961 restore_parse_state(&saved_parse_state);
69376962 }
6963+
6964+ nocode_wanted = saved_nocode_wanted;
69386965 }
69396966
69406967 /* parse a function defined by symbol 'sym' and generate its code in
@@ -6978,7 +7005,7 @@ static void gen_function(Sym *sym) · 37 unmodified lines
69787005 func_vt.t = VT_VOID; /* for safety */
69797006 func_var = 0; /* for safety */
69807007 ind = 0; /* for safety */
6981− nocode_wanted = 1;
7008+ nocode_wanted = 0x80000000;
69827009 check_vstack();
69837010 }
69847011
tcctools.c+105−0
@@ -544,3 +544,108 @@ ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename) · 543 unmodified lines
544544 }
545545
546546 /* -------------------------------------------------------------- */
547+/* run test snippets from file */
548+
549+static char *readfile(const char *fname)
550+{
551+ char *buf;
552+ int fsize;
553+ FILE *fi;
554+ fi = fopen(fname, "rb");
555+ if (!fi)
556+ return NULL;
557+ fseek(fi, 0, SEEK_END);
558+ fsize = ftell(fi);
559+ fseek(fi, 0, SEEK_SET);
560+ buf = tcc_malloc(fsize + 1);
561+ fread(buf, fsize, 1, fi);
562+ fclose(fi);
563+ buf[fsize] = 0;
564+ return buf;
565+}
566+
567+static int run_prog(const char *prog, int ac, char **av)
568+{
569+ TCCState *s;
570+ int (*func)(int, char**);
571+ int ret = -10000;
572+
573+ s = tcc_new();
574+ tcc_parse_args(s, &ac, &av, 1);
575+ tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
576+ if (tcc_compile_string(s, prog) == -1)
577+ goto done;
578+ if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0)
579+ goto done;
580+ func = tcc_get_symbol(s, "main");
581+ if (!func)
582+ goto done;
583+ ret = func(ac, av);
584+done:
585+ tcc_delete(s);
586+ return ret;
587+}
588+
589+static char *trimback(char *a, char *e)
590+{
591+ while (e > a && (unsigned char)e[-1] <= ' ')
592+ --e;
593+ *e = 0;;
594+ return a;
595+}
596+
597+ST_FUNC int tcc_tool_test(TCCState *s, int argc, char **argv)
598+{
599+ const char *fname;
600+ char *buf, *p, *a, *b, *e, tmp[100];
601+ int r = 0, c, n;
602+ const char sep[] = "/*-* test";
603+
604+ n = s->do_test - argc;
605+ if (!n)
606+ return 0;
607+ fname = argv[0], argv -= n, argc += n;
608+
609+ buf = readfile(fname);
610+ if (NULL == buf)
611+ return -1;
612+ p = strstr(buf, sep);
613+ if (!p) {
614+ tcc_free(buf);
615+ return -1;
616+ }
617+
618+ while (*p) {
619+ a = p, p = strchr(p, '\n');
620+ if (NULL == p)
621+ break;
622+ *p++ = 0;
623+ b = p, p = strstr(p, sep);
624+ if (NULL == p)
625+ p = strchr(b, 0);
626+ c = *p, *p = 0;
627+
628+ trimback(a, b);
629+ if (r)
630+ printf("\n");
631+ printf("%s\n", a);
632+ fflush(stdout);
633+
634+ e = a += sizeof sep - 5;
635+ while (*e && *e != ':')
636+ ++e;
637+ if (!*e || e - a > 32)
638+ e = a + 4;
639+ n = snprintf(tmp, sizeof tmp, "#line 1 \"%.*s\"\n", (int)(e - a), a);
640+ if (b - buf >= n)
641+ b = memcpy(b - n, tmp, n);
642+ n = run_prog(b, argc, argv);
643+ if (n != -10000)
644+ printf("returns %d\n", n);
645+ *p = c, ++r;
646+ }
647+ tcc_free(buf);
648+ exit(0);
649+}
650+
651+/* -------------------------------------------------------------- */
tests/tests2/95_bitfields.c+1−1
@@ -58,7 +58,7 @@ · 57 unmodified lines
5858 struct M P __s {
5959 long long x : 45;
6060 long long : 2;
61− long long y : 35;
61+ long long y : 30;
6262 unsigned long long z : 38;
6363 char a; short b;
6464 };
tests/tests2/95_bitfields_ms.expect+8−8
@@ -23,8 +23,8 @@ values : 03 ffffffff 0f fffffff8 78 · 22 unmodified lines
2323 align/size : 4 8
2424
2525 ---- TEST 5 - MS-BITFIELDS ----
26−bits in use : 00000000FFFF00FF0000003FFFFFFFFF00000007FFFFFFFF00001FFFFFFFFFFF
27−bits as set : 0000000000770044000000000000007800000007F00000000000000123456789
26+bits in use : 00000000FFFF00FF0000003FFFFFFFFF000000003FFFFFFF00001FFFFFFFFFFF
27+bits as set : 0000000000770044000000000000007800000000300000000000000123456789
2828 values : 0000000123456789 fffffffff0000000 0000000000000078 44 77
2929 align/size : 8 32
3030
@@ -61,8 +61,8 @@ values : 03 ffffffff 0f fffffff8 78 · 30 unmodified lines
6161 align/size : 1 8
6262
6363 ---- TEST 5 - MS-BITFIELDS - PACKED ----
64−bits in use : FFFFFF0000003FFFFFFFFF00000007FFFFFFFF00001FFFFFFFFFFF
65−bits as set : 007744000000000000007800000007F00000000000000123456789
64+bits in use : FFFFFF0000003FFFFFFFFF000000003FFFFFFF00001FFFFFFFFFFF
65+bits as set : 007744000000000000007800000000300000000000000123456789
6666 values : 0000000123456789 fffffffff0000000 0000000000000078 44 77
6767 align/size : 1 27
6868
@@ -99,8 +99,8 @@ values : 03 ffffffff 0f fffffff8 78 · 30 unmodified lines
9999 align/size : 4 8
100100
101101 ---- TEST 5 - MS-BITFIELDS - WITH ALIGN ----
102−bits in use : 00000000FFFF00FF0000003FFFFFFFFF00000007FFFFFFFF00001FFFFFFFFFFF
103−bits as set : 0000000000770044000000000000007800000007F00000000000000123456789
102+bits in use : 00000000FFFF00FF0000003FFFFFFFFF000000003FFFFFFF00001FFFFFFFFFFF
103+bits as set : 0000000000770044000000000000007800000000300000000000000123456789
104104 values : 0000000123456789 fffffffff0000000 0000000000000078 44 77
105105 align/size : 8 32
106106
@@ -137,8 +137,8 @@ values : 03 ffffffff 0f fffffff8 78 · 30 unmodified lines
137137 align/size : 1 8
138138
139139 ---- TEST 5 - MS-BITFIELDS - PACKED - WITH ALIGN ----
140−bits in use : FFFFFF0000003FFFFFFFFF00000007FFFFFFFF00001FFFFFFFFFFF
141−bits as set : 007744000000000000007800000007F00000000000000123456789
140+bits in use : FFFFFF0000003FFFFFFFFF000000003FFFFFFF00001FFFFFFFFFFF
141+bits as set : 007744000000000000007800000000300000000000000123456789
142142 values : 0000000123456789 fffffffff0000000 0000000000000078 44 77
143143 align/size : 1 27
144144
tests/tests2/96_nodata_wanted.c+74−0
@@ -0,0 +1,74 @@
1+/*****************************************************************************/
2+/* test 'nodata_wanted' data output suppression */
3+
4+/*-* test 1: initializer not computable 1 */
5+void foo() {
6+ if (1) {
7+ static short w = (int)&foo; /* error */
8+ }
9+}
10+
11+/*-* test 2: initializer not computable 2 */
12+void foo() {
13+ if (0) {
14+ static short w = (int)&foo; /* error */
15+ }
16+}
17+
18+/*-* test 3: initializer not computable 3 */
19+void foo();
20+static short w = (int)&foo; /* error */
21+
22+
23+/*-* test 4: 2 cast warnings */
24+void foo() {
25+ short w = &foo; /* no error */
26+}
27+
28+/*-* test 5; nodata_wanted test */
29+#include <stdio.h>
30+
31+#define DATA_LBL(s) \
32+ __asm__(".global d"#s",t"#s"\n.data\nd"#s":\n.text\nt"#s":\n"); \
33+ extern char d##s[],t##s[];
34+
35+#define PROG \
36+ static void *p = (void*)&main;\
37+ static char cc[] = "static string";\
38+ static double d = 8.0;\
39+ static struct __attribute__((packed)) {\
40+ unsigned x : 12;\
41+ unsigned char y : 7;\
42+ unsigned z : 28, a: 4, b: 5;\
43+ } s = { 0x333,0x44,0x555555,6,7 };\
44+ printf(" static data: %d - %.1f - %.1f - %s - %s\n",\
45+ sizeof 8.0, 8.0, d, __FUNCTION__, cc);\
46+ printf(" static bitfields: %x %x %x %x %x\n", s.x, s.y, s.z, s.a, s.b);
47+
48+int main()
49+{
50+ printf("suppression off\n");
51+ DATA_LBL(s1);
52+ if (1) {
53+ PROG
54+ }
55+ DATA_LBL(e1);
56+ printf(" data length is %s\n", de1 - ds1 ? "not 0":"0");
57+ //printf(" text length is %s\n", te1 - ts1 ? "not 0":"0");
58+
59+ printf("suppression on\n");
60+ DATA_LBL(s2);
61+ if (0) {
62+ PROG
63+ }
64+ DATA_LBL(e2);
65+ printf(" data length is %x\n", de2 - ds2);
66+ //printf(" text length is %X\n", te2 - ts2);
67+ return 0;
68+}
69+
70+/*-* test 6: some test */
71+int main()
72+{
73+ return 34;
74+}
tests/tests2/96_nodata_wanted.expect+24−0
@@ -0,0 +1,24 @@
1+/*-* test 1: initializer not computable 1 */
2+test 1:3: error: initializer element is not computable at load time
3+
4+/*-* test 2: initializer not computable 2 */
5+test 2:3: error: initializer element is not computable at load time
6+
7+/*-* test 3: initializer not computable 3 */
8+test 3:2: error: initializer element is not computable at load time
9+
10+/*-* test 4: 2 cast warnings */
11+test 4:2: warning: assignment makes integer from pointer without a cast
12+test 4:2: warning: nonportable conversion from pointer to char/short
13+
14+/*-* test 5; nodata_wanted test */
15+suppression off
16+ static data: 8 - 8.0 - 8.0 - main - static string
17+ static bitfields: 333 44 555555 6 7
18+ data length is not 0
19+suppression on
20+ data length is 0
21+returns 0
22+
23+/*-* test 6: some test */
24+returns 34
tests/tests2/Makefile+51−40
@@ -5,29 +5,6 @@ VPATH = $(SRC) · 4 unmodified lines
55
66 TESTS = $(patsubst %.c,%.test,$(sort $(notdir $(wildcard $(SRC)/*.c))))
77
8−# Some tests might need arguments
9−ARGS =
10−31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5
11−46_grep.test : ARGS = '[^* ]*[:a:d: ]+\:\*-/: $$' $(SRC)/46_grep.c
12−
13−# And some tests don't test the right thing with -run
14−NORUN =
15−42_function_pointer.test : NORUN = true
16−
17−# Some tests might need different flags
18−FLAGS =
19−76_dollars_in_identifiers.test : FLAGS += -fdollars-in-identifiers
20−
21−# Always generate certain .expects (don't put these in the GIT),
22−GEN-ALWAYS = 95_bitfields.expect
23−
24−# Filter source directory in warnings/errors (out-of-tree builds)
25−FILTER = 2>&1 | sed 's,$(SRC)/,,g'
26−# Filter some always-warning
27−ifeq (-$(findstring arm,$(ARCH))-,-arm-)
28−FILTER += 2>&1 | grep -v 'warning: soft float ABI currently not supported'
29−endif
30−
318 # some tests do not pass on all platforms, remove them for now
329 SKIP = 34_array_assignment.test # array assignment is not in C standard
3310 ifeq ($(CONFIG_arm_eabi),yes) # not ARM soft-float
@@ -50,46 +27,80 @@ ifeq (-$(CONFIG_WIN32)-$(CONFIG_i386)$(CONFIG_arm)-,--yes-) · 16 unmodified lines
5027 SKIP += 95_bitfields_ms.test # type_align is differnt on 32bit-non-windows
5128 endif
5229
30+# Some tests might need arguments
31+ARGS =
32+31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5
33+46_grep.test : ARGS = '[^* ]*[:a:d: ]+\:\*-/: $$' $(SRC)/46_grep.c
34+
35+# And some tests don't test the right thing with -run
36+NORUN =
37+42_function_pointer.test : NORUN = true
38+
39+# Some tests might need different flags
40+FLAGS =
41+76_dollars_in_identifiers.test : FLAGS += -fdollars-in-identifiers
42+
43+# run the source file cut into snippets
44+96_nodata_wanted.test : FLAGS = -dT
45+
46+# Always generate certain .expects (don't put these in the GIT),
47+GEN-ALWAYS =
48+GEN-ALWAYS += 95_bitfields.expect
49+
50+# using the ms compiler for the really ms-compatible bitfields
51+95_bitfields_ms.test : GEN = $(GEN-MSC)
52+
53+# Filter source directory in warnings/errors (out-of-tree builds)
54+FILTER = 2>&1 | sed 's,$(SRC)/,,g'
55+# Filter some always-warning
56+ifeq (-$(findstring arm,$(ARCH))-,-arm-)
57+FILTER += 2>&1 | grep -v 'warning: soft float ABI currently not supported'
58+endif
59+
5360 all test tests2.all: $(filter-out $(SKIP),$(TESTS)) ;
5461
5562 %.test: %.c %.expect
5663 @echo Test: $*...
57− @$(if $(NORUN),\
58− ($(TCC) $(FLAGS) $< -o a.exe && ./a.exe $(ARGS)),\
59− $(TCC) $(FLAGS) -run $< $(ARGS)\
60− ) $(FILTER) >$*.output 2>&1 || true
61− @diff -Nbu $(filter %.expect,$^) $*.output \
62− && rm -f $*.output $(filter $*.expect,$(GEN-ALWAYS))
64+ @$(if $(NORUN),$(T1),$(T2)) $(if $(NODIFF),,$(T3))
6365
64−F1 = $(or $(filter $1_%,$(TESTS)),$1_???.test)
65−F2 = $1 UPDATE="$(patsubst %.test,%.expect,$1)"
66+T1 = $(TCC) $(FLAGS) $< -o a.exe && ./a.exe $(ARGS)
67+T2 = $(TCC) $(FLAGS) -run $< $(ARGS)
68+T3 = $(FILTER) >$*.output 2>&1 || true \
69+ && diff -Nbu $(filter %.expect,$^) $*.output \
70+ && rm -f $*.output $(filter $*.expect,$(GEN-ALWAYS))
6671
6772 # run single test and update .expect file, e.g. "make tests2.37+"
6873 tests2.%+:
6974 @$(MAKE) $(call F2,$(call F1,$*)) --no-print-directory
7075
76+# just run tcc to see the output, e.g. "make tests2.37-"
77+tests2.%-:
78+ @$(MAKE) $(call F1,$*) NODIFF=true --no-print-directory
79+
7180 # run single test, e.g. "make tests2.37"
7281 tests2.%:
7382 @$(MAKE) $(call F1,$*) --no-print-directory
7483
84+F1 = $(or $(filter $1_%,$(TESTS)),$1_???.test)
85+F2 = $1 UPDATE="$(patsubst %.test,%.expect,$1)"
86+
7587 # automatically generate .expect files with gcc:
7688 %.expect :
7789 @echo Generating: $@
78− @$(CC) -w -std=gnu99 $(FLAGS) $(SRC)/$*.c -o a.exe
79− @./a.exe $(ARGS) $(FILTER) >$@ 2>&1
80− @rm -f a.exe
90+ @$(call GEN,$(SRC)/$*.c) $(FILTER) >$@ 2>&1
91+ @rm -f *.exe *.obj *.pdb
8192
82−# using the ms compiler for the really ms-compatible bitfields
93+# using TCC for .expect if -dT in FLAGS
94+GEN = $(if $(findstring -dT,$(FLAGS)),$(GEN-TCC),$(GEN-CC))
95+GEN-CC = $(CC) -w -std=gnu99 $(FLAGS) $1 -o a.exe && ./a.exe $(ARGS)
96+GEN-TCC = $(TCC) $(FLAGS) -run $1 $(ARGS)
97+GEN-MSC = $(MS-CC) $1 && ./$(basename $@).exe
8398 MS-CC = cl
84−95_bitfields_ms.expect :
85− @echo Generating: $@
86− @$(MS-CC) $(basename $@).c
87− @./$(basename $@).exe >$@ 2>&1
88− @rm -f *.exe *.obj *.pdb
8999
90100 # tell make not to delete
91101 .PRECIOUS: %.expect
92102
103+# force .expect generation for these files
93104 $(sort $(GEN-ALWAYS) $(UPDATE)) : force
94105 force:
95106

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