History

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.

Michael Matz committed 10 years ago

Commit f85db991 parent aa1ed614 files · +19 −7Browse files

Unified · Split

4 files
  1. tccgen.c +9 −6
  2. tests/tests2/61_undefined_enum.expect +1 −1
  3. tests/tests2/81_types.c +9 −0
  4. tests/tests2/81_types.expect +0 −0
tccgen.c+9−6
@@ -2200,7 +2200,7 @@ ST_FUNC int type_size(CType *type, int *a) · 2199 unmodified lines
22002200 *a = 8;
22012201 #endif
22022202 return 8;
2203− } else if (bt == VT_INT || bt == VT_ENUM || bt == VT_FLOAT) {
2203+ } else if (bt == VT_INT || bt == VT_FLOAT) {
22042204 *a = 4;
22052205 return 4;
22062206 } else if (bt == VT_SHORT) {
@@ -2209,6 +2209,10 @@ ST_FUNC int type_size(CType *type, int *a) · 2 unmodified lines
22092209 } else if (bt == VT_QLONG || bt == VT_QFLOAT) {
22102210 *a = 8;
22112211 return 16;
2212+ } else if (bt == VT_ENUM) {
2213+ *a = 4;
2214+ /* Enums might be incomplete, so don't just return '4' here. */
2215+ return type->ref->c;
22122216 } else {
22132217 /* char, void, function, _Bool */
22142218 *a = 1;
@@ -2902,7 +2906,7 @@ static void parse_attribute(AttributeDef *ad) · 687 unmodified lines
29022906 }
29032907
29042908 /* enum/struct/union declaration. u is either VT_ENUM or VT_STRUCT */
2905−static void struct_decl(CType *type, int u, int tdef)
2909+static void struct_decl(CType *type, int u)
29062910 {
29072911 int a, v, size, align, maxalign, c, offset, flexible;
29082912 int bit_size, bit_pos, bsize, bt, lbit_pos, prevbt;
@@ -2923,8 +2927,7 @@ static void struct_decl(CType *type, int u, int tdef) · 14 unmodified lines
29232927 if (s->type.t != a)
29242928 tcc_error("invalid type");
29252929 goto do_decl;
2926− } else if (tok >= TOK_IDENT && !tdef)
2927− tcc_error("unknown struct/union/enum");
2930+ }
29282931 } else {
29292932 v = anon_sym++;
29302933 }
@@ -3229,14 +3232,14 @@ static int parse_btype(CType *type, AttributeDef *ad) · 298 unmodified lines
32293232 }
32303233 break;
32313234 case TOK_ENUM:
3232− struct_decl(&type1, VT_ENUM, t & (VT_TYPEDEF | VT_EXTERN));
3235+ struct_decl(&type1, VT_ENUM);
32333236 basic_type2:
32343237 u = type1.t;
32353238 type->ref = type1.ref;
32363239 goto basic_type1;
32373240 case TOK_STRUCT:
32383241 case TOK_UNION:
3239− struct_decl(&type1, VT_STRUCT, t & (VT_TYPEDEF | VT_EXTERN));
3242+ struct_decl(&type1, VT_STRUCT);
32403243 goto basic_type2;
32413244
32423245 /* type modifiers */
tests/tests2/61_undefined_enum.expect+1−1
@@ -1 +1 @@
1−61_undefined_enum.c:1: error: unknown struct/union/enum
1+61_undefined_enum.c:1: error: unknown type size
tests/tests2/81_types.c+9−0
@@ -0,0 +1,9 @@
1+/* The following are all valid decls, even though some subtypes
2+ are incomplete. */
3+enum E *e;
4+const enum E *e1;
5+enum E const *e2;
6+struct S *s;
7+const struct S *s1;
8+struct S const *s2;
9+int main () { return 0; }
tests/tests2/81_types.expect+0−0

Empty file added.

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