| @@ -5713,7 +5713,8 @@ static void parse_init_elem(int expr_type) · 5712 unmodified lines |
| 5713 | 5713 | |
| 5714 | 5714 | /* t is the array or struct type. c is the array or struct |
| 5715 | 5715 | address. cur_field is the pointer to the current |
| 5716 | | − value, for arrays the 'c' member contains the current index. |
| 5716 | + value, for arrays the 'c' member contains the current start |
| 5717 | + index and the 'r' contains the end index (in case of range init). |
| 5717 | 5718 | 'size_only' is true if only size info is needed (only used |
| 5718 | 5719 | in arrays) */ |
| 5719 | 5720 | static void decl_designator(CType *type, Section *sec, unsigned long c, |
| @@ -5748,8 +5749,10 @@ static void decl_designator(CType *type, Section *sec, unsigned long c, · 28 unmodified lines |
| 5748 | 5749 | index_last = index; |
| 5749 | 5750 | } |
| 5750 | 5751 | skip(']'); |
| 5751 | | − if (!notfirst) |
| 5752 | | − (*cur_field)->c = index_last; |
| 5752 | + if (!notfirst) { |
| 5753 | + (*cur_field)->c = index; |
| 5754 | + (*cur_field)->r = index_last; |
| 5755 | + } |
| 5753 | 5756 | type = pointed_type(type); |
| 5754 | 5757 | elem_size = type_size(type, &align); |
| 5755 | 5758 | c += index * elem_size; |
| @@ -5812,17 +5815,25 @@ static void decl_designator(CType *type, Section *sec, unsigned long c, · 56 unmodified lines |
| 5812 | 5815 | uint8_t *src, *dst; |
| 5813 | 5816 | int i; |
| 5814 | 5817 | |
| 5815 | | − if (!sec) |
| 5816 | | − tcc_error("range init not supported yet for dynamic storage"); |
| 5817 | | − c_end = c + nb_elems * elem_size; |
| 5818 | | − if (c_end > sec->data_allocated) |
| 5819 | | − section_realloc(sec, c_end); |
| 5820 | | − src = sec->data + c; |
| 5821 | | − dst = src; |
| 5822 | | − for(i = 1; i < nb_elems; i++) { |
| 5823 | | − dst += elem_size; |
| 5824 | | − memcpy(dst, src, elem_size); |
| 5825 | | − } |
| 5818 | + if (!sec) { |
| 5819 | + vset(type, VT_LOCAL|VT_LVAL, c); |
| 5820 | + for (i = 1; i < nb_elems; i++) { |
| 5821 | + vset(type, VT_LOCAL|VT_LVAL, c + elem_size * i); |
| 5822 | + vswap(); |
| 5823 | + vstore(); |
| 5824 | + } |
| 5825 | + vpop(); |
| 5826 | + } else { |
| 5827 | + c_end = c + nb_elems * elem_size; |
| 5828 | + if (c_end > sec->data_allocated) |
| 5829 | + section_realloc(sec, c_end); |
| 5830 | + src = sec->data + c; |
| 5831 | + dst = src; |
| 5832 | + for(i = 1; i < nb_elems; i++) { |
| 5833 | + dst += elem_size; |
| 5834 | + memcpy(dst, src, elem_size); |
| 5835 | + } |
| 5836 | + } |
| 5826 | 5837 | } |
| 5827 | 5838 | } |
| 5828 | 5839 | |
| @@ -6014,7 +6025,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 185 unmodified lines |
| 6014 | 6025 | !(type->t & VT_ARRAY) && |
| 6015 | 6026 | /* Use i_c_parameter_t, to strip toplevel qualifiers. |
| 6016 | 6027 | The source type might have VT_CONSTANT set, which is |
| 6017 | | − of course assignable to a non-const elements. */ |
| 6028 | + of course assignable to non-const elements. */ |
| 6018 | 6029 | is_compatible_parameter_types(type, &vtop->type)) { |
| 6019 | 6030 | init_putv(type, sec, c); |
| 6020 | 6031 | } else if (type->t & VT_ARRAY) { |
| @@ -6088,6 +6099,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 67 unmodified lines |
| 6088 | 6099 | } |
| 6089 | 6100 | } else { |
| 6090 | 6101 | indexsym.c = 0; |
| 6102 | + indexsym.r = 0; |
| 6091 | 6103 | f = &indexsym; |
| 6092 | 6104 | |
| 6093 | 6105 | do_init_list: |
| @@ -6102,8 +6114,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 8 unmodified lines |
| 6102 | 6114 | (index - array_length) * size1); |
| 6103 | 6115 | } |
| 6104 | 6116 | if (type->t & VT_ARRAY) { |
| 6105 | | − index++; |
| 6106 | | − indexsym.c++; |
| 6117 | + index = indexsym.c = ++indexsym.r; |
| 6107 | 6118 | } else { |
| 6108 | 6119 | index = index + type_size(&f->type, &align1); |
| 6109 | 6120 | if (s->type.t == TOK_UNION) |