History

tccgen: scopes levels for local symbols (update 2)

allow typedef int xxx; typedef int xxx; in the same scope as long as it is the same type

grischka committed 10 years ago

Commit a94e8d41 parent d48662d3 files · +21 −17Browse files

Unified · Split

3 files
  1. tccgen.c +14 −11
  2. tests/Makefile +1 −0
  3. tests/pp/Makefile +6 −6
tccgen.c+14−11
@@ -2927,13 +2927,10 @@ static void struct_decl(CType *type, AttributeDef *ad, int u) · 2926 unmodified lines
29272927 if (v < TOK_IDENT)
29282928 expect("struct/union/enum name");
29292929 s = struct_find(v);
2930− if (s && s->type.t == a) {
2931− if (0 == local_scope)
2932− goto do_decl; /* compatibility with past behavior */
2933− if (tok != '{' && tok != ';')
2934− goto do_decl; /* variable declaration: 'struct s x;' */
2935− if (s->scope == local_scope && (s->c == -1 || tok != '{'))
2936− goto do_decl; /* at least one must be incomplete type */
2930+ if (s && (s->scope == local_scope || (tok != '{' && tok != ';'))) {
2931+ if (s->type.t != a)
2932+ tcc_error("redefinition of '%s'", get_tok_str(v, NULL));
2933+ goto do_decl;
29372934 }
29382935 } else {
29392936 v = anon_sym++;
@@ -3435,8 +3432,6 @@ static void post_type(CType *type, AttributeDef *ad) · 495 unmodified lines
34353432 plast = &first;
34363433 arg_size = 0;
34373434 if (tok != ')') {
3438− int ls = local_scope;
3439− local_scope = 1; /* for struct decl inside function params */
34403435 for(;;) {
34413436 /* read param name and compute offset */
34423437 if (l != FUNC_OLD) {
@@ -3476,7 +3471,6 @@ static void post_type(CType *type, AttributeDef *ad) · 33 unmodified lines
34763471 break;
34773472 }
34783473 }
3479− local_scope = ls;
34803474 }
34813475 /* if no parameters, then old type prototype */
34823476 if (l == 0)
@@ -6434,7 +6428,16 @@ static int decl0(int l, int is_for_loop_init) · 2951 unmodified lines
64346428 if (btype.t & VT_TYPEDEF) {
64356429 /* save typedefed type */
64366430 /* XXX: test storage specifiers ? */
6437− sym = sym_push(v, &type, 0, 0);
6431+ sym = sym_find(v);
6432+ if (sym && sym->scope == local_scope) {
6433+ if (!is_compatible_types(&sym->type, &type)
6434+ || !(sym->type.t & VT_TYPEDEF))
6435+ tcc_error("incompatible redefinition of '%s'",
6436+ get_tok_str(v, NULL));
6437+ sym->type = type;
6438+ } else {
6439+ sym = sym_push(v, &type, 0, 0);
6440+ }
64386441 sym->a = ad.a;
64396442 sym->type.t |= VT_TYPEDEF;
64406443 } else {
tests/Makefile+1−0
@@ -250,6 +250,7 @@ cache: tcc_g · 249 unmodified lines
250250 # clean
251251 clean:
252252 $(MAKE) -C tests2 $@
253+ $(MAKE) -C pp $@
253254 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc \
254255 *-cc *-tcc *.exe \
255256 hello libtcc_test vla_test tcctest[1234] ex? tcc_g
tests/pp/Makefile+6−6
@@ -8,16 +8,18 @@ TESTS += $(patsubst %.S,%.test,$(wildcard *.S)) · 7 unmodified lines
88
99 all test : $(sort $(TESTS))
1010
11+DIFF_OPTS = -Nu -b -B -I "^\#"
12+
1113 %.test: %.c %.expect
1214 @echo PPTest $* ...
1315 -@$(TCC) -E -P $< >$*.output 2>&1 ; \
14− diff -Nu -b -B -I "^#" $(EXTRA_DIFF_OPTS) $*.expect $*.output \
16+ diff $(DIFF_OPTS) $*.expect $*.output \
1517 && rm -f $*.output
1618
1719 %.test: %.S %.expect
1820 @echo PPTest $* ...
1921 -@$(TCC) -E -P $< >$*.output 2>&1 ; \
20− diff -Nu -b -B -I "^#" $(EXTRA_DIFF_OPTS) $*.expect $*.output \
22+ diff $(DIFF_OPTS) $*.expect $*.output \
2123 && rm -f $*.output
2224
2325 # automatically generate .expect files with gcc:
@@ -33,10 +35,8 @@ all test : $(sort $(TESTS)) · 9 unmodified lines
3335 clean:
3436 rm -vf *.output
3537
36−# 02.test : EXTRA_DIFF_OPTS = -w
37−# 03.test : EXTRA_DIFF_OPTS = -w
38−# 04.test : EXTRA_DIFF_OPTS = -w
39−# 10.test : EXTRA_DIFF_OPTS = -w
38+02.test : DIFF_OPTS += -w
39+15.test : DIFF_OPTS += -w
4040
4141 # diff options:
4242 # -b ighore space changes

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