ST_FUNC void vset(TCCState* tcc_state, CType *type, int r, int v) { CValue cval; memset(&cval, 0, sizeof(CValue)); cval.i = v; //,<<<<<<<<<<< here is the main bug that mix with garbage vsetc(tcc_state, type, r, &cval); } /* store a value or an expression directly in global data or in local array */ static void init_putv(TCCState* tcc_state, CType *type, Section *sec, unsigned long c, int v, int expr_type) { ... case VT_PTR: if (tcc_state->tccgen_vtop->r & VT_SYM) { greloc(tcc_state, sec, tcc_state->tccgen_vtop->sym, c, R_DATA_PTR); } //<<< on the next line is where we try to get the assigned value to cvalue.i as cvalue.ull *(addr_t *)ptr |= (tcc_state->tccgen_vtop->c.ull & bit_mask) << bit_pos; break; Also this patch makes vla tests pass on linux 32 bits
Unified · Split
| @@ -329,6 +329,7 @@ static void vsetc(CType *type, int r, CValue *vc) · 328 unmodified lines | ||
| 329 | 329 | void vpush(CType *type) |
| 330 | 330 | { |
| 331 | 331 | CValue cval; |
| 332 | + memset(&cval, 0, sizeof(CValue)); | |
| 332 | 333 | vsetc(type, VT_CONST, &cval); |
| 333 | 334 | } |
| 334 | 335 | |
| @@ -336,6 +337,7 @@ void vpush(CType *type) · 1 unmodified line | ||
| 336 | 337 | ST_FUNC void vpushi(int v) |
| 337 | 338 | { |
| 338 | 339 | CValue cval; |
| 340 | + memset(&cval, 0, sizeof(CValue)); | |
| 339 | 341 | cval.i = v; |
| 340 | 342 | vsetc(&int_type, VT_CONST, &cval); |
| 341 | 343 | } |
| @@ -344,6 +346,7 @@ ST_FUNC void vpushi(int v) · 2 unmodified lines | ||
| 344 | 346 | static void vpushs(long long v) |
| 345 | 347 | { |
| 346 | 348 | CValue cval; |
| 349 | + memset(&cval, 0, sizeof(CValue)); | |
| 347 | 350 | if (PTR_SIZE == 4) |
| 348 | 351 | cval.i = (int)v; |
| 349 | 352 | else |
| @@ -354,8 +357,9 @@ static void vpushs(long long v) · 4 unmodified lines | ||
| 354 | 357 | /* push arbitrary 64bit constant */ |
| 355 | 358 | void vpush64(int ty, unsigned long long v) |
| 356 | 359 | { |
| 357 | − CValue cval; | |
| 358 | 360 | CType ctype; |
| 361 | + CValue cval; | |
| 362 | + memset(&cval, 0, sizeof(CValue)); | |
| 359 | 363 | ctype.t = ty; |
| 360 | 364 | ctype.ref = NULL; |
| 361 | 365 | cval.ull = v; |
| @@ -372,6 +376,7 @@ static inline void vpushll(long long v) · 10 unmodified lines | ||
| 372 | 376 | static inline void vpushsym(CType *type, Sym *sym) |
| 373 | 377 | { |
| 374 | 378 | CValue cval; |
| 379 | + memset(&cval, 0, sizeof(CValue)); | |
| 375 | 380 | |
| 376 | 381 | cval.ull = 0; |
| 377 | 382 | vsetc(type, VT_CONST | VT_SYM, &cval); |
| @@ -446,6 +451,7 @@ ST_FUNC void vpush_global_sym(CType *type, int v) · 68 unmodified lines | ||
| 446 | 451 | ST_FUNC void vset(CType *type, int r, int v) |
| 447 | 452 | { |
| 448 | 453 | CValue cval; |
| 454 | + memset(&cval, 0, sizeof(CValue)); | |
| 449 | 455 | |
| 450 | 456 | cval.i = v; |
| 451 | 457 | vsetc(type, r, &cval); |
| @@ -731,6 +737,7 @@ ST_FUNC int gv(int rc) · 279 unmodified lines | ||
| 731 | 737 | unsigned long offset; |
| 732 | 738 | #if defined(TCC_TARGET_ARM) && !defined(TCC_ARM_VFP) |
| 733 | 739 | CValue check; |
| 740 | + memset(&check, 0, sizeof(CValue)); | |
| 734 | 741 | #endif |
| 735 | 742 | |
| 736 | 743 | /* XXX: unify with initializers handling ? */ |
| @@ -936,6 +936,7 @@ static void tok_str_add2(TokenString *s, int t, CValue *cv) · 935 unmodified lines | ||
| 936 | 936 | ST_FUNC void tok_str_add_tok(TokenString *s) |
| 937 | 937 | { |
| 938 | 938 | CValue cval; |
| 939 | + memset(&cval, 0, sizeof(CValue)); | |
| 939 | 940 | |
| 940 | 941 | /* save line number info */ |
| 941 | 942 | if (file->line_num != s->last_line_num) { |
| @@ -999,8 +1000,9 @@ static inline void TOK_GET(int *t, const int **pp, CValue *cv) · 57 unmodified lines | ||
| 999 | 1000 | static int macro_is_equal(const int *a, const int *b) |
| 1000 | 1001 | { |
| 1001 | 1002 | char buf[STRING_MAX_SIZE + 1]; |
| 1002 | − CValue cv; | |
| 1003 | 1003 | int t; |
| 1004 | + CValue cv; | |
| 1005 | + memset(&cv, 0, sizeof(CValue)); | |
| 1004 | 1006 | while (*a && *b) { |
| 1005 | 1007 | TOK_GET(&t, &a, &cv); |
| 1006 | 1008 | pstrcpy(buf, sizeof buf, get_tok_str(t, &cv)); |
| @@ -1159,6 +1161,7 @@ static void tok_print(int *str) · 152 unmodified lines | ||
| 1159 | 1161 | { |
| 1160 | 1162 | int t; |
| 1161 | 1163 | CValue cval; |
| 1164 | + memset(&cval, 0, sizeof(CValue)); | |
| 1162 | 1165 | |
| 1163 | 1166 | printf("<"); |
| 1164 | 1167 | while (1) { |
| @@ -2525,9 +2528,10 @@ static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args) · 1360 unmodified lines | ||
| 2525 | 2528 | int last_tok, t, spc; |
| 2526 | 2529 | const int *st; |
| 2527 | 2530 | Sym *s; |
| 2528 | − CValue cval; | |
| 2529 | 2531 | TokenString str; |
| 2530 | 2532 | CString cstr; |
| 2533 | + CValue cval; | |
| 2534 | + memset(&cval, 0, sizeof(CValue)); | |
| 2531 | 2535 | |
| 2532 | 2536 | tok_str_new(&str); |
| 2533 | 2537 | last_tok = 0; |
| @@ -2629,9 +2633,10 @@ static int macro_subst_tok(TokenString *tok_str, · 95 unmodified lines | ||
| 2629 | 2633 | const int *p; |
| 2630 | 2634 | TokenString str; |
| 2631 | 2635 | char *cstrval; |
| 2632 | − CValue cval; | |
| 2633 | 2636 | CString cstr; |
| 2634 | 2637 | char buf[32]; |
| 2638 | + CValue cval; | |
| 2639 | + memset(&cval, 0, sizeof(CValue)); | |
| 2635 | 2640 | |
| 2636 | 2641 | /* if symbol is a macro, prepare substitution */ |
| 2637 | 2642 | /* special macros */ |
| @@ -2806,6 +2811,7 @@ static inline int *macro_twosharps(const int *macro_str) · 168 unmodified lines | ||
| 2806 | 2811 | /* we search the first '##' */ |
| 2807 | 2812 | for(ptr = macro_str;;) { |
| 2808 | 2813 | CValue cval; |
| 2814 | + memset(&cval, 0, sizeof(CValue)); | |
| 2809 | 2815 | TOK_GET(&t, &ptr, &cval); |
| 2810 | 2816 | if (t == TOK_TWOSHARPS) |
| 2811 | 2817 | break; |
| @@ -2836,6 +2842,7 @@ static inline int *macro_twosharps(const int *macro_str) · 24 unmodified lines | ||
| 2836 | 2842 | t = *++ptr; |
| 2837 | 2843 | if (t && t != TOK_TWOSHARPS) { |
| 2838 | 2844 | CValue cval; |
| 2845 | + memset(&cval, 0, sizeof(CValue)); | |
| 2839 | 2846 | TOK_GET(&t, &ptr, &cval); |
| 2840 | 2847 | /* We concatenate the two tokens */ |
| 2841 | 2848 | cstr_new(&cstr); |
| @@ -2877,9 +2884,10 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list, · 35 unmodified lines | ||
| 2877 | 2884 | int *macro_str1; |
| 2878 | 2885 | const int *ptr; |
| 2879 | 2886 | int t, ret, spc; |
| 2880 | − CValue cval; | |
| 2881 | 2887 | struct macro_level ml; |
| 2882 | 2888 | int force_blank; |
| 2889 | + CValue cval; | |
| 2890 | + memset(&cval, 0, sizeof(CValue)); | |
| 2883 | 2891 | |
| 2884 | 2892 | /* first scan for '##' operator handling */ |
| 2885 | 2893 | ptr = macro_str; |