| @@ -1944,7 +1944,7 @@ ST_FUNC int type_size(CType *type, int *a) · 1943 unmodified lines |
| 1944 | if (bt == VT_STRUCT) { | 1944 | if (bt == VT_STRUCT) { |
| 1945 | /* struct/union */ | 1945 | /* struct/union */ |
| 1946 | s = type->ref; | 1946 | s = type->ref; |
| 1947 | *a = s->r; | 1947 | *a = s->r & 0xffffff; |
| 1948 | return s->c; | 1948 | return s->c; |
| 1949 | } else if (bt == VT_PTR) { | 1949 | } else if (bt == VT_PTR) { |
| 1950 | if (type->t & VT_ARRAY) { | 1950 | if (type->t & VT_ARRAY) { |
| @@ -2586,7 +2586,7 @@ static void parse_attribute(AttributeDef *ad) · 635 unmodified lines |
| 2586 | static void struct_decl(CType *type, int u) | 2586 | static void struct_decl(CType *type, int u) |
| 2587 | { | 2587 | { |
| 2588 | int a, v, size, align, maxalign, c, offset; | 2588 | int a, v, size, align, maxalign, c, offset; |
| 2589 | int bit_size, bit_pos, bsize, bt, lbit_pos, prevbt; | 2589 | int bit_size, bit_pos, bsize, bt, lbit_pos, prevbt, resize; |
| 2590 | Sym *s, *ss, *ass, **ps; | 2590 | Sym *s, *ss, *ass, **ps; |
| 2591 | AttributeDef ad; | 2591 | AttributeDef ad; |
| 2592 | CType type1, btype; | 2592 | CType type1, btype; |
| @@ -2647,6 +2647,7 @@ static void struct_decl(CType *type, int u) · 54 unmodified lines |
| 2647 | } | 2647 | } |
| 2648 | skip('}'); | 2648 | skip('}'); |
| 2649 | } else { | 2649 | } else { |
| | 2650 | resize = 0; |
| 2650 | maxalign = 1; | 2651 | maxalign = 1; |
| 2651 | ps = &s->next; | 2652 | ps = &s->next; |
| 2652 | prevbt = VT_INT; | 2653 | prevbt = VT_INT; |
| @@ -2737,6 +2738,8 @@ static void struct_decl(CType *type, int u) · 84 unmodified lines |
| 2737 | offset = c; | 2738 | offset = c; |
| 2738 | if (size > 0) | 2739 | if (size > 0) |
| 2739 | c += size; | 2740 | c += size; |
| | 2741 | if (size < 0) |
| | 2742 | resize = 1; |
| 2740 | } else { | 2743 | } else { |
| 2741 | offset = 0; | 2744 | offset = 0; |
| 2742 | if (size > c) | 2745 | if (size > c) |
| @@ -2777,7 +2780,7 @@ static void struct_decl(CType *type, int u) · 34 unmodified lines |
| 2777 | skip('}'); | 2780 | skip('}'); |
| 2778 | /* store size and alignment */ | 2781 | /* store size and alignment */ |
| 2779 | s->c = (c + maxalign - 1) & -maxalign; | 2782 | s->c = (c + maxalign - 1) & -maxalign; |
| 2780 | s->r = maxalign; | 2783 | s->r = maxalign | (resize ? (1 << 31) : 0); |
| 2781 | } | 2784 | } |
| 2782 | } | 2785 | } |
| 2783 | } | 2786 | } |
| @@ -3113,6 +3116,8 @@ static void post_type(CType *type, AttributeDef *ad) · 329 unmodified lines |
| 3113 | /* we push a anonymous symbol which will contain the array | 3116 | /* we push a anonymous symbol which will contain the array |
| 3114 | element type */ | 3117 | element type */ |
| 3115 | s = sym_push(SYM_FIELD, type, 0, n); | 3118 | s = sym_push(SYM_FIELD, type, 0, n); |
| | 3119 | if (n < 0) |
| | 3120 | ARRAY_RESIZE(s->r) = 1; |
| 3116 | type->t = t1 | VT_ARRAY | VT_PTR; | 3121 | type->t = t1 | VT_ARRAY | VT_PTR; |
| 3117 | type->ref = s; | 3122 | type->ref = s; |
| 3118 | } | 3123 | } |
| @@ -4845,6 +4850,8 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 1726 unmodified lines |
| 4845 | } | 4850 | } |
| 4846 | } else { | 4851 | } else { |
| 4847 | index = 0; | 4852 | index = 0; |
| | 4853 | if (ARRAY_RESIZE(s->r)) |
| | 4854 | n = -1; |
| 4848 | while (tok != '}') { | 4855 | while (tok != '}') { |
| 4849 | decl_designator(type, sec, c, &index, NULL, size_only); | 4856 | decl_designator(type, sec, c, &index, NULL, size_only); |
| 4850 | if (n >= 0 && index >= n) | 4857 | if (n >= 0 && index >= n) |
| @@ -4918,6 +4925,8 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 67 unmodified lines |
| 4918 | array_length = 0; | 4925 | array_length = 0; |
| 4919 | index = 0; | 4926 | index = 0; |
| 4920 | n = s->c; | 4927 | n = s->c; |
| | 4928 | if (s->r & (1<<31)) |
| | 4929 | n = -1; |
| 4921 | while (tok != '}') { | 4930 | while (tok != '}') { |
| 4922 | decl_designator(type, sec, c, NULL, &f, size_only); | 4931 | decl_designator(type, sec, c, NULL, &f, size_only); |
| 4923 | index = f->c; | 4932 | index = f->c; |
| @@ -4954,7 +4963,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 30 unmodified lines |
| 4954 | skip(','); | 4963 | skip(','); |
| 4955 | } | 4964 | } |
| 4956 | /* put zeros at the end */ | 4965 | /* put zeros at the end */ |
| 4957 | if (!size_only && array_length < n) { | 4966 | if (!size_only && n >= 0 && array_length < n) { |
| 4958 | init_putz(type, sec, c + array_length, | 4967 | init_putz(type, sec, c + array_length, |
| 4959 | n - array_length); | 4968 | n - array_length); |
| 4960 | } | 4969 | } |
| @@ -4964,6 +4973,8 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 3 unmodified lines |
| 4964 | skip(')'); | 4973 | skip(')'); |
| 4965 | par_count--; | 4974 | par_count--; |
| 4966 | } | 4975 | } |
| | 4976 | if (n < 0) |
| | 4977 | s->c = array_length; |
| 4967 | } else if (tok == '{') { | 4978 | } else if (tok == '{') { |
| 4968 | next(); | 4979 | next(); |
| 4969 | decl_initializer(type, sec, c, first, size_only); | 4980 | decl_initializer(type, sec, c, first, size_only); |
| @@ -5011,6 +5022,9 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 41 unmodified lines |
| 5011 | TokenString init_str; | 5022 | TokenString init_str; |
| 5012 | Section *sec; | 5023 | Section *sec; |
| 5013 | | 5024 | |
| | 5025 | /* resize the struct */ |
| | 5026 | if ((type->t & VT_BTYPE) == VT_STRUCT && (type->ref->r & (1<<31)) != 0) |
| | 5027 | type->ref->c = -1; |
| 5014 | size = type_size(type, &align); | 5028 | size = type_size(type, &align); |
| 5015 | /* If unknown size, we must evaluate it before | 5029 | /* If unknown size, we must evaluate it before |
| 5016 | evaluating initializers because | 5030 | evaluating initializers because |