History

After several days searching why my code refactoring to remove globals was crashing, I found the problem it was because CValue stack variables have rubish as it inital values and assigning to a member that is smaller than the big union item and trying to recover it later as a different member gives bak garbage.

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

mingodad committed 12 years ago

Commit 4bc83ac1 parent aa561d72 files · +20 −5Browse files

Unified · Split

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

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