From e034853b38907440142107eb689c5dd6c6621fca Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Wed, 13 Jul 2016 17:39:15 +0200 Subject: Fix parsing array typedefs of unknown size This must compile: typedef int arrtype1[]; arrtype1 sinit19 = {1}; arrtype1 sinit20 = {2,3}; and generate two arrays of one resp. two elements. Before the fix the determined size of the first array was encoded in the type directly, so sinit20 couldn't be parsed anymore (because arrtype1 was thought to be only one element long). --- tccgen.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tccgen.c') diff --git a/tccgen.c b/tccgen.c index c006f71..6d72ab9 100644 --- a/tccgen.c +++ b/tccgen.c @@ -6657,6 +6657,14 @@ static int decl0(int l, int is_for_loop_init) } while (1) { /* iterate thru each declaration */ type = btype; + /* If the base type itself was an array type of unspecified + size (like in 'typedef int arr[]; arr x = {1};') then + we will overwrite the unknown size by the real one for + this decl. We need to unshare the ref symbol holding + that size. */ + if ((type.t & VT_ARRAY) && type.ref->c < 0) { + type.ref = sym_push(SYM_FIELD, &type.ref->type, 0, type.ref->c); + } type_decl(&type, &ad, &v, TYPE_DIRECT); #if 0 { -- cgit v1.3.1