aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryuanbin <yuanbin0@gmail.com>2010-06-11 20:28:31 +0800
committeryuanbin <Administrator@yuan.(none)>2010-06-11 20:48:33 +0800
commit6709933d78d82f066f3234eb5194a81e5cbf8165 (patch)
tree0d126710744a23db3475337418f4617134db249b
parentdc265feb63c70a1a76fb566a6c05fe62246b65a0 (diff)
downloadtinycc-6709933d78d82f066f3234eb5194a81e5cbf8165.tar.gz
tinycc-6709933d78d82f066f3234eb5194a81e5cbf8165.tar.bz2
tccgen: initial last member of union
-rw-r--r--tccgen.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/tccgen.c b/tccgen.c
index 9940df5..914afe1 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -4824,7 +4824,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
/* patch type size if needed */
if (n < 0)
s->c = array_length;
- } else if ((type->t & VT_BTYPE) == VT_STRUCT &&
+ } else if ((type->t & VT_BTYPE) == VT_STRUCT && type->ref->c && /* Coo: ignore empty */
(sec || !first || tok == '{')) {
int par_count;
@@ -4860,7 +4860,14 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
no_oblock = 0;
}
s = type->ref;
- f = s->next;
+ f = s->next;
+ /* Coo: initial last member of union */
+ while (f->next && f->next->c==f->c) {
+ if ((f->type.t&VT_BITFIELD) && (f->next->type.t&VT_BITFIELD)
+ && ((f->type.t>>VT_STRUCT_SHIFT)&0x3f)==((f->next->type.t>>VT_STRUCT_SHIFT)&0x3f))
+ break;
+ f = f->next;
+ }
array_length = 0;
index = 0;
n = s->c;
@@ -4875,26 +4882,27 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
if (index > array_length)
array_length = index;
- /* gr: skip fields from same union - ugly. */
- while (f->next) {
- ///printf("index: %2d %08x -- %2d %08x\n", f->c, f->type.t, f->next->c, f->next->type.t);
- /* test for same offset */
- if (f->next->c != f->c)
- break;
- /* if yes, test for bitfield shift */
- if ((f->type.t & VT_BITFIELD) && (f->next->type.t & VT_BITFIELD)) {
- int bit_pos_1 = (f->type.t >> VT_STRUCT_SHIFT) & 0x3f;
- int bit_pos_2 = (f->next->type.t >> VT_STRUCT_SHIFT) & 0x3f;
- //printf("bitfield %d %d\n", bit_pos_1, bit_pos_2);
- if (bit_pos_1 != bit_pos_2)
+ f = f->next;
+ /* Coo: initial last member of union */
+ if (f)
+ /* gr: skip fields from same union - ugly. */
+ while (f->next) {
+ ///printf("index: %2d %08x -- %2d %08x\n", f->c, f->type.t, f->next->c, f->next->type.t);
+ /* test for same offset */
+ if (f->next->c != f->c)
break;
+ /* if yes, test for bitfield shift */
+ if ((f->type.t & VT_BITFIELD) && (f->next->type.t & VT_BITFIELD)) {
+ int bit_pos_1 = (f->type.t >> VT_STRUCT_SHIFT) & 0x3f;
+ int bit_pos_2 = (f->next->type.t >> VT_STRUCT_SHIFT) & 0x3f;
+ //printf("bitfield %d %d\n", bit_pos_1, bit_pos_2);
+ if (bit_pos_1 != bit_pos_2)
+ break;
+ }
+ f = f->next;
}
- f = f->next;
- }
-
- f = f->next;
- if (no_oblock && f == NULL)
- break;
+ else if (no_oblock)
+ break;
if (tok == '}')
break;
skip(',');