mirror of
https://github.com/mirror/tinycc.git
synced 2024-12-26 03:50:07 +08:00
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).
This commit is contained in:
parent
b7e0b693a6
commit
e034853b38
8
tccgen.c
8
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
|
||||
{
|
||||
|
@ -1446,6 +1446,13 @@ struct complexinit2 cix22 = {
|
||||
.b = { 4001, 4002, 4003, 4004, 4005, 4006 }
|
||||
};
|
||||
|
||||
typedef int arrtype1[];
|
||||
arrtype1 sinit19 = {1};
|
||||
arrtype1 sinit20 = {2,3};
|
||||
typedef int arrtype2[3];
|
||||
arrtype2 sinit21 = {4};
|
||||
arrtype2 sinit22 = {5,6,7};
|
||||
|
||||
void init_test(void)
|
||||
{
|
||||
int linit1 = 2;
|
||||
@ -1546,6 +1553,13 @@ void init_test(void)
|
||||
cix[0].b[2].a, cix[0].b[2].b);
|
||||
printf("cix2: %d %d\n", cix21.b[2], cix22.b[5]);
|
||||
printf("sizeof cix20 %d, cix21 %d, sizeof cix22 %d\n", sizeof cix20, sizeof cix21, sizeof cix22);
|
||||
|
||||
printf("arrtype1: %d %d %d\n", sinit19[0], sinit20[0], sinit20[1]);
|
||||
printf("arrtype2: %d %d\n", sizeof(sinit19), sizeof(sinit20));
|
||||
printf("arrtype3: %d %d %d\n", sinit21[0], sinit21[1], sinit21[2]);
|
||||
printf("arrtype4: %d %d %d\n", sinit22[0], sinit22[1], sinit22[2]);
|
||||
printf("arrtype5: %d %d\n", sizeof(sinit21), sizeof(sinit22));
|
||||
printf("arrtype6: %d\n", sizeof(arrtype2));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user