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
50 50
51ST_DATA Sym *global_stack;51ST_DATA Sym *global_stack;
52ST_DATA Sym *local_stack;52ST_DATA Sym *local_stack;
53ST_DATA Sym *scope_stack_bottom;
53ST_DATA Sym *define_stack;54ST_DATA Sym *define_stack;
54ST_DATA Sym *global_label_stack;55ST_DATA Sym *global_label_stack;
55ST_DATA Sym *local_label_stack;56ST_DATA Sym *local_label_stack;
@@ -147,6 +148,13 @@ ST_INLN void sym_free(Sym *sym) · 91 unmodified lines
147ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, long c)148ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, long c)
148{149{
149 Sym *s;150 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;
150 s = sym_malloc();158 s = sym_malloc();
151 s->asm_label = NULL;159 s->asm_label = NULL;
152 s->v = v;160 s->v = v;
@@ -4347,7 +4355,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 4194 unmodified lines
4347 int case_reg, int is_expr)4355 int case_reg, int is_expr)
4348{4356{
4349 int a, b, c, d;4357 int a, b, c, d;
4350 Sym *s;4358 Sym *s, *frame_bottom;
4351 4359
4352 /* generate line number info */4360 /* generate line number info */
4353 if (tcc_state->do_debug &&4361 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
4398 next();4406 next();
4399 /* record local declaration stack position */4407 /* record local declaration stack position */
4400 s = local_stack;4408 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;
4401 llabel = local_label_stack;4412 llabel = local_label_stack;
4402 /* handle local labels declarations */4413 /* handle local labels declarations */
4403 if (tok == TOK_LABEL) {4414 if (tok == TOK_LABEL) {
@@ -4440,6 +4451,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 36 unmodified lines
4440 }4451 }
4441 }4452 }
4442 /* pop locally defined symbols */4453 /* pop locally defined symbols */
4454 scope_stack_bottom = scope_stack_bottom->next;
4443 sym_pop(&local_stack, s);4455 sym_pop(&local_stack, s);
4444 next();4456 next();
4445 } else if (tok == TOK_RETURN) {4457 } 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
4510 next();4522 next();
4511 skip('(');4523 skip('(');
4512 s = local_stack;4524 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;
4513 if (tok != ';') {4528 if (tok != ';') {
4514 /* c99 for-loop init decl? */4529 /* c99 for-loop init decl? */
4515 if (!decl0(VT_LOCAL, 1)) {4530 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
4541 gjmp_addr(c);4556 gjmp_addr(c);
4542 gsym(a);4557 gsym(a);
4543 gsym_addr(b, c);4558 gsym_addr(b, c);
4559 scope_stack_bottom = scope_stack_bottom->next;
4544 sym_pop(&local_stack, s);4560 sym_pop(&local_stack, s);
4545 } else 4561 } else
4546 if (tok == TOK_DO) {4562 if (tok == TOK_DO) {
@@ -5509,7 +5525,9 @@ static void gen_function(Sym *sym) · 962 unmodified lines
5509 gfunc_epilog();5525 gfunc_epilog();
5510 cur_text_section->data_offset = ind;5526 cur_text_section->data_offset = ind;
5511 label_pop(&global_label_stack, NULL);5527 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);
5513 /* end of function */5531 /* end of function */
5514 /* patch symbol size */5532 /* patch symbol size */
5515 ((ElfW(Sym) *)symtab_section->data)[sym->c].st_size = 5533 ((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
5577 CType type, btype;5595 CType type, btype;
5578 Sym *sym;5596 Sym *sym;
5579 AttributeDef ad;5597 AttributeDef ad;
5580 5598
5581 while (1) {5599 while (1) {
5582 if (!parse_btype(&btype, &ad)) {5600 if (!parse_btype(&btype, &ad)) {
5583 if (is_for_loop_init)5601 if (is_for_loop_init)