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 <stdio.h>

    // 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++;
    }
This commit is contained in:
seyko 2015-03-03 15:00:13 +03:00
parent a429d40f06
commit bbf8221ec3

View file

@ -3148,14 +3148,14 @@ static int parse_btype(CType *type, AttributeDef *ad)
} }
break; break;
case TOK_ENUM: case TOK_ENUM:
struct_decl(&type1, VT_ENUM, t & VT_TYPEDEF); struct_decl(&type1, VT_ENUM, t & (VT_TYPEDEF | VT_EXTERN));
basic_type2: basic_type2:
u = type1.t; u = type1.t;
type->ref = type1.ref; type->ref = type1.ref;
goto basic_type1; goto basic_type1;
case TOK_STRUCT: case TOK_STRUCT:
case TOK_UNION: case TOK_UNION:
struct_decl(&type1, VT_STRUCT, t & VT_TYPEDEF); struct_decl(&type1, VT_STRUCT, t & (VT_TYPEDEF | VT_EXTERN));
goto basic_type2; goto basic_type2;
/* type modifiers */ /* type modifiers */