Fix multidimensional arrays on stack
This commit is contained in:
parent
4efcada291
commit
8a3d0a0557
2 changed files with 38 additions and 1 deletions
4
tccgen.c
4
tccgen.c
|
|
@ -5442,7 +5442,8 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td)
|
||||||
}
|
}
|
||||||
if (tok != ']') {
|
if (tok != ']') {
|
||||||
nocode_wanted = 1;
|
nocode_wanted = 1;
|
||||||
gexpr(), vpop();
|
gexpr();
|
||||||
|
goto check;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -5457,6 +5458,7 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td)
|
||||||
nocode_wanted = 0;
|
nocode_wanted = 0;
|
||||||
gexpr();
|
gexpr();
|
||||||
}
|
}
|
||||||
|
check:
|
||||||
if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
|
if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
|
||||||
n = vtop->c.i;
|
n = vtop->c.i;
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
|
|
|
||||||
|
|
@ -2997,10 +2997,45 @@ void c99_vla_test_2(int d, int h, int w)
|
||||||
free (arr);
|
free (arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void c99_vla_test_3a (int arr[2][3][4])
|
||||||
|
{
|
||||||
|
printf ("%d\n", arr[1][2][3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void c99_vla_test_3b(int s, int arr[s][3][4])
|
||||||
|
{
|
||||||
|
printf ("%d\n", arr[1][2][3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void c99_vla_test_3c(int s, int arr[2][s][4])
|
||||||
|
{
|
||||||
|
printf ("%d\n", arr[1][2][3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void c99_vla_test_3d(int s, int arr[2][3][s])
|
||||||
|
{
|
||||||
|
printf ("%d\n", arr[1][2][3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void c99_vla_test_3(void)
|
||||||
|
{
|
||||||
|
int a[2][3][4];
|
||||||
|
|
||||||
|
memset (a, 0, sizeof(a));
|
||||||
|
a[1][2][3] = 2;
|
||||||
|
c99_vla_test_3a(a);
|
||||||
|
c99_vla_test_3b(2, a);
|
||||||
|
#if 0 // FIXME
|
||||||
|
c99_vla_test_3c(3, a);
|
||||||
|
c99_vla_test_3d(4, a);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void c99_vla_test(void)
|
void c99_vla_test(void)
|
||||||
{
|
{
|
||||||
c99_vla_test_1(5, 2);
|
c99_vla_test_1(5, 2);
|
||||||
c99_vla_test_2(3, 4, 5);
|
c99_vla_test_2(3, 4, 5);
|
||||||
|
c99_vla_test_3();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue