From 6709933d78d82f066f3234eb5194a81e5cbf8165 Mon Sep 17 00:00:00 2001 From: yuanbin Date: Fri, 11 Jun 2010 20:28:31 +0800 Subject: [PATCH] tccgen: initial last member of union --- tccgen.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file 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(',');