aboutsummaryrefslogtreecommitdiff
path: root/tccgen.c
diff options
context:
space:
mode:
authorMichael Matz <matz@suse.de>2016-03-24 15:44:01 +0100
committerMichael Matz <matz@suse.de>2016-03-24 15:44:01 +0100
commitf85db99ff0b48b5837fa985dcf9c58190b35f96a (patch)
treefdd6e4674aaae43b8fce39a08e581ab4c27c43b4 /tccgen.c
parentaa1ed616eb01efe353e7c5e829fffbed01b428bd (diff)
downloadtinycc-f85db99ff0b48b5837fa985dcf9c58190b35f96a.tar.gz
tinycc-f85db99ff0b48b5837fa985dcf9c58190b35f96a.tar.bz2
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.
Diffstat (limited to 'tccgen.c')
-rw-r--r--tccgen.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/tccgen.c b/tccgen.c
index 0524b64..7be2f2f 100644
--- a/tccgen.c
+++ b/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 */