From bbf8221ec35d6197c8b717940fd0a24d1956e507 Mon Sep 17 00:00:00 2001 From: seyko Date: Tue, 3 Mar 2015 15:00:13 +0300 Subject: [PATCH] tcc don't understand am extern array of structs. A regression was found trying to compile a linux kernel 2.4.26 which can be compiled by tcc 0.9.23 /////////////////// #include // test for a bug: // compiler don't understand am extern array of structs // $ tcc test_1.c // test_1.c:8: error: unknown struct/union/enum extern struct FILE std_files[4]; int main() { return 0; } ////////////////// tcc-current /* enum/struct/union declaration. u is either VT_ENUM or VT_STRUCT */ static void struct_decl(CType *type, int u, int tdef) ... if (tok != '{') { v = tok; next(); /* struct already defined ? return it */ if (v < TOK_IDENT) expect("struct/union/enum name"); s = struct_find(v); if (s) { 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++; } tcc-0.9.23 which don't have such error /* enum/struct/union declaration. u is either VT_ENUM or VT_STRUCT */ static void struct_decl(CType *type, int u) .... if (tok != '{') { v = tok; next(); /* struct already defined ? return it */ if (v < TOK_IDENT) expect("struct/union/enum name"); s = struct_find(v); if (s) { if (s->type.t != a) error("invalid type"); goto do_decl; } } else { v = anon_sym++; } --- tccgen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tccgen.c b/tccgen.c index 383b1466..0c3c459a 100644 --- a/tccgen.c +++ b/tccgen.c @@ -3148,14 +3148,14 @@ static int parse_btype(CType *type, AttributeDef *ad) } break; case TOK_ENUM: - struct_decl(&type1, VT_ENUM, t & VT_TYPEDEF); + struct_decl(&type1, VT_ENUM, t & (VT_TYPEDEF | VT_EXTERN)); 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); + struct_decl(&type1, VT_STRUCT, t & (VT_TYPEDEF | VT_EXTERN)); goto basic_type2; /* type modifiers */ -- 2.11.4.GIT