Also ... tcctest.c: - exclude stuff that gcc doesn't compile on windows. libtcc.c/tccpp.c: - use unsigned for memory sizes to avoid printf format warnings - use "file:line: message" to make IDE error parsers happy. tccgen.c: fix typo
Unified · Split
| @@ -248,20 +248,20 @@ PUB_FUNC void tcc_memstats(int bench) · 247 unmodified lines | ||
| 248 | 248 | #define MEM_DEBUG_FILE_LEN 15 |
| 249 | 249 | |
| 250 | 250 | struct mem_debug_header { |
| 251 | − size_t magic1; | |
| 252 | − size_t size; | |
| 251 | + unsigned magic1; | |
| 252 | + unsigned size; | |
| 253 | 253 | struct mem_debug_header *prev; |
| 254 | 254 | struct mem_debug_header *next; |
| 255 | − size_t line_num; | |
| 256 | − char file_name[MEM_DEBUG_FILE_LEN + 1]; | |
| 257 | − size_t magic2; | |
| 255 | + int line_num; | |
| 256 | + char file_name[MEM_DEBUG_FILE_LEN + 1]; | |
| 257 | + unsigned magic2; | |
| 258 | 258 | }; |
| 259 | 259 | |
| 260 | 260 | typedef struct mem_debug_header mem_debug_header_t; |
| 261 | 261 | |
| 262 | 262 | static mem_debug_header_t *mem_debug_chain; |
| 263 | −static size_t mem_cur_size; | |
| 264 | −static size_t mem_max_size; | |
| 263 | +static unsigned mem_cur_size; | |
| 264 | +static unsigned mem_max_size; | |
| 265 | 265 | |
| 266 | 266 | PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line) |
| 267 | 267 | { |
| @@ -312,13 +312,13 @@ PUB_FUNC void tcc_free_debug(void *ptr) · 44 unmodified lines | ||
| 312 | 312 | header = (mem_debug_header_t *)ptr; |
| 313 | 313 | if (header->magic1 != MEM_DEBUG_MAGIC1 || |
| 314 | 314 | header->magic2 != MEM_DEBUG_MAGIC2 || |
| 315 | − header->size == (size_t)-1 ) | |
| 315 | + header->size == (unsigned)-1 ) | |
| 316 | 316 | { |
| 317 | 317 | tcc_error("tcc_free check failed"); |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | mem_cur_size -= header->size; |
| 321 | − header->size = (size_t)-1; | |
| 321 | + header->size = (unsigned)-1; | |
| 322 | 322 | |
| 323 | 323 | if (header->next) |
| 324 | 324 | header->next->prev = header->prev; |
| @@ -355,7 +355,7 @@ PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file · 30 unmodified lines | ||
| 355 | 355 | header = (mem_debug_header_t *)ptr; |
| 356 | 356 | if (header->magic1 != MEM_DEBUG_MAGIC1 || |
| 357 | 357 | header->magic2 != MEM_DEBUG_MAGIC2 || |
| 358 | − header->size == (size_t)-1 ) | |
| 358 | + header->size == (unsigned)-1 ) | |
| 359 | 359 | { |
| 360 | 360 | check_error: |
| 361 | 361 | tcc_error("tcc_realloc check failed"); |
| @@ -414,6 +414,9 @@ PUB_FUNC void tcc_memstats(int bench) · 52 unmodified lines | ||
| 414 | 414 | header->file_name, header->line_num, header->size); |
| 415 | 415 | header = header->next; |
| 416 | 416 | } |
| 417 | +#if MEM_DEBUG-0 == 2 | |
| 418 | + exit(2); | |
| 419 | +#endif | |
| 417 | 420 | } |
| 418 | 421 | else if (bench) |
| 419 | 422 | fprintf(stderr, "mem_max_size= %d bytes\n", mem_max_size); |
| @@ -71,6 +71,7 @@ · 70 unmodified lines | ||
| 71 | 71 | # pragma warning (disable : 4996) // The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name |
| 72 | 72 | # pragma warning (disable : 4018) // signed/unsigned mismatch |
| 73 | 73 | # pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned |
| 74 | +# define ssize_t intptr_t | |
| 74 | 75 | # endif |
| 75 | 76 | # undef CONFIG_TCC_STATIC |
| 76 | 77 | #endif |
| @@ -5288,8 +5288,8 @@ static void expr_cond(void) · 5287 unmodified lines | ||
| 5288 | 5288 | |
| 5289 | 5289 | /* this is horrible, but we must also convert first |
| 5290 | 5290 | operand */ |
| 5291 | − vpushv(&sv); | |
| 5292 | − if (c != 2) { | |
| 5291 | + if (c != 0) { | |
| 5292 | + *vtop = sv; | |
| 5293 | 5293 | gen_cast(&type); |
| 5294 | 5294 | if (islv) { |
| 5295 | 5295 | mk_pointer(&vtop->type); |
| @@ -5298,17 +5298,14 @@ static void expr_cond(void) · 2 unmodified lines | ||
| 5298 | 5298 | gaddrof(); |
| 5299 | 5299 | } |
| 5300 | 5300 | |
| 5301 | − if (c != 0) | |
| 5302 | − vswap(); | |
| 5303 | − vtop--; | |
| 5304 | 5301 | if (c < 0) { |
| 5305 | 5302 | r1 = gv(rc); |
| 5306 | 5303 | move_reg(r2, r1, type.t); |
| 5307 | 5304 | vtop->r = r2; |
| 5305 | + gsym(tt); | |
| 5306 | + if (islv) | |
| 5307 | + indir(); | |
| 5308 | 5308 | } |
| 5309 | − gsym(tt); | |
| 5310 | − if (islv) | |
| 5311 | − indir(); | |
| 5312 | 5309 | } |
| 5313 | 5310 | } |
| 5314 | 5311 | } |
| @@ -137,22 +137,22 @@ ST_FUNC void expect(const char *msg) · 136 unmodified lines | ||
| 137 | 137 | #define CSTR_TAL_LIMIT 1024 |
| 138 | 138 | |
| 139 | 139 | typedef struct TinyAlloc { |
| 140 | − size_t limit; | |
| 141 | − size_t size; | |
| 140 | + unsigned limit; | |
| 141 | + unsigned size; | |
| 142 | 142 | uint8_t *buffer; |
| 143 | 143 | uint8_t *p; |
| 144 | − size_t nb_allocs; | |
| 144 | + unsigned nb_allocs; | |
| 145 | 145 | struct TinyAlloc *next, *top; |
| 146 | 146 | #ifdef TAL_INFO |
| 147 | − size_t nb_peak; | |
| 148 | − size_t nb_total; | |
| 149 | − size_t nb_missed; | |
| 147 | + unsigned nb_peak; | |
| 148 | + unsigned nb_total; | |
| 149 | + unsigned nb_missed; | |
| 150 | 150 | uint8_t *peak_p; |
| 151 | 151 | #endif |
| 152 | 152 | } TinyAlloc; |
| 153 | 153 | |
| 154 | 154 | typedef struct tal_header_t { |
| 155 | − size_t size; | |
| 155 | + unsigned size; | |
| 156 | 156 | #ifdef TAL_DEBUG |
| 157 | 157 | int line_num; /* negative line_num used for double free check */ |
| 158 | 158 | char file_name[TAL_DEBUG_FILE_LEN + 1]; |
| @@ -161,7 +161,7 @@ typedef struct tal_header_t { · 2 unmodified lines | ||
| 161 | 161 | |
| 162 | 162 | /* ------------------------------------------------------------------------- */ |
| 163 | 163 | |
| 164 | −ST_FUNC TinyAlloc *tal_new(TinyAlloc **pal, size_t limit, size_t size) | |
| 164 | +static TinyAlloc *tal_new(TinyAlloc **pal, unsigned limit, unsigned size) | |
| 165 | 165 | { |
| 166 | 166 | TinyAlloc *al = tcc_mallocz(sizeof(TinyAlloc)); |
| 167 | 167 | al->p = al->buffer = tcc_malloc(size); |
| @@ -171,7 +171,7 @@ ST_FUNC TinyAlloc *tal_new(TinyAlloc **pal, size_t limit, size_t size) · 3 unmodified lines | ||
| 171 | 171 | return al; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | −ST_FUNC void tal_delete(TinyAlloc *al) | |
| 174 | +static void tal_delete(TinyAlloc *al) | |
| 175 | 175 | { |
| 176 | 176 | TinyAlloc *next; |
| 177 | 177 | |
| @@ -192,11 +192,14 @@ tail_call: · 14 unmodified lines | ||
| 192 | 192 | while (p < al->p) { |
| 193 | 193 | tal_header_t *header = (tal_header_t *)p; |
| 194 | 194 | if (header->line_num > 0) { |
| 195 | − fprintf(stderr, " file %s, line %u: %u bytes\n", | |
| 195 | + fprintf(stderr, "%s:%d: chunk of %d bytes\n", | |
| 196 | 196 | header->file_name, header->line_num, header->size); |
| 197 | 197 | } |
| 198 | 198 | p += header->size + sizeof(tal_header_t); |
| 199 | 199 | } |
| 200 | +#if MEM_DEBUG-0 == 2 | |
| 201 | + exit(2); | |
| 202 | +#endif | |
| 200 | 203 | } |
| 201 | 204 | #endif |
| 202 | 205 | next = al->next; |
| @@ -206,7 +209,7 @@ tail_call: · 3 unmodified lines | ||
| 206 | 209 | goto tail_call; |
| 207 | 210 | } |
| 208 | 211 | |
| 209 | −ST_FUNC void tal_free_impl(TinyAlloc *al, void *p TAL_DEBUG_PARAMS) | |
| 212 | +static void tal_free_impl(TinyAlloc *al, void *p TAL_DEBUG_PARAMS) | |
| 210 | 213 | { |
| 211 | 214 | if (!p) |
| 212 | 215 | return; |
| @@ -215,10 +218,10 @@ tail_call: · 2 unmodified lines | ||
| 215 | 218 | #ifdef TAL_DEBUG |
| 216 | 219 | tal_header_t *header = (((tal_header_t *)p) - 1); |
| 217 | 220 | if (header->line_num < 0) { |
| 218 | − fprintf(stderr, "TAL_DEBUG: file %s, line %u double frees chunk from\n", | |
| 221 | + fprintf(stderr, "%s:%d: TAL_DEBUG: double frees chunk from\n", | |
| 219 | 222 | file, line); |
| 220 | − fprintf(stderr, " file %s, line %u: %u bytes\n", | |
| 221 | − header->file_name, -header->line_num, header->size); | |
| 223 | + fprintf(stderr, "%s:%d: %d bytes\n", | |
| 224 | + header->file_name, (int)-header->line_num, (int)header->size); | |
| 222 | 225 | } else |
| 223 | 226 | header->line_num = -header->line_num; |
| 224 | 227 | #endif |
| @@ -233,12 +236,12 @@ tail_call: · 8 unmodified lines | ||
| 233 | 236 | tcc_free(p); |
| 234 | 237 | } |
| 235 | 238 | |
| 236 | −ST_FUNC void *tal_realloc_impl(TinyAlloc **pal, void *p, size_t size TAL_DEBUG_PARAMS) | |
| 239 | +static void *tal_realloc_impl(TinyAlloc **pal, void *p, unsigned size TAL_DEBUG_PARAMS) | |
| 237 | 240 | { |
| 238 | 241 | tal_header_t *header; |
| 239 | 242 | void *ret; |
| 240 | 243 | int is_own; |
| 241 | − size_t adj_size = (size + 3) & -4; | |
| 244 | + unsigned adj_size = (size + 3) & -4; | |
| 242 | 245 | TinyAlloc *al = *pal; |
| 243 | 246 | |
| 244 | 247 | tail_call: |
| @@ -5,7 +5,7 @@ · 4 unmodified lines | ||
| 5 | 5 | TOP = .. |
| 6 | 6 | include $(TOP)/Makefile |
| 7 | 7 | VPATH = $(TOPSRC)/tests $(TOPSRC) $(TOP) |
| 8 | −CFLAGS = -I$(TOPSRC) -I$(TOP) | |
| 8 | +CFLAGS := $(filter-out -W% -g% -O%,$(CFLAGS)) -I$(TOPSRC) | |
| 9 | 9 | |
| 10 | 10 | # what tests to run |
| 11 | 11 | TESTS = \ |
| @@ -13,6 +13,7 @@ TESTS = \ · 1 unmodified line | ||
| 13 | 13 | hello-run \ |
| 14 | 14 | libtest \ |
| 15 | 15 | test3 \ |
| 16 | + memtest \ | |
| 16 | 17 | dlltest \ |
| 17 | 18 | abitest \ |
| 18 | 19 | vla_test-run \ |
| @@ -145,6 +146,12 @@ ifndef CONFIG_WIN32 · 126 unmodified lines | ||
| 145 | 146 | endif |
| 146 | 147 | @rm tcc2$(EXESUF) libtcc2$(DLLSUF) |
| 147 | 148 | |
| 149 | +memtest: | |
| 150 | + @echo ------------ $@ ------------ | |
| 151 | + $(CC) $(CFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -DMEM_DEBUG=2 ../tcc.c $(LIBS) -o memtest-tcc$(EXESUF) | |
| 152 | + ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE ../tcc.c $(LIBS) | |
| 153 | + ./memtest-tcc$(EXESUF) $(TCCFLAGS) $(NATIVE_DEFINES) -DONE_SOURCE -run ../tcc.c $(TCCFLAGS) tcctest.c | |
| 154 | + | |
| 148 | 155 | |
| 149 | 156 | # memory and bound check auto test |
| 150 | 157 | BOUNDS_OK = 1 4 8 10 14 |
| @@ -3122,6 +3122,7 @@ void other_constraints_test(void) · 3121 unmodified lines | ||
| 3122 | 3122 | printf ("oc1: %d\n", ret == (unsigned long)&var); |
| 3123 | 3123 | } |
| 3124 | 3124 | |
| 3125 | +#ifndef _WIN32 | |
| 3125 | 3126 | /* Test global asm blocks playing with aliases. */ |
| 3126 | 3127 | void base_func(void) |
| 3127 | 3128 | { |
| @@ -3161,6 +3162,7 @@ char * get_asm_string (void) · 33 unmodified lines | ||
| 3161 | 3162 | char * str = ((char*)bug_table) + bug_table[1]; |
| 3162 | 3163 | return str; |
| 3163 | 3164 | } |
| 3165 | +#endif | |
| 3164 | 3166 | |
| 3165 | 3167 | unsigned int set; |
| 3166 | 3168 | |
| @@ -3301,12 +3303,15 @@ void asm_test(void) · 134 unmodified lines | ||
| 3301 | 3303 | printf("set=0x%x\n", set); |
| 3302 | 3304 | val = 0x01020304; |
| 3303 | 3305 | printf("swab32(0x%08x) = 0x%0x\n", val, swab32(val)); |
| 3306 | +#ifndef _WIN32 | |
| 3304 | 3307 | override_func1(); |
| 3305 | 3308 | override_func2(); |
| 3306 | 3309 | /* The base_func ref from the following inline asm should find |
| 3307 | 3310 | the global one, not the local decl from this function. */ |
| 3308 | 3311 | asm volatile(".weak override_func3\n.set override_func3, base_func"); |
| 3309 | 3312 | override_func3(); |
| 3313 | + printf("asmstr: %s\n", get_asm_string()); | |
| 3314 | +#endif | |
| 3310 | 3315 | /* Check that we can also load structs of appropriate layout |
| 3311 | 3316 | into registers. */ |
| 3312 | 3317 | asm volatile("" : "=r" (asmret) : "0"(s2)); |
| @@ -3319,7 +3324,6 @@ void asm_test(void) · 6 unmodified lines | ||
| 3319 | 3324 | if (!somebool) |
| 3320 | 3325 | printf("asmbool: failed\n"); |
| 3321 | 3326 | #endif |
| 3322 | − printf("asmstr: %s\n", get_asm_string()); | |
| 3323 | 3327 | val = 43; |
| 3324 | 3328 | fancy_copy (&val, &val2); |
| 3325 | 3329 | printf ("fancycpy(%d)=%d\n", val, val2); |
| @@ -3677,10 +3681,12 @@ typedef struct gate_struct64 gate_desc; · 351 unmodified lines | ||
| 3677 | 3681 | gate_desc a_gate_desc; |
| 3678 | 3682 | void attrib_test(void) |
| 3679 | 3683 | { |
| 3684 | +#ifndef _WIN32 | |
| 3680 | 3685 | printf("attr: %d %d %d %d\n", sizeof(struct Spacked), |
| 3681 | 3686 | sizeof(spacked), sizeof(Spacked2), sizeof(spacked2)); |
| 3682 | 3687 | printf("attr: %d %d\n", sizeof(Spacked3), sizeof(spacked3)); |
| 3683 | 3688 | printf("attr: %d %d\n", sizeof(gate_desc), sizeof(a_gate_desc)); |
| 3689 | +#endif | |
| 3684 | 3690 | } |
| 3685 | 3691 | extern __attribute__((__unused__)) char * __attribute__((__unused__)) * |
| 3686 | 3692 | strange_attrib_placement (void); |
| @@ -63,7 +63,7 @@ all test: $(filter-out $(SKIP),$(TESTS)) · 62 unmodified lines | ||
| 63 | 63 | |
| 64 | 64 | # automatically generate .expect files with gcc: |
| 65 | 65 | %.expect : %.c |
| 66 | − (gcc -w $*.c -o a.exe && ./a.exe $(ARGS)) >$*.expect 2>&1; rm -f a.exe | |
| 66 | + (gcc -w $*.c -o a.exe && ./a.exe $(ARGS)) $(FILTER) >$*.expect 2>&1; rm -f a.exe | |
| 67 | 67 | |
| 68 | 68 | # tell make not to delete |
| 69 | 69 | .PRECIOUS: %.expect |