summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorherman ten brugge <hermantenbrugge@home.nl>2021-12-27 11:39:52 +0100
committerherman ten brugge <hermantenbrugge@home.nl>2021-12-27 11:39:52 +0100
commitd33b1894273444eda8d87d9f54acdeb21ba37ce6 (patch)
treee201ccc6bbba64187271ab19ffe6f250d1eed9d2
parent1692060fb06ab04c3848e7a76c165473f1cc2630 (diff)
Fix vla bug
This fixes a vla bug. Probably more fixes are needed. Add testcode for bug.
-rw-r--r--tccgen.c2
-rw-r--r--tests/tcctest.c30
2 files changed, 29 insertions, 3 deletions
diff --git a/tccgen.c b/tccgen.c
index e0b5fd6..67e205b 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -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);
diff --git a/tests/tcctest.c b/tests/tcctest.c
index a4bb212..be31f82 100644
--- a/tests/tcctest.c
+++ b/tests/tcctest.c
@@ -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);
}