Fix type parsing
the check on incomplete struct/union/enum types was too early, disallowing mixed specifiers and qualifiers. Simply rely on the size (->c) field for that. See testcases.
This commit is contained in:
15
tccgen.c
15
tccgen.c
@ -2200,7 +2200,7 @@ ST_FUNC int type_size(CType *type, int *a)
|
||||
*a = 8;
|
||||
#endif
|
||||
return 8;
|
||||
} else if (bt == VT_INT || bt == VT_ENUM || bt == VT_FLOAT) {
|
||||
} else if (bt == VT_INT || bt == VT_FLOAT) {
|
||||
*a = 4;
|
||||
return 4;
|
||||
} else if (bt == VT_SHORT) {
|
||||
@ -2209,6 +2209,10 @@ ST_FUNC int type_size(CType *type, int *a)
|
||||
} else if (bt == VT_QLONG || bt == VT_QFLOAT) {
|
||||
*a = 8;
|
||||
return 16;
|
||||
} else if (bt == VT_ENUM) {
|
||||
*a = 4;
|
||||
/* Enums might be incomplete, so don't just return '4' here. */
|
||||
return type->ref->c;
|
||||
} else {
|
||||
/* char, void, function, _Bool */
|
||||
*a = 1;
|
||||
@ -2902,7 +2906,7 @@ static void parse_attribute(AttributeDef *ad)
|
||||
}
|
||||
|
||||
/* enum/struct/union declaration. u is either VT_ENUM or VT_STRUCT */
|
||||
static void struct_decl(CType *type, int u, int tdef)
|
||||
static void struct_decl(CType *type, int u)
|
||||
{
|
||||
int a, v, size, align, maxalign, c, offset, flexible;
|
||||
int bit_size, bit_pos, bsize, bt, lbit_pos, prevbt;
|
||||
@ -2923,8 +2927,7 @@ static void struct_decl(CType *type, int u, int tdef)
|
||||
if (s->type.t != a)
|
||||
tcc_error("invalid type");
|
||||
goto do_decl;
|
||||
} else if (tok >= TOK_IDENT && !tdef)
|
||||
tcc_error("unknown struct/union/enum");
|
||||
}
|
||||
} else {
|
||||
v = anon_sym++;
|
||||
}
|
||||
@ -3229,14 +3232,14 @@ static int parse_btype(CType *type, AttributeDef *ad)
|
||||
}
|
||||
break;
|
||||
case TOK_ENUM:
|
||||
struct_decl(&type1, VT_ENUM, t & (VT_TYPEDEF | VT_EXTERN));
|
||||
struct_decl(&type1, VT_ENUM);
|
||||
basic_type2:
|
||||
u = type1.t;
|
||||
type->ref = type1.ref;
|
||||
goto basic_type1;
|
||||
case TOK_STRUCT:
|
||||
case TOK_UNION:
|
||||
struct_decl(&type1, VT_STRUCT, t & (VT_TYPEDEF | VT_EXTERN));
|
||||
struct_decl(&type1, VT_STRUCT);
|
||||
goto basic_type2;
|
||||
|
||||
/* type modifiers */
|
||||
|
||||
Reference in New Issue
Block a user