aboutsummaryrefslogtreecommitdiff
path: root/tccgen.c
diff options
context:
space:
mode:
Diffstat (limited to 'tccgen.c')
-rw-r--r--tccgen.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/tccgen.c b/tccgen.c
index d5b915b..bab4f7c 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -2740,7 +2740,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)
{
- int a, v, size, align, maxalign, c, offset;
+ int a, v, size, align, maxalign, c, offset, flexible;
int bit_size, bit_pos, bsize, bt, lbit_pos, prevbt;
Sym *s, *ss, *ass, **ps;
AttributeDef ad;
@@ -2814,9 +2814,13 @@ static void struct_decl(CType *type, int u, int tdef)
prevbt = VT_INT;
bit_pos = 0;
offset = 0;
+ flexible = 0;
while (tok != '}') {
parse_btype(&btype, &ad);
while (1) {
+ if (flexible)
+ tcc_error("flexible array member '%s' not at the end of struct",
+ get_tok_str(v, NULL));
bit_size = -1;
v = 0;
type1 = btype;
@@ -2824,6 +2828,13 @@ static void struct_decl(CType *type, int u, int tdef)
type_decl(&type1, &ad, &v, TYPE_DIRECT | TYPE_ABSTRACT);
if (v == 0 && (type1.t & VT_BTYPE) != VT_STRUCT)
expect("identifier");
+ if (type_size(&type1, &align) < 0) {
+ if ((a == TOK_STRUCT) && (type1.t & VT_ARRAY) && c)
+ flexible = 1;
+ else
+ tcc_error("field '%s' has incomplete type",
+ get_tok_str(v, NULL));
+ }
if ((type1.t & VT_BTYPE) == VT_FUNC ||
(type1.t & (VT_TYPEDEF | VT_STATIC | VT_EXTERN | VT_INLINE)))
tcc_error("invalid type for '%s'",