Skip to content

Commit 2662b7b

Browse files
author
grischka
committed
tccgen: local scope for types of function parameters
int foo(struct xxx {int x[3];} *p) { ... We want 'xxx' be visible only inside the function. To get that, the patch removes the 'sym_push(param)' in xxx-gen.c, and instead (in tccgen.c:gen_function()) pushes all symbols that were newly defined during parsing of the parameter list in post_type(). Also, - decl_initializer_alloc(): patch existing globals earlier, which updates flex arrays too - let patch_type() do the 'redefinition' check and FUNC_OLD update
1 parent deb7a3f commit 2662b7b

File tree

12 files changed

+233
-170
lines changed

12 files changed

+233
-170
lines changed

arm-gen.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,8 +1493,7 @@ void gfunc_prolog(Sym *func_sym)
14931493
addr = (n + nf + sn) * 4;
14941494
sn += size;
14951495
}
1496-
sym_push(sym->v & ~SYM_FIELD, type, VT_LOCAL | VT_LVAL,
1497-
addr + 12);
1496+
gfunc_set_param(sym, addr + 12, 0);
14981497
}
14991498
last_itod_magic=0;
15001499
leaffunc = 1;

arm64-gen.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,9 +1242,8 @@ ST_FUNC void gfunc_prolog(Sym *func_sym)
12421242
int off = (a[i] < 16 ? 160 + a[i] / 2 * 8 :
12431243
a[i] < 32 ? 16 + (a[i] - 16) / 2 * 16 :
12441244
224 + ((a[i] - 32) >> 1 << 1));
1245-
sym_push(sym->v & ~SYM_FIELD, &sym->type,
1246-
(a[i] & 1 ? VT_LLOCAL : VT_LOCAL) | VT_LVAL,
1247-
off);
1245+
1246+
gfunc_set_param(sym, off, a[i] & 1);
12481247

12491248
if (a[i] < 16) {
12501249
int align, size = type_size(&sym->type, &align);

c67-gen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,7 @@ void gfunc_prolog(Sym *func_sym)
19681968
/* define parameters */
19691969
while ((sym = sym->next) != NULL) {
19701970
type = &sym->type;
1971-
sym_push(sym->v & ~SYM_FIELD, type, VT_LOCAL | VT_LVAL, addr);
1971+
gfunc_set_param(sym, addr, 0);
19721972
size = type_size(type, &align);
19731973
size = (size + 3) & ~3;
19741974

i386-gen.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,7 @@ ST_FUNC void gfunc_prolog(Sym *func_sym)
578578
param_addr = addr;
579579
addr += size;
580580
}
581-
sym_push(sym->v & ~SYM_FIELD, type,
582-
VT_LOCAL | VT_LVAL, param_addr);
581+
gfunc_set_param(sym, param_addr, 0);
583582
param_index++;
584583
}
585584
func_ret_sub = 0;

riscv64-gen.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -833,9 +833,7 @@ ST_FUNC void gfunc_prolog(Sym *func_sym)
833833
}
834834
}
835835
}
836-
sym_push(sym->v & ~SYM_FIELD, &sym->type,
837-
(byref ? VT_LLOCAL : VT_LOCAL) | VT_LVAL,
838-
param_addr);
836+
gfunc_set_param(sym, param_addr, byref);
839837
}
840838
func_va_list_ofs = addr;
841839
num_va_regs = 0;

tcc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,7 @@ ST_FUNC int classify_x86_64_va_arg(CType *ty);
15061506
ST_FUNC void gbound_args(int nb_args);
15071507
ST_DATA int func_bound_add_epilog;
15081508
#endif
1509+
ST_FUNC Sym *gfunc_set_param(Sym *s, int c, int byref);
15091510

15101511
/* ------------ tccelf.c ------------ */
15111512

@@ -1856,7 +1857,7 @@ ST_FUNC void tcc_debug_eincl(TCCState *s1);
18561857
ST_FUNC void tcc_debug_newfile(TCCState *s1);
18571858

18581859
ST_FUNC void tcc_debug_line(TCCState *s1);
1859-
ST_FUNC void tcc_add_debug_info(TCCState *s1, int param, Sym *s, Sym *e);
1860+
ST_FUNC void tcc_add_debug_info(TCCState *s1, Sym *s, Sym *e);
18601861
ST_FUNC void tcc_debug_funcstart(TCCState *s1, Sym *sym);
18611862
ST_FUNC void tcc_debug_prolog_epilog(TCCState *s1, int value);
18621863
ST_FUNC void tcc_debug_funcend(TCCState *s1, int size);

tccdbg.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,7 @@ static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result)
16251625

16261626
t = t->type.ref;
16271627
debug_type = tcc_debug_find(s1, t, 0);
1628-
if (debug_type == -1) {
1628+
if (debug_type == -1 && t->c >= 0) {
16291629
debug_type = tcc_debug_add(s1, t, 0);
16301630
cstr_new (&str);
16311631
cstr_printf (&str, "%s:T%d=%c%d",
@@ -1664,7 +1664,7 @@ static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result)
16641664
Sym *e = t = t->type.ref;
16651665

16661666
debug_type = tcc_debug_find(s1, t, 0);
1667-
if (debug_type == -1) {
1667+
if (debug_type == -1 && t->c >= 0) {
16681668
debug_type = tcc_debug_add(s1, t, 0);
16691669
cstr_new (&str);
16701670
cstr_printf (&str, "%s:T%d=e",
@@ -1741,7 +1741,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s)
17411741
if ((type & VT_BTYPE) == VT_STRUCT) {
17421742
t = t->type.ref;
17431743
debug_type = tcc_debug_find(s1, t, 1);
1744-
if (debug_type == -1) {
1744+
if (debug_type == -1 && t->c >= 0) {
17451745
int pos_sib = 0, i, *pos_type;
17461746

17471747
debug_type = tcc_debug_add(s1, t, 1);
@@ -1819,7 +1819,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s)
18191819
else if (IS_ENUM(type)) {
18201820
t = t->type.ref;
18211821
debug_type = tcc_debug_find(s1, t, 1);
1822-
if (debug_type == -1) {
1822+
if (debug_type == -1 && t->c >= 0) {
18231823
int pos_sib, pos_type;
18241824
Sym sym = {0}; sym.type.t = VT_INT | (type & VT_UNSIGNED);
18251825

@@ -2090,14 +2090,16 @@ static void tcc_debug_finish (TCCState *s1, struct _debug_info *cur)
20902090
}
20912091
}
20922092

2093-
ST_FUNC void tcc_add_debug_info(TCCState *s1, int param, Sym *s, Sym *e)
2093+
ST_FUNC void tcc_add_debug_info(TCCState *s1, Sym *s, Sym *e)
20942094
{
20952095
CString debug_str;
2096+
int param;
20962097

20972098
if (!(s1->do_debug & 2))
20982099
return;
20992100

21002101
cstr_new (&debug_str);
2102+
param = !e;
21012103
for (; s != e; s = s->prev) {
21022104
if (!s->v || (s->r & VT_VALMASK) != VT_LOCAL)
21032105
continue;

0 commit comments

Comments
 (0)