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
329329 void vpush(CType *type)
330330 {
331331 CValue cval;
332+ memset(&cval, 0, sizeof(CValue));
332333 vsetc(type, VT_CONST, &cval);
333334 }
334335
@@ -336,6 +337,7 @@ void vpush(CType *type) · 1 unmodified line
336337 ST_FUNC void vpushi(int v)
337338 {
338339 CValue cval;
340+ memset(&cval, 0, sizeof(CValue));
339341 cval.i = v;
340342 vsetc(&int_type, VT_CONST, &cval);
341343 }
@@ -344,6 +346,7 @@ ST_FUNC void vpushi(int v) · 2 unmodified lines
344346 static void vpushs(long long v)
345347 {
346348 CValue cval;
349+ memset(&cval, 0, sizeof(CValue));
347350 if (PTR_SIZE == 4)
348351 cval.i = (int)v;
349352 else
@@ -354,8 +357,9 @@ static void vpushs(long long v) · 4 unmodified lines
354357 /* push arbitrary 64bit constant */
355358 void vpush64(int ty, unsigned long long v)
356359 {
357− CValue cval;
358360 CType ctype;
361+ CValue cval;
362+ memset(&cval, 0, sizeof(CValue));
359363 ctype.t = ty;
360364 ctype.ref = NULL;
361365 cval.ull = v;
@@ -372,6 +376,7 @@ static inline void vpushll(long long v) · 10 unmodified lines
372376 static inline void vpushsym(CType *type, Sym *sym)
373377 {
374378 CValue cval;
379+ memset(&cval, 0, sizeof(CValue));
375380
376381 cval.ull = 0;
377382 vsetc(type, VT_CONST | VT_SYM, &cval);
@@ -446,6 +451,7 @@ ST_FUNC void vpush_global_sym(CType *type, int v) · 68 unmodified lines
446451 ST_FUNC void vset(CType *type, int r, int v)
447452 {
448453 CValue cval;
454+ memset(&cval, 0, sizeof(CValue));
449455
450456 cval.i = v;
451457 vsetc(type, r, &cval);
@@ -731,6 +737,7 @@ ST_FUNC int gv(int rc) · 279 unmodified lines
731737 unsigned long offset;
732738 #if defined(TCC_TARGET_ARM) && !defined(TCC_ARM_VFP)
733739 CValue check;
740+ memset(&check, 0, sizeof(CValue));
734741 #endif
735742
736743 /* 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
936936 ST_FUNC void tok_str_add_tok(TokenString *s)
937937 {
938938 CValue cval;
939+ memset(&cval, 0, sizeof(CValue));
939940
940941 /* save line number info */
941942 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
9991000 static int macro_is_equal(const int *a, const int *b)
10001001 {
10011002 char buf[STRING_MAX_SIZE + 1];
1002− CValue cv;
10031003 int t;
1004+ CValue cv;
1005+ memset(&cv, 0, sizeof(CValue));
10041006 while (*a && *b) {
10051007 TOK_GET(&t, &a, &cv);
10061008 pstrcpy(buf, sizeof buf, get_tok_str(t, &cv));
@@ -1159,6 +1161,7 @@ static void tok_print(int *str) · 152 unmodified lines
11591161 {
11601162 int t;
11611163 CValue cval;
1164+ memset(&cval, 0, sizeof(CValue));
11621165
11631166 printf("<");
11641167 while (1) {
@@ -2525,9 +2528,10 @@ static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args) · 1360 unmodified lines
25252528 int last_tok, t, spc;
25262529 const int *st;
25272530 Sym *s;
2528− CValue cval;
25292531 TokenString str;
25302532 CString cstr;
2533+ CValue cval;
2534+ memset(&cval, 0, sizeof(CValue));
25312535
25322536 tok_str_new(&str);
25332537 last_tok = 0;
@@ -2629,9 +2633,10 @@ static int macro_subst_tok(TokenString *tok_str, · 95 unmodified lines
26292633 const int *p;
26302634 TokenString str;
26312635 char *cstrval;
2632− CValue cval;
26332636 CString cstr;
26342637 char buf[32];
2638+ CValue cval;
2639+ memset(&cval, 0, sizeof(CValue));
26352640
26362641 /* if symbol is a macro, prepare substitution */
26372642 /* special macros */
@@ -2806,6 +2811,7 @@ static inline int *macro_twosharps(const int *macro_str) · 168 unmodified lines
28062811 /* we search the first '##' */
28072812 for(ptr = macro_str;;) {
28082813 CValue cval;
2814+ memset(&cval, 0, sizeof(CValue));
28092815 TOK_GET(&t, &ptr, &cval);
28102816 if (t == TOK_TWOSHARPS)
28112817 break;
@@ -2836,6 +2842,7 @@ static inline int *macro_twosharps(const int *macro_str) · 24 unmodified lines
28362842 t = *++ptr;
28372843 if (t && t != TOK_TWOSHARPS) {
28382844 CValue cval;
2845+ memset(&cval, 0, sizeof(CValue));
28392846 TOK_GET(&t, &ptr, &cval);
28402847 /* We concatenate the two tokens */
28412848 cstr_new(&cstr);
@@ -2877,9 +2884,10 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list, · 35 unmodified lines
28772884 int *macro_str1;
28782885 const int *ptr;
28792886 int t, ret, spc;
2880− CValue cval;
28812887 struct macro_level ml;
28822888 int force_blank;
2889+ CValue cval;
2890+ memset(&cval, 0, sizeof(CValue));
28832891
28842892 /* first scan for '##' operator handling */
28852893 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