mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-27 06:10:06 +08:00
Fix complex static initializers (handle additional '}' and '{' brackets)
- added an example to test suite - the "warning: assignment discards qualifiers from pointer target type" is present but harmless
This commit is contained in:
parent
a3ebdd0aeb
commit
dbefae52b0
12
tccgen.c
12
tccgen.c
@ -4768,7 +4768,7 @@ static void init_putz(CType *t, Section *sec, unsigned long c, int size)
|
|||||||
static void decl_initializer(CType *type, Section *sec, unsigned long c,
|
static void decl_initializer(CType *type, Section *sec, unsigned long c,
|
||||||
int first, int size_only)
|
int first, int size_only)
|
||||||
{
|
{
|
||||||
int index, array_length, n, no_oblock, nb, parlevel, i;
|
int index, array_length, n, no_oblock, nb, parlevel, parlevel1, i;
|
||||||
int size1, align1, expr_type;
|
int size1, align1, expr_type;
|
||||||
Sym *s, *f;
|
Sym *s, *f;
|
||||||
CType *t1;
|
CType *t1;
|
||||||
@ -4970,13 +4970,17 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c,
|
|||||||
skip('}');
|
skip('}');
|
||||||
} else if (size_only) {
|
} else if (size_only) {
|
||||||
/* just skip expression */
|
/* just skip expression */
|
||||||
parlevel = 0;
|
parlevel = parlevel1 = 0;
|
||||||
while ((parlevel > 0 || (tok != '}' && tok != ',')) &&
|
while ((parlevel > 0 || parlevel1 > 0 ||
|
||||||
tok != -1) {
|
(tok != '}' && tok != ',')) && tok != -1) {
|
||||||
if (tok == '(')
|
if (tok == '(')
|
||||||
parlevel++;
|
parlevel++;
|
||||||
else if (tok == ')')
|
else if (tok == ')')
|
||||||
parlevel--;
|
parlevel--;
|
||||||
|
else if (tok == '{')
|
||||||
|
parlevel1++;
|
||||||
|
else if (tok == '}')
|
||||||
|
parlevel1--;
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -827,6 +827,27 @@ struct aligntest4 {
|
|||||||
double a[0];
|
double a[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct complexinit0 {
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct complexinit {
|
||||||
|
int a;
|
||||||
|
struct complexinit0 *b;
|
||||||
|
};
|
||||||
|
|
||||||
|
const static struct complexinit cix[] = {
|
||||||
|
[0] = {
|
||||||
|
.a = 0xfefa,
|
||||||
|
.b = (const struct complexinit0[]) {
|
||||||
|
{ 0x80, 0x81 },
|
||||||
|
{ 0x82, 0x83 },
|
||||||
|
{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void struct_test()
|
void struct_test()
|
||||||
{
|
{
|
||||||
struct1 *s;
|
struct1 *s;
|
||||||
@ -856,6 +877,11 @@ void struct_test()
|
|||||||
printf("st2: %d %d %d\n",
|
printf("st2: %d %d %d\n",
|
||||||
s->f1, s->f2, s->f3);
|
s->f1, s->f2, s->f3);
|
||||||
printf("str_addr=%x\n", (int)st1.str - (int)&st1.f1);
|
printf("str_addr=%x\n", (int)st1.str - (int)&st1.f1);
|
||||||
|
printf("cix: %d %d %d %d %d %d %d\n",
|
||||||
|
cix[0].a,
|
||||||
|
cix[0].b[0].a, cix[0].b[0].b,
|
||||||
|
cix[0].b[1].a, cix[0].b[1].b,
|
||||||
|
cix[0].b[2].a, cix[0].b[2].b);
|
||||||
|
|
||||||
/* align / size tests */
|
/* align / size tests */
|
||||||
printf("aligntest1 sizeof=%d alignof=%d\n",
|
printf("aligntest1 sizeof=%d alignof=%d\n",
|
||||||
|
Loading…
Reference in New Issue
Block a user