tccgen: initial last member of union

This commit is contained in:
yuanbin 2010-06-11 20:28:31 +08:00 committed by yuanbin
parent dc265feb63
commit 6709933d78

View File

@ -4824,7 +4824,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
/* patch type size if needed */ /* patch type size if needed */
if (n < 0) if (n < 0)
s->c = array_length; 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 == '{')) { (sec || !first || tok == '{')) {
int par_count; int par_count;
@ -4860,7 +4860,14 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
no_oblock = 0; no_oblock = 0;
} }
s = type->ref; 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; array_length = 0;
index = 0; index = 0;
n = s->c; n = s->c;
@ -4875,26 +4882,27 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
if (index > array_length) if (index > array_length)
array_length = index; array_length = index;
/* gr: skip fields from same union - ugly. */ f = f->next;
while (f->next) { /* Coo: initial last member of union */
///printf("index: %2d %08x -- %2d %08x\n", f->c, f->type.t, f->next->c, f->next->type.t); if (f)
/* test for same offset */ /* gr: skip fields from same union - ugly. */
if (f->next->c != f->c) while (f->next) {
break; ///printf("index: %2d %08x -- %2d %08x\n", f->c, f->type.t, f->next->c, f->next->type.t);
/* if yes, test for bitfield shift */ /* test for same offset */
if ((f->type.t & VT_BITFIELD) && (f->next->type.t & VT_BITFIELD)) { if (f->next->c != f->c)
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; 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; else if (no_oblock)
} break;
f = f->next;
if (no_oblock && f == NULL)
break;
if (tok == '}') if (tok == '}')
break; break;
skip(','); skip(',');