diff --git a/tccgen.c b/tccgen.c index 67cf6b9c..c293074a 100644 --- a/tccgen.c +++ b/tccgen.c @@ -1263,7 +1263,7 @@ static void patch_type(Sym *sym, CType *type) } else { if ((sym->type.t & VT_ARRAY) && type->ref->c >= 0) { /* set array size if it was omitted in extern declaration */ - sym->type.ref = type->ref; + sym->type.ref->c = type->ref->c; } if ((type->t ^ sym->type.t) & VT_STATIC) tcc_warning("storage mismatch for redefinition of '%s'", @@ -4890,6 +4890,8 @@ static int parse_btype(CType *type, AttributeDef *ad, int ignore_label) sym_to_attr(ad, s); typespec_found = 1; st = bt = -2; + if (type->ref && (t & VT_ARRAY) && type->ref->c < 0) + type->ref = sym_push(SYM_FIELD, &type->ref->type, 0, type->ref->c); break; } type_found = 1; @@ -4992,7 +4994,7 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) type_decl(&pt, &ad1, &n, TYPE_DIRECT | TYPE_ABSTRACT | TYPE_PARAM); if ((pt.t & VT_BTYPE) == VT_VOID) tcc_error("parameter declared as void"); - if (n == 0) + if (local_scope > 1 || n == 0) n = SYM_FIELD; } else { n = tok; @@ -5000,7 +5002,7 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) pt.ref = NULL; next(); } - if (n < TOK_UIDENT) + if (local_scope == 1 && n < TOK_UIDENT) expect("identifier"); convert_parameter_type(&pt); arg_size += (type_size(&pt, &align) + PTR_SIZE - 1) / PTR_SIZE; @@ -8685,7 +8687,9 @@ static int decl(int l) sym = type.ref; if (sym->f.func_type == FUNC_OLD && l == VT_CONST) { func_vt = type; + ++local_scope; decl(VT_CMP); + --local_scope; } if ((type.t & (VT_EXTERN|VT_INLINE)) == (VT_EXTERN|VT_INLINE)) { /* always_inline functions must be handled as if they diff --git a/tests/tests2/129_scopes.c b/tests/tests2/129_scopes.c index 08c8b316..b8a21ad8 100644 --- a/tests/tests2/129_scopes.c +++ b/tests/tests2/129_scopes.c @@ -76,11 +76,48 @@ struct st func(void) return st; } +/* --------------------------------------------- */ +static void func2(char *(*md)(char *md)) +{ + (*md)("test"); +} + +static char *a(char *a) +{ + printf("%s\n", a); + return a; +} + +int main_4(void) +{ + func2(a); + return 0; +} + +/* --------------------------------------------- */ +int b[3]; +int f(void); + +int main_5(void) +{ + extern int b[3]; + b[2]=10; + printf("%d\n", f()); + return 0; +} + +int f(void) +{ + return b[2]==10 ? 1 : 0; +} + /* --------------------------------------------- */ int main() { main_1(); main_2(); main_3(); + main_4(); + main_5(); return 0; } diff --git a/tests/tests2/129_scopes.expect b/tests/tests2/129_scopes.expect index 0e90240c..e5006a0e 100644 --- a/tests/tests2/129_scopes.expect +++ b/tests/tests2/129_scopes.expect @@ -21,3 +21,5 @@ 129_scopes.c:43: ok : "!in" 129_scopes.c:59: ok : "c == 'a'" 129_scopes.c:69: ok : "st.a == 10" +test +1 diff --git a/tests/tests2/133_old_func.c b/tests/tests2/133_old_func.c index cb702194..73e5b7fe 100644 --- a/tests/tests2/133_old_func.c +++ b/tests/tests2/133_old_func.c @@ -8,6 +8,16 @@ float x; void func(float a); +void func3(struct p { int a; int b; } *q) { +} + +void func4(q) + struct p { int a; int b; int c; } *q; +{ +} + +struct p { int a; int b; int c; int d; }; + int main(void) { diff --git a/tests/tests2/39_typedef.c b/tests/tests2/39_typedef.c index da73f71e..f3ab6560 100644 --- a/tests/tests2/39_typedef.c +++ b/tests/tests2/39_typedef.c @@ -12,8 +12,11 @@ typedef struct FunStruct MyFunStruct; typedef MyFunStruct *MoreFunThanEver; +typedef int t[]; + int main() { + int i, *p; MyInt a = 1; printf("%d\n", a); @@ -25,6 +28,14 @@ int main() MoreFunThanEver c = &b; printf("%d,%d\n", c->i, c->j); + p = (t){1,2,3}; + for (i = 0; i < 3 ; i++) printf("%d ", *p++); printf("\n"); + p = (t){1,2,3,4}; + for (i = 0; i < 4 ; i++) printf("%d ", *p++); printf("\n"); + + printf("%d\n", (int)sizeof((t){1,2,3})); + printf("%d\n", (int)sizeof((t){1,2,3,4})); + return 0; } diff --git a/tests/tests2/39_typedef.expect b/tests/tests2/39_typedef.expect index b9050a9b..39d75869 100644 --- a/tests/tests2/39_typedef.expect +++ b/tests/tests2/39_typedef.expect @@ -1,3 +1,7 @@ 1 12,34 12,34 +1 2 3 +1 2 3 4 +12 +16