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;
@ -4861,6 +4861,13 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
} }
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,6 +4882,9 @@ 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;
f = f->next;
/* Coo: initial last member of union */
if (f)
/* gr: skip fields from same union - ugly. */ /* gr: skip fields from same union - ugly. */
while (f->next) { while (f->next) {
///printf("index: %2d %08x -- %2d %08x\n", f->c, f->type.t, f->next->c, f->next->type.t); ///printf("index: %2d %08x -- %2d %08x\n", f->c, f->type.t, f->next->c, f->next->type.t);
@ -4891,9 +4901,7 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
} }
f = f->next; f = f->next;
} }
else if (no_oblock)
f = f->next;
if (no_oblock && f == NULL)
break; break;
if (tok == '}') if (tok == '}')
break; break;