Handle incomplete types gracefully.

This commit is contained in:
Bill Currie 2011-02-13 19:26:20 +09:00
parent ed3f98eab4
commit c336aaeb80
2 changed files with 10 additions and 1 deletions

View file

@ -113,7 +113,12 @@ new_def (const char *name, type_t *type, defspace_t *space,
def->type = type; def->type = type;
if (storage != st_extern) { if (storage != st_extern) {
def->offset = defspace_new_loc (space, type_size (type)); int size = type_size (type);
if (!size) {
error (0, "%s has incomplete type", name);
size = 1;
}
def->offset = defspace_new_loc (space, size);
} }
if (space) { if (space) {
def->space = space; def->space = space;

View file

@ -890,9 +890,13 @@ type_size (type_t *type)
case ev_invalid: case ev_invalid:
switch (type->ty) { switch (type->ty) {
case ty_enum: case ty_enum:
if (!type->t.symtab)
return 0;
return type_size (&type_integer); return type_size (&type_integer);
case ty_struct: case ty_struct:
case ty_union: case ty_union:
if (!type->t.symtab)
return 0;
return type->t.symtab->size; return type->t.symtab->size;
case ty_class: case ty_class:
{ {