History

tccgen.c: local extern decls: copy s->ref for VT_PTR too

This fixes the issue int main() { extern char *x; } void main1() { extern char *x; } t2.c:5: error: incompatible types for redefinition of 'x' (reported by Giovanni Mascellani 2019/07/16)

grischka committed 7 years ago

Commit 7b8799e1 parent 92985554 files · +42 −14Browse files

Unified · Split

4 files
  1. Makefile +1 −1
  2. tccgen.c +17 −13
  3. tests/tests2/60_errors_and_warnings.c +22 −0
  4. tests/tests2/60_errors_and_warnings.expect +2 −0
Makefile+1−1
@@ -98,7 +98,7 @@ TCC_X += riscv64 · 97 unmodified lines
98 98
99# cross libtcc1.a targets to build99# cross libtcc1.a targets to build
100LIBTCC1_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince100LIBTCC1_X = i386 x86_64 i386-win32 x86_64-win32 x86_64-osx arm arm64 arm-wince
101LIBTCC1_X = riscv64101LIBTCC1_X += riscv64
102 102
103PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF))103PROGS_CROSS = $(foreach X,$(TCC_X),$X-tcc$(EXESUF))
104LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),$X-libtcc1.a)104LIBTCC1_CROSS = $(foreach X,$(LIBTCC1_X),$X-libtcc1.a)
tccgen.c+17−13
@@ -1096,18 +1096,24 @@ static Sym *sym_copy(Sym *s0, Sym **ps) · 1095 unmodified lines
1096 return s;1096 return s;
1097}1097}
1098 1098
1099/* copy a list of syms */1099/* copy s->type.ref to stack 'ps' for VT_FUNC and VT_PTR */
1100static void sym_copy_ref(Sym *s0, Sym **ps)1100static void sym_copy_ref(Sym *s, Sym **ps)
1101{1101{
1102 Sym *s, **sp = &s0->type.ref;1102 int bt = s->type.t & VT_BTYPE;
1103 for (s = *sp, *sp = NULL; s; s = s->next)1103 if (bt == VT_FUNC || bt == VT_PTR) {
1104 sp = &(*sp = sym_copy(s, ps))->next;1104 Sym **sp = &s->type.ref;
1105 for (s = *sp, *sp = NULL; s; s = s->next) {
1106 Sym *s2 = sym_copy(s, ps);
1107 sp = &(*sp = s2)->next;
1108 sym_copy_ref(s2, ps);
1109 }
1110 }
1105}1111}
1106 1112
1107/* define a new external reference to a symbol 'v' */1113/* define a new external reference to a symbol 'v' */
1108static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad)1114static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad)
1109{1115{
1110 Sym *s; int bt;1116 Sym *s;
1111 1117
1112 /* look for global symbol */1118 /* look for global symbol */
1113 s = sym_find(v);1119 s = sym_find(v);
@@ -1121,16 +1127,14 @@ static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad) · 7 unmodified lines
1121 s->a = ad->a;1127 s->a = ad->a;
1122 s->asm_label = ad->asm_label;1128 s->asm_label = ad->asm_label;
1123 s->type.ref = type->ref;1129 s->type.ref = type->ref;
1124 bt = s->type.t & (VT_BTYPE|VT_ARRAY);1130 /* copy type to the global stack */
1125 /* copy type to the global stack also */1131 if (local_stack)
1126 if (local_scope && (bt == VT_FUNC || (bt & VT_ARRAY)))
1127 sym_copy_ref(s, &global_stack);1132 sym_copy_ref(s, &global_stack);
1128 } else {1133 } else {
1129 patch_storage(s, ad, type);1134 patch_storage(s, ad, type);
1130 bt = s->type.t & VT_BTYPE;
1131 }1135 }
1132 /* push variables to local scope if any */1136 /* push variables on local_stack if any */
1133 if (local_stack && bt != VT_FUNC)1137 if (local_stack && (s->type.t & VT_BTYPE) != VT_FUNC)
1134 s = sym_copy(s, &local_stack);1138 s = sym_copy(s, &local_stack);
1135 return s;1139 return s;
1136}1140}
tests/tests2/60_errors_and_warnings.c+22−0
@@ -273,5 +273,27 @@ int main () · 272 unmodified lines
273int xxx[1] = {1};273int xxx[1] = {1};
274int bar() { P(3, xxx[0]); return 0; }274int bar() { P(3, xxx[0]); return 0; }
275 275
276#elif defined test_var_4
277struct yyy { int y; };
278struct zzz;
279void f1() {
280 extern char *x;
281 extern char **xx;
282 extern struct yyy y;
283 extern struct yyy *yy;
284 extern struct zzz z;
285 extern struct zzz *zz;
286}
287void f2() {
288 extern char *x;
289 extern char **xx;
290 extern struct yyy y;
291 extern struct yyy *yy;
292 extern struct zzz z;
293 extern struct zzz *zz;
294}
295struct yyy y, *yy;
296struct zzz { int z; } z, *zz;
297
276/******************************************************************/298/******************************************************************/
277#endif299#endif
tests/tests2/60_errors_and_warnings.expect+2−0
@@ -132,3 +132,5 @@ bar : 3 ; 3 · 131 unmodified lines
132 132
133[test_var_3]133[test_var_3]
13460_errors_and_warnings.c:273: error: incompatible types for redefinition of 'xxx'13460_errors_and_warnings.c:273: error: incompatible types for redefinition of 'xxx'
135
136[test_var_4]

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