History

tccgen: globalize function return type too

Commit 38ab5f65b31cd1c4fa0aed45fbf80107051ded13 was missing to move the function return type to the global stack too. Also, check redefinition in sym_push(), as before.

grischka committed 1 year ago

Commit de8c19e1 parent 47106ce1 file · +20 −17Browse files

Unified · Split

tccgen.c+20−17
@@ -367,11 +367,12 @@ static inline void psyms(const char *msg, Sym *s, Sym *last) · 366 unmodified lines
367static void type_to_str(char *buf, int buf_size, CType *type, const char *varstr);367static void type_to_str(char *buf, int buf_size, CType *type, const char *varstr);
368 368
369/* print type */369/* print type */
370static void ptype(CType *type, int v)370static void ptype(const char *msg, CType *type, int v)
371{371{
372 char buf[500];372 char buf[500];
373 type_to_str(buf, sizeof(buf), type, get_tok_str(v, NULL));373 type_to_str(buf, sizeof(buf), type,
374 printf("type = '%s'\n", buf);374 (v & ~SYM_FIELD) ? get_tok_str(v, NULL) : NULL);
375 printf("%s : %s;\n", msg, buf);
375}376}
376#endif377#endif
377 378
@@ -714,13 +715,6 @@ ST_INLN Sym *sym_find(int v) · 336 unmodified lines
714 return table_ident[v]->sym_identifier;715 return table_ident[v]->sym_identifier;
715}716}
716 717
717static 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/* make sym in-/visible to the parser */718/* make sym in-/visible to the parser */
725static inline void sym_link(Sym *s, int yes)719static 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 else725 else
732 ps = &ts->sym_identifier;726 ps = &ts->sym_identifier;
733 if (yes) {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 s->prev_tok = *ps, *ps = s;728 s->prev_tok = *ps, *ps = s;
737 s->sym_scope = local_scope;729 s->sym_scope = local_scope;
738 } else {730 } else {
@@ -740,6 +732,14 @@ static inline void sym_link(Sym *s, int yes) · 1 unmodified line
740 }732 }
741}733}
742 734
735static 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/* push a given symbol on the symbol stack */743/* push a given symbol on the symbol stack */
744ST_FUNC Sym *sym_push(int v, CType *type, int r, int c)744ST_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 if ((v & ~SYM_STRUCT) < SYM_FIRST_ANOM) {755 if ((v & ~SYM_STRUCT) < SYM_FIRST_ANOM) {
756 /* record symbol in token array */756 /* record symbol in token array */
757 sym_link(s, 1);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 return s;761 return s;
760}762}
@@ -1330,7 +1332,7 @@ static void move_ref_to_global(Sym *s) · 569 unmodified lines
1330 if (!(bt == VT_PTR1332 if (!(bt == VT_PTR
1331 || bt == VT_FUNC1333 || bt == VT_FUNC
1332 || bt == VT_STRUCT1334 || bt == VT_STRUCT
1333 || ((IS_ENUM(s->type.t)) && (bt = VT_ENUM,1))))1335 || IS_ENUM(s->type.t)))
1334 return;1336 return;
1335 1337
1336 for (s = s->type.ref, n = 0; s; s = s->next) {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 if (l == s) {1340 if (l == s) {
1339 *lp = s->prev;1341 *lp = s->prev;
1340 s->prev = global_stack, global_stack = s;1342 s->prev = global_stack, global_stack = s;
1341 if (n || bt == VT_PTR) {1343 if (n || bt == VT_PTR || bt == VT_FUNC) {
1342 move_ref_to_global(s);1344 move_ref_to_global(s);
1343 } else {1345 } else {
1344 if ((bt == VT_STRUCT || bt == VT_ENUM)1346 if ((s->v & ~SYM_STRUCT) < SYM_FIRST_ANOM) {
1345 && (s->v & ~SYM_STRUCT) < SYM_FIRST_ANOM) {
1346 /* copy struct/enum tag to local scope */1347 /* copy struct/enum tag to local scope */
1347 s->v |= SYM_FIELD;1348 s->v |= SYM_FIELD;
1348 l = sym_copy(s, lp);1349 l = sym_copy(s, lp);
1349 l->v &= ~SYM_FIELD;1350 l->v &= ~SYM_FIELD;
1350 }1351 }
1351 n = 1;
1352 }1352 }
1353 if (bt != VT_PTR)
1354 n = 1;
1353 break;1355 break;
1354 }1356 }
1355 }1357 }
@@ -8715,6 +8717,7 @@ static int decl(int l) · 7359 unmodified lines
8715 type = btype;8717 type = btype;
8716 ad = adbase;8718 ad = adbase;
8717 type_decl(&type, &ad, &v, TYPE_DIRECT);8719 type_decl(&type, &ad, &v, TYPE_DIRECT);
8720 /*ptype("decl", &type, v);*/
8718 8721
8719 if ((type.t & VT_BTYPE) == VT_FUNC) {8722 if ((type.t & VT_BTYPE) == VT_FUNC) {
8720 if ((type.t & VT_STATIC) && (l != VT_CONST))8723 if ((type.t & VT_STATIC) && (l != VT_CONST))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t