Revert of the commit: fix for the array in struct initialization w/o '{', case 2

A right solution for this problem will follow.
This commit is contained in:
seyko 2015-03-23 07:40:41 +03:00
parent aba2d648f4
commit 367bb6f4b7

View file

@ -80,7 +80,7 @@ static int is_compatible_types(CType *type1, CType *type2);
static int parse_btype(CType *type, AttributeDef *ad); static int parse_btype(CType *type, AttributeDef *ad);
static void type_decl(CType *type, AttributeDef *ad, int *v, int td); static void type_decl(CType *type, AttributeDef *ad, int *v, int td);
static void parse_expr_type(CType *type); static void parse_expr_type(CType *type);
static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only, int *par_count_p); static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only);
static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg, int is_expr); static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg, int is_expr);
static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, char *asm_label, int scope); static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, char *asm_label, int scope);
static int decl0(int l, int is_for_loop_init); static int decl0(int l, int is_for_loop_init);
@ -5155,7 +5155,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
in arrays) */ in arrays) */
static void decl_designator(CType *type, Section *sec, unsigned long c, static void decl_designator(CType *type, Section *sec, unsigned long c,
int *cur_index, Sym **cur_field, int *cur_index, Sym **cur_field,
int size_only, int *par_count_p) int size_only)
{ {
Sym *s, *f; Sym *s, *f;
int notfirst, index, index_last, align, l, nb_elems, elem_size; int notfirst, index, index_last, align, l, nb_elems, elem_size;
@ -5247,7 +5247,7 @@ static void decl_designator(CType *type, Section *sec, unsigned long c,
c += f->c; c += f->c;
} }
} }
decl_initializer(type, sec, c, 0, size_only, par_count_p); decl_initializer(type, sec, c, 0, size_only);
/* XXX: make it more general */ /* XXX: make it more general */
if (!size_only && nb_elems > 1) { if (!size_only && nb_elems > 1) {
@ -5416,7 +5416,7 @@ static void init_putz(CType *t, Section *sec, unsigned long c, int size)
dimension implicit array init handling). 'size_only' is true if dimension implicit array init handling). 'size_only' is true if
size only evaluation is wanted (only for arrays). */ size only evaluation is wanted (only for arrays). */
static void decl_initializer(CType *type, Section *sec, unsigned long c, static void decl_initializer(CType *type, Section *sec, unsigned long c,
int first, int size_only, int *par_count_p) int first, int size_only)
{ {
int index, array_length, n, no_oblock, nb, parlevel, parlevel1, i; int index, array_length, n, no_oblock, nb, parlevel, parlevel1, i;
int size1, align1, expr_type; int size1, align1, expr_type;
@ -5512,7 +5512,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
} else { } else {
index = 0; index = 0;
while (tok != '}') { while (tok != '}') {
decl_designator(type, sec, c, &index, NULL, size_only, par_count_p); decl_designator(type, sec, c, &index, NULL, size_only);
if (n >= 0 && index >= n) if (n >= 0 && index >= n)
tcc_error("index too large"); tcc_error("index too large");
/* must put zero in holes (note that doing it that way /* must put zero in holes (note that doing it that way
@ -5529,10 +5529,6 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
same time) */ same time) */
if (index >= n && no_oblock) if (index >= n && no_oblock)
break; break;
if (*par_count_p != 0 && tok == ')') {
skip(')');
*par_count_p -= 1;
}
if (tok == '}') if (tok == '}')
break; break;
skip(','); skip(',');
@ -5589,7 +5585,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
index = 0; index = 0;
n = s->c; n = s->c;
while (tok != '}') { while (tok != '}') {
decl_designator(type, sec, c, NULL, &f, size_only, &par_count); decl_designator(type, sec, c, NULL, &f, size_only);
index = f->c; index = f->c;
if (!size_only && array_length < index) { if (!size_only && array_length < index) {
init_putz(type, sec, c + array_length, init_putz(type, sec, c + array_length,
@ -5655,9 +5651,8 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
par_count--; par_count--;
} }
} else if (tok == '{') { } else if (tok == '{') {
int par_count = 0;
next(); next();
decl_initializer(type, sec, c, first, size_only, &par_count); decl_initializer(type, sec, c, first, size_only);
skip('}'); skip('}');
} else if (size_only) { } else if (size_only) {
/* just skip expression */ /* just skip expression */
@ -5729,7 +5724,6 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
initializers handling */ initializers handling */
tok_str_new(&init_str); tok_str_new(&init_str);
if (size < 0 || (flexible_array && has_init)) { if (size < 0 || (flexible_array && has_init)) {
int par_count = 0;
if (!has_init) if (!has_init)
tcc_error("unknown type size"); tcc_error("unknown type size");
/* get all init string */ /* get all init string */
@ -5765,7 +5759,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
macro_ptr = init_str.str; macro_ptr = init_str.str;
next(); next();
decl_initializer(type, NULL, 0, 1, 1, &par_count); decl_initializer(type, NULL, 0, 1, 1);
/* prepare second initializer parsing */ /* prepare second initializer parsing */
macro_ptr = init_str.str; macro_ptr = init_str.str;
next(); next();
@ -5920,8 +5914,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
#endif #endif
} }
if (has_init || (type->t & VT_VLA)) { if (has_init || (type->t & VT_VLA)) {
int par_count = 0; decl_initializer(type, sec, addr, 1, 0);
decl_initializer(type, sec, addr, 1, 0, &par_count);
/* restore parse state if needed */ /* restore parse state if needed */
if (init_str.str) { if (init_str.str) {
tok_str_free(init_str.str); tok_str_free(init_str.str);