History

bitfields init : tiny solution

This replaces commit 5c6356ff8e8ad57c8d5ad8220d665dfba02290cf, except the tests.

grischka committed 6 years ago

Commit 8cb3e531 parent 5c6356f1 file · +9 −27Browse files

Unified · Split

tccgen.c+9−27
@@ -7423,10 +7423,17 @@ static int decl_designator(CType *type, Section *sec, unsigned long c, · 7422 unmodified lines
74237423 c += f->c;
74247424 }
74257425 }
7426+
74267427 /* must put zero in holes (note that doing it that way
74277428 ensures that it even works with designators) */
7428− if (!(flags & DIF_SIZE_ONLY) && c - corig > al)
7429− init_putz(sec, corig + al, c - corig - al);
7429+ if (!(flags & DIF_SIZE_ONLY)) {
7430+ int zlen = c - (corig + al);
7431+ if (type->t & VT_BITFIELD) /* must include current field too */
7432+ zlen += type_size(type, &align);
7433+ if (zlen > 0)
7434+ init_putz(sec, corig + al, zlen);
7435+ }
7436+
74307437 decl_initializer(type, sec, c, flags & ~DIF_FIRST);
74317438
74327439 /* XXX: make it more general */
@@ -7651,23 +7658,6 @@ static void init_putv(CType *type, Section *sec, unsigned long c) · 218 unmodified lines
76517658 }
76527659 }
76537660
7654−/* Check for bitfield in struct/union recursive */
7655−static int check_bf(Sym *f)
7656−{
7657− while (f->next) {
7658− f = f->next;
7659− if ((f->type.t & VT_BITFIELD) ||
7660− ((f->type.t & VT_BTYPE) == VT_STRUCT && check_bf(f->type.ref)))
7661− return 1;
7662− if (f->type.t & VT_ARRAY) {
7663− Sym *r = f->type.ref;
7664− if (((r->type.t & VT_BTYPE) == VT_STRUCT && check_bf(r->type.ref)))
7665− return 1;
7666− }
7667− }
7668− return 0;
7669−}
7670−
76717661 /* 't' contains the type and storage info. 'c' is the offset of the
76727662 object in section 'sec'. If 'sec' is NULL, it means stack based
76737663 allocation. 'flags & DIF_FIRST' is true if array '{' must be read (multi
@@ -7705,11 +7695,6 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 31 unmodified lines
77057695 t1 = pointed_type(type);
77067696 size1 = type_size(t1, &align1);
77077697
7708− if (!(flags & DIF_SIZE_ONLY) &&
7709− (s->type.t & VT_BTYPE) == VT_STRUCT && check_bf (s->type.ref))
7710− /* If there is a bitfield in array clear it */
7711− init_putz(sec, c, size1 * n);
7712−
77137698 no_oblock = 1;
77147699 if (((flags & DIF_FIRST) && tok != TOK_LSTR && tok != TOK_STR) ||
77157700 tok == '{') {
@@ -7839,9 +7824,6 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 123 unmodified lines
78397824 s = type->ref;
78407825 f = s->next;
78417826 n = s->c;
7842− if (!(flags & DIF_SIZE_ONLY) && check_bf (s))
7843− /* If there is a bitfield in struct/union clear it */
7844− init_putz(sec, c, n);
78457827 goto do_init_list;
78467828 } else if (tok == '{') {
78477829 if (flags & DIF_HAVE_ELEM)

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