History

Error out in case of variable name clash

Error out when two local variable with same name are defined in the same scope. This fixes bug #15597 in savannah's BTS.

Thomas Preud'homme committed 14 years ago

Commit cf95ac31 parent 85f6fad1 file · +21 −3Browse files

Unified · Split

tccgen.c+21−3
@@ -50,6 +50,7 @@ ST_DATA int nb_sym_pools; · 49 unmodified lines
5050
5151 ST_DATA Sym *global_stack;
5252 ST_DATA Sym *local_stack;
53+ST_DATA Sym *scope_stack_bottom;
5354 ST_DATA Sym *define_stack;
5455 ST_DATA Sym *global_label_stack;
5556 ST_DATA Sym *local_label_stack;
@@ -147,6 +148,13 @@ ST_INLN void sym_free(Sym *sym) · 91 unmodified lines
147148 ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, long c)
148149 {
149150 Sym *s;
151+ if (ps == &local_stack) {
152+ for (s = *ps; s && s != scope_stack_bottom; s = s->prev)
153+ if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) < SYM_FIRST_ANOM && s->v == v)
154+ tcc_error("incompatible types for redefinition of '%s'",
155+ get_tok_str(v, NULL));
156+ }
157+ s = *ps;
150158 s = sym_malloc();
151159 s->asm_label = NULL;
152160 s->v = v;
@@ -4347,7 +4355,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 4194 unmodified lines
43474355 int case_reg, int is_expr)
43484356 {
43494357 int a, b, c, d;
4350− Sym *s;
4358+ Sym *s, *frame_bottom;
43514359
43524360 /* generate line number info */
43534361 if (tcc_state->do_debug &&
@@ -4398,6 +4406,9 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 44 unmodified lines
43984406 next();
43994407 /* record local declaration stack position */
44004408 s = local_stack;
4409+ frame_bottom = sym_push2(&local_stack, SYM_FIELD, 0, 0);
4410+ frame_bottom->next = scope_stack_bottom;
4411+ scope_stack_bottom = frame_bottom;
44014412 llabel = local_label_stack;
44024413 /* handle local labels declarations */
44034414 if (tok == TOK_LABEL) {
@@ -4440,6 +4451,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 36 unmodified lines
44404451 }
44414452 }
44424453 /* pop locally defined symbols */
4454+ scope_stack_bottom = scope_stack_bottom->next;
44434455 sym_pop(&local_stack, s);
44444456 next();
44454457 } else if (tok == TOK_RETURN) {
@@ -4510,6 +4522,9 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 64 unmodified lines
45104522 next();
45114523 skip('(');
45124524 s = local_stack;
4525+ frame_bottom = sym_push2(&local_stack, SYM_FIELD, 0, 0);
4526+ frame_bottom->next = scope_stack_bottom;
4527+ scope_stack_bottom = frame_bottom;
45134528 if (tok != ';') {
45144529 /* c99 for-loop init decl? */
45154530 if (!decl0(VT_LOCAL, 1)) {
@@ -4541,6 +4556,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 25 unmodified lines
45414556 gjmp_addr(c);
45424557 gsym(a);
45434558 gsym_addr(b, c);
4559+ scope_stack_bottom = scope_stack_bottom->next;
45444560 sym_pop(&local_stack, s);
45454561 } else
45464562 if (tok == TOK_DO) {
@@ -5509,7 +5525,9 @@ static void gen_function(Sym *sym) · 962 unmodified lines
55095525 gfunc_epilog();
55105526 cur_text_section->data_offset = ind;
55115527 label_pop(&global_label_stack, NULL);
5512− sym_pop(&local_stack, NULL); /* reset local stack */
5528+ /* reset local stack */
5529+ scope_stack_bottom = NULL;
5530+ sym_pop(&local_stack, NULL);
55135531 /* end of function */
55145532 /* patch symbol size */
55155533 ((ElfW(Sym) *)symtab_section->data)[sym->c].st_size =
@@ -5577,7 +5595,7 @@ static int decl0(int l, int is_for_loop_init) · 61 unmodified lines
55775595 CType type, btype;
55785596 Sym *sym;
55795597 AttributeDef ad;
5580−
5598+
55815599 while (1) {
55825600 if (!parse_btype(&btype, &ad)) {
55835601 if (is_for_loop_init)