From fe23a14ebb692084cc1720a5f25157797d680c15 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Mon, 17 Jun 2019 18:52:49 +0200 Subject: [PATCH] Deal with more tentative definitions see testcase. --- tccgen.c | 1 + tests/tcctest.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/tccgen.c b/tccgen.c index 618e5ae..ca2a9a5 100644 --- a/tccgen.c +++ b/tccgen.c @@ -1005,6 +1005,7 @@ static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad) Sym *s; s = sym_find(v); if (!s || (!IS_ASM_SYM(s) && !(s->type.t & VT_EXTERN) + && (!(type->t & VT_EXTERN) || s->sym_scope) && (s->type.t & VT_BTYPE) != VT_FUNC)) { if (s && !is_compatible_types(&s->type, type)) tcc_error("conflicting types for '%s'", get_tok_str(s->v, NULL)); diff --git a/tests/tcctest.c b/tests/tcctest.c index 77d7946..49bf863 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -816,6 +816,16 @@ void scope_test2() printf("exloc: %d\n", *st2_p); } +/* C has tentative definition, and they may be repeated. */ +extern int st_global1; +int st_global1=42; +extern int st_global1; +int st_global1; +extern int st_global2; +int st_global2; +extern int st_global2; +int st_global2; + void array_test() { int i, j, a[4];