Commit 38ab5f65b31cd1c4fa0aed45fbf80107051ded13 was missing to move the function return type to the global stack too. Also, check redefinition in sym_push(), as before.
Unified · Split
| @@ -367,11 +367,12 @@ static inline void psyms(const char *msg, Sym *s, Sym *last) · 366 unmodified lines | ||
| 367 | 367 | static void type_to_str(char *buf, int buf_size, CType *type, const char *varstr); |
| 368 | 368 | |
| 369 | 369 | /* print type */ |
| 370 | −static void ptype(CType *type, int v) | |
| 370 | +static void ptype(const char *msg, CType *type, int v) | |
| 371 | 371 | { |
| 372 | 372 | char buf[500]; |
| 373 | − type_to_str(buf, sizeof(buf), type, get_tok_str(v, NULL)); | |
| 374 | − printf("type = '%s'\n", buf); | |
| 373 | + type_to_str(buf, sizeof(buf), type, | |
| 374 | + (v & ~SYM_FIELD) ? get_tok_str(v, NULL) : NULL); | |
| 375 | + printf("%s : %s;\n", msg, buf); | |
| 375 | 376 | } |
| 376 | 377 | #endif |
| 377 | 378 | |
| @@ -714,13 +715,6 @@ ST_INLN Sym *sym_find(int v) · 336 unmodified lines | ||
| 714 | 715 | return table_ident[v]->sym_identifier; |
| 715 | 716 | } |
| 716 | 717 | |
| 717 | −static int sym_scope_e(Sym *s) | |
| 718 | −{ | |
| 719 | − return IS_ENUM_VAL (s->type.t) | |
| 720 | − ? s->type.ref->sym_scope | |
| 721 | − : s->sym_scope; | |
| 722 | −} | |
| 723 | − | |
| 724 | 718 | /* make sym in-/visible to the parser */ |
| 725 | 719 | static inline void sym_link(Sym *s, int yes) |
| 726 | 720 | { |
| @@ -731,8 +725,6 @@ static inline void sym_link(Sym *s, int yes) · 4 unmodified lines | ||
| 731 | 725 | else |
| 732 | 726 | ps = &ts->sym_identifier; |
| 733 | 727 | if (yes) { |
| 734 | − if (*ps && sym_scope_e(*ps) == local_scope) | |
| 735 | − tcc_error("redeclaration of '%s'", get_tok_str(s->v, NULL)); | |
| 736 | 728 | s->prev_tok = *ps, *ps = s; |
| 737 | 729 | s->sym_scope = local_scope; |
| 738 | 730 | } else { |
| @@ -740,6 +732,14 @@ static inline void sym_link(Sym *s, int yes) · 1 unmodified line | ||
| 740 | 732 | } |
| 741 | 733 | } |
| 742 | 734 | |
| 735 | +static inline int sym_scope_ex(Sym *s) | |
| 736 | +{ | |
| 737 | + /* enums have 'sym_scope' overwritten by 'enum_val' */ | |
| 738 | + return IS_ENUM_VAL (s->type.t) | |
| 739 | + ? s->type.ref->sym_scope | |
| 740 | + : s->sym_scope; | |
| 741 | +} | |
| 742 | + | |
| 743 | 743 | /* push a given symbol on the symbol stack */ |
| 744 | 744 | ST_FUNC Sym *sym_push(int v, CType *type, int r, int c) |
| 745 | 745 | { |
| @@ -755,6 +755,8 @@ ST_FUNC Sym *sym_push(int v, CType *type, int r, int c) · 9 unmodified lines | ||
| 755 | 755 | if ((v & ~SYM_STRUCT) < SYM_FIRST_ANOM) { |
| 756 | 756 | /* record symbol in token array */ |
| 757 | 757 | sym_link(s, 1); |
| 758 | + if (s->prev_tok && sym_scope_ex(s->prev_tok) == local_scope) | |
| 759 | + tcc_error("redeclaration of '%s'", get_tok_str(s->v, NULL)); | |
| 758 | 760 | } |
| 759 | 761 | return s; |
| 760 | 762 | } |
| @@ -1330,7 +1332,7 @@ static void move_ref_to_global(Sym *s) · 569 unmodified lines | ||
| 1330 | 1332 | if (!(bt == VT_PTR |
| 1331 | 1333 | || bt == VT_FUNC |
| 1332 | 1334 | || bt == VT_STRUCT |
| 1333 | − || ((IS_ENUM(s->type.t)) && (bt = VT_ENUM,1)))) | |
| 1335 | + || IS_ENUM(s->type.t))) | |
| 1334 | 1336 | return; |
| 1335 | 1337 | |
| 1336 | 1338 | for (s = s->type.ref, n = 0; s; s = s->next) { |
| @@ -1338,18 +1340,18 @@ static void move_ref_to_global(Sym *s) · 1 unmodified line | ||
| 1338 | 1340 | if (l == s) { |
| 1339 | 1341 | *lp = s->prev; |
| 1340 | 1342 | s->prev = global_stack, global_stack = s; |
| 1341 | − if (n || bt == VT_PTR) { | |
| 1343 | + if (n || bt == VT_PTR || bt == VT_FUNC) { | |
| 1342 | 1344 | move_ref_to_global(s); |
| 1343 | 1345 | } else { |
| 1344 | − if ((bt == VT_STRUCT || bt == VT_ENUM) | |
| 1345 | − && (s->v & ~SYM_STRUCT) < SYM_FIRST_ANOM) { | |
| 1346 | + if ((s->v & ~SYM_STRUCT) < SYM_FIRST_ANOM) { | |
| 1346 | 1347 | /* copy struct/enum tag to local scope */ |
| 1347 | 1348 | s->v |= SYM_FIELD; |
| 1348 | 1349 | l = sym_copy(s, lp); |
| 1349 | 1350 | l->v &= ~SYM_FIELD; |
| 1350 | 1351 | } |
| 1351 | − n = 1; | |
| 1352 | 1352 | } |
| 1353 | + if (bt != VT_PTR) | |
| 1354 | + n = 1; | |
| 1353 | 1355 | break; |
| 1354 | 1356 | } |
| 1355 | 1357 | } |
| @@ -8715,6 +8717,7 @@ static int decl(int l) · 7359 unmodified lines | ||
| 8715 | 8717 | type = btype; |
| 8716 | 8718 | ad = adbase; |
| 8717 | 8719 | type_decl(&type, &ad, &v, TYPE_DIRECT); |
| 8720 | + /*ptype("decl", &type, v);*/ | |
| 8718 | 8721 | |
| 8719 | 8722 | if ((type.t & VT_BTYPE) == VT_FUNC) { |
| 8720 | 8723 | if ((type.t & VT_STATIC) && (l != VT_CONST)) |