History

revert complicated & broken flexible array member handling

Joe Soroka committed 15 years ago

Commit 06a7c411 parent 4062d782 files · +5 −21Browse files

Unified · Split

2 files
  1. tcc.h +1 −3
  2. tccgen.c +4 −18
tcc.h+1−3
@@ -282,8 +282,7 @@ typedef struct AttributeDef { · 281 unmodified lines
282 func_args : 5,282 func_args : 5,
283 mode : 4,283 mode : 4,
284 weak : 1,284 weak : 1,
285 resize : 1,285 fill : 11;
286 fill : 10;
287 struct Section *section;286 struct Section *section;
288 int alias_target; /* token */287 int alias_target; /* token */
289} AttributeDef;288} AttributeDef;
@@ -295,7 +294,6 @@ typedef struct AttributeDef { · 5 unmodified lines
295#define FUNC_ARGS(r) (((AttributeDef*)&(r))->func_args)294#define FUNC_ARGS(r) (((AttributeDef*)&(r))->func_args)
296#define FUNC_ALIGN(r) (((AttributeDef*)&(r))->aligned)295#define FUNC_ALIGN(r) (((AttributeDef*)&(r))->aligned)
297#define FUNC_PACKED(r) (((AttributeDef*)&(r))->packed)296#define FUNC_PACKED(r) (((AttributeDef*)&(r))->packed)
298#define ARRAY_RESIZE(r) (((AttributeDef*)&(r))->resize)
299#define ATTR_MODE(r) (((AttributeDef*)&(r))->mode)297#define ATTR_MODE(r) (((AttributeDef*)&(r))->mode)
300#define INT_ATTR(ad) (*(int*)(ad))298#define INT_ATTR(ad) (*(int*)(ad))
301 299
tccgen.c+4−18
@@ -1958,7 +1958,7 @@ ST_FUNC int type_size(CType *type, int *a) · 1957 unmodified lines
1958 if (bt == VT_STRUCT) {1958 if (bt == VT_STRUCT) {
1959 /* struct/union */1959 /* struct/union */
1960 s = type->ref;1960 s = type->ref;
1961 *a = s->r & 0xffffff;1961 *a = s->r;
1962 return s->c;1962 return s->c;
1963 } else if (bt == VT_PTR) {1963 } else if (bt == VT_PTR) {
1964 if (type->t & VT_ARRAY) {1964 if (type->t & VT_ARRAY) {
@@ -2610,7 +2610,7 @@ static void parse_attribute(AttributeDef *ad) · 645 unmodified lines
2610static void struct_decl(CType *type, int u)2610static void struct_decl(CType *type, int u)
2611{2611{
2612 int a, v, size, align, maxalign, c, offset;2612 int a, v, size, align, maxalign, c, offset;
2613 int bit_size, bit_pos, bsize, bt, lbit_pos, prevbt, resize;2613 int bit_size, bit_pos, bsize, bt, lbit_pos, prevbt;
2614 Sym *s, *ss, *ass, **ps;2614 Sym *s, *ss, *ass, **ps;
2615 AttributeDef ad;2615 AttributeDef ad;
2616 CType type1, btype;2616 CType type1, btype;
@@ -2671,7 +2671,6 @@ static void struct_decl(CType *type, int u) · 54 unmodified lines
2671 }2671 }
2672 skip('}');2672 skip('}');
2673 } else {2673 } else {
2674 resize = 0;
2675 maxalign = 1;2674 maxalign = 1;
2676 ps = &s->next;2675 ps = &s->next;
2677 prevbt = VT_INT;2676 prevbt = VT_INT;
@@ -2762,8 +2761,6 @@ static void struct_decl(CType *type, int u) · 84 unmodified lines
2762 offset = c;2761 offset = c;
2763 if (size > 0)2762 if (size > 0)
2764 c += size;2763 c += size;
2765 if (size < 0)
2766 resize = 1;
2767 } else {2764 } else {
2768 offset = 0;2765 offset = 0;
2769 if (size > c)2766 if (size > c)
@@ -2804,7 +2801,7 @@ static void struct_decl(CType *type, int u) · 34 unmodified lines
2804 skip('}');2801 skip('}');
2805 /* store size and alignment */2802 /* store size and alignment */
2806 s->c = (c + maxalign - 1) & -maxalign; 2803 s->c = (c + maxalign - 1) & -maxalign;
2807 s->r = maxalign | (resize ? (1 << 31) : 0);2804 s->r = maxalign;
2808 }2805 }
2809 }2806 }
2810}2807}
@@ -3147,8 +3144,6 @@ static void post_type(CType *type, AttributeDef *ad) · 336 unmodified lines
3147 /* we push a anonymous symbol which will contain the array3144 /* we push a anonymous symbol which will contain the array
3148 element type */3145 element type */
3149 s = sym_push(SYM_FIELD, type, 0, n);3146 s = sym_push(SYM_FIELD, type, 0, n);
3150 if (n < 0)
3151 ARRAY_RESIZE(s->r) = 1;
3152 type->t = t1 | VT_ARRAY | VT_PTR;3147 type->t = t1 | VT_ARRAY | VT_PTR;
3153 type->ref = s;3148 type->ref = s;
3154 }3149 }
@@ -4884,8 +4879,6 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 1729 unmodified lines
4884 }4879 }
4885 } else {4880 } else {
4886 index = 0;4881 index = 0;
4887 if (ARRAY_RESIZE(s->r))
4888 n = -1;
4889 while (tok != '}') {4882 while (tok != '}') {
4890 decl_designator(type, sec, c, &index, NULL, size_only);4883 decl_designator(type, sec, c, &index, NULL, size_only);
4891 if (n >= 0 && index >= n)4884 if (n >= 0 && index >= n)
@@ -4959,8 +4952,6 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 67 unmodified lines
4959 array_length = 0;4952 array_length = 0;
4960 index = 0;4953 index = 0;
4961 n = s->c;4954 n = s->c;
4962 if (s->r & (1<<31))
4963 n = -1;
4964 while (tok != '}') {4955 while (tok != '}') {
4965 decl_designator(type, sec, c, NULL, &f, size_only);4956 decl_designator(type, sec, c, NULL, &f, size_only);
4966 index = f->c;4957 index = f->c;
@@ -4997,7 +4988,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 30 unmodified lines
4997 skip(',');4988 skip(',');
4998 }4989 }
4999 /* put zeros at the end */4990 /* put zeros at the end */
5000 if (!size_only && n >= 0 && array_length < n) {4991 if (!size_only && array_length < n) {
5001 init_putz(type, sec, c + array_length, 4992 init_putz(type, sec, c + array_length,
5002 n - array_length);4993 n - array_length);
5003 }4994 }
@@ -5007,8 +4998,6 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 3 unmodified lines
5007 skip(')');4998 skip(')');
5008 par_count--;4999 par_count--;
5009 }5000 }
5010 if (n < 0)
5011 s->c = array_length;
5012 } else if (tok == '{') {5001 } else if (tok == '{') {
5013 next();5002 next();
5014 decl_initializer(type, sec, c, first, size_only);5003 decl_initializer(type, sec, c, first, size_only);
@@ -5056,9 +5045,6 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 41 unmodified lines
5056 TokenString init_str;5045 TokenString init_str;
5057 Section *sec;5046 Section *sec;
5058 5047
5059 /* resize the struct */
5060 if ((type->t & VT_BTYPE) == VT_STRUCT && (type->ref->r & (1<<31)) != 0)
5061 type->ref->c = -1;
5062 size = type_size(type, &align);5048 size = type_size(type, &align);
5063 /* If unknown size, we must evaluate it before5049 /* If unknown size, we must evaluate it before
5064 evaluating initializers because5050 evaluating initializers because

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