tccgen: flex arrays etc.

Fixes potential writes past the allocated space with mostly
illegal flex array initializers. (60_errors_and_warnings.c
:test_var_array)

In exchange suspicious precautions such as section_reserve
or checks with sec->data_allocated were removed.  (There is
an hard check 'init_assert()' for now but it's meant to be
just temporary)

Also, instead of filling holes, always memset(0) structures
& arrays on stack.  Sometimes more efficient, sometimes isn't.
At least we can omit putting null initializers.

About array range inititializers:  Reparsing tokens has a
small problem with sideeffects, for example

   int c = 0, dd[] = { [0 ... 1] = ++c, [2 ... 3] = ++c };

Also, instead of 'squeeze_multi_relocs()', delete pre-existing
relocations in advance. This works even if secondary initializers
don't even have relocations, as with
    [0 ... 7] = &stuff,
    [4] = NULL

Also, in tcc.h: new macro "tcc_internal_error()"
This commit is contained in:
grischka
2020-09-23 12:03:59 +02:00
parent 40395511d7
commit 72b520e709
9 changed files with 312 additions and 225 deletions

View File

@@ -346,4 +346,13 @@ static struct var_len { int i; const char str[]; } var_array[] =
{ 2, "longlonglonglonglong" },
{ 3, "tst3" } };
#elif defined test_var_array2
struct c1 { int a; int b[]; };
struct c1 c1 = { 1, { 2, 3, 4 } };
struct c2 { int c; struct c1 c1; };
struct c2 c2 = { 1, { 2, { 3, 4, 5 }}};
/******************************************************************/
#endif