see testcase, when the inner array dimension of multi-dimensional VLAs isn't given TCC was generating invalid vstack accesses. Those are actually invalid, so just diagnose them.
Unified · Split
| @@ -4521,6 +4521,7 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) · 4520 unmodified lines | |||
| 4521 | } else { | 4521 | } else { |
| 4522 | if (!is_integer_btype(vtop->type.t & VT_BTYPE)) | 4522 | if (!is_integer_btype(vtop->type.t & VT_BTYPE)) |
| 4523 | tcc_error("size of variable length array should be an integer"); | 4523 | tcc_error("size of variable length array should be an integer"); |
| 4524 | n = 0; | ||
| 4524 | t1 = VT_VLA; | 4525 | t1 = VT_VLA; |
| 4525 | } | 4526 | } |
| 4526 | } | 4527 | } |
| @@ -4532,6 +4533,8 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) · 5 unmodified lines | |||
| 4532 | t1 |= type->t & VT_VLA; | 4533 | t1 |= type->t & VT_VLA; |
| 4533 | 4534 | ||
| 4534 | if (t1 & VT_VLA) { | 4535 | if (t1 & VT_VLA) { |
| 4536 | if (n < 0) | ||
| 4537 | tcc_error("need explicit inner array size in VLAs"); | ||
| 4535 | loc -= type_size(&int_type, &align); | 4538 | loc -= type_size(&int_type, &align); |
| 4536 | loc &= -align; | 4539 | loc &= -align; |
| 4537 | n = loc; | 4540 | n = loc; |
| @@ -166,4 +166,10 @@ union u { · 165 unmodified lines | |||
| 166 | int i; | 166 | int i; |
| 167 | } m; | 167 | } m; |
| 168 | }; | 168 | }; |
| 169 | #elif defined test_vla_1 | ||
| 170 | int X=1; | ||
| 171 | |||
| 172 | int main(void) { | ||
| 173 | int t[][][X]; | ||
| 174 | } | ||
| 169 | #endif | 175 | #endif |
| @@ -77,3 +77,6 @@ · 76 unmodified lines | |||
| 77 | 77 | ||
| 78 | [test_nested_types] | 78 | [test_nested_types] |
| 79 | 60_errors_and_warnings.c:166: error: struct/union/enum already defined | 79 | 60_errors_and_warnings.c:166: error: struct/union/enum already defined |
| 80 | |||
| 81 | [test_vla_1] | ||
| 82 | 60_errors_and_warnings.c:173: error: need explicit inner array size in VLAs | ||