Fix vla bug

This fixes a vla bug. Probably more fixes are needed.
Add testcode for bug.
This commit is contained in:
herman ten brugge 2021-12-27 11:39:52 +01:00
parent 1692060fb0
commit d33b189427
2 changed files with 29 additions and 3 deletions

View File

@ -3494,7 +3494,7 @@ redo:
gen_cast_s(VT_INT);
#endif
type1 = vtop[-1].type;
if (vtop[-1].type.t & VT_VLA)
if (vtop[-1].type.ref->type.t & VT_VLA)
vla_runtime_pointed_size(&vtop[-1].type);
else {
u = pointed_size(&vtop[-1].type);

View File

@ -2915,7 +2915,6 @@ typedef int constant_negative_array_size_as_compile_time_assertion_idiom[(1 ? 2
void c99_vla_test_1(int size1, int size2)
{
#if defined __i386__ || defined __x86_64__
int size = size1 * size2;
int tab1[size][2], tab2[10][2];
void *tab1_ptr, *tab2_ptr, *bad_ptr;
@ -2961,12 +2960,39 @@ void c99_vla_test_1(int size1, int size2)
printf("PASSED PASSED PASSED PASSED PASSED PASSED PASSED PASSED ");
}
printf("\n");
#endif
}
void c99_vla_test_2(int d, int h, int w)
{
int x, y, z;
int (*arr)[h][w] = malloc(sizeof(int) * d*h*w);
int c = 1;
printf("Test C99 VLA 6 (pointer)\n");
for (z=0; z<d; z++) {
for (y=0; y<h; y++) {
for (x=0; x<w; x++) {
arr[z][y][x] = c++;
}
}
}
for (z=0; z<d; z++) {
for (y=0; y<h; y++) {
for (x=0; x<w; x++) {
printf("% 4i", arr[z][y][x]);
}
puts("");
}
puts("");
}
free (arr);
}
void c99_vla_test(void)
{
c99_vla_test_1(5, 2);
c99_vla_test_2(3, 4, 5);
}