aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tccgen.c15
-rw-r--r--tests/tests2/61_undefined_enum.expect2
-rw-r--r--tests/tests2/81_types.c9
-rw-r--r--tests/tests2/81_types.expect0
4 files changed, 19 insertions, 7 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 */
diff --git a/tests/tests2/61_undefined_enum.expect b/tests/tests2/61_undefined_enum.expect
index 7ccdeca..eb8b774 100644
--- a/tests/tests2/61_undefined_enum.expect
+++ b/tests/tests2/61_undefined_enum.expect
@@ -1 +1 @@
-61_undefined_enum.c:1: error: unknown struct/union/enum
+61_undefined_enum.c:1: error: unknown type size
diff --git a/tests/tests2/81_types.c b/tests/tests2/81_types.c
new file mode 100644
index 0000000..542d066
--- /dev/null
+++ b/tests/tests2/81_types.c
@@ -0,0 +1,9 @@
+/* The following are all valid decls, even though some subtypes
+ are incomplete. */
+enum E *e;
+const enum E *e1;
+enum E const *e2;
+struct S *s;
+const struct S *s1;
+struct S const *s2;
+int main () { return 0; }
diff --git a/tests/tests2/81_types.expect b/tests/tests2/81_types.expect
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/tests2/81_types.expect