History

Detect invalid VLA decls

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.

Michael Matz committed 7 years ago

Commit 2a417b51 parent 5ac2a263 files · +12 −0Browse files

Unified · Split

3 files
  1. tccgen.c +3 −0
  2. tests/tests2/60_errors_and_warnings.c +6 −0
  3. tests/tests2/60_errors_and_warnings.expect +3 −0
tccgen.c+3−0
@@ -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;
tests/tests2/60_errors_and_warnings.c+6−0
@@ -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
170int X=1;
171
172int main(void) {
173 int t[][][X];
174}
169#endif175#endif
tests/tests2/60_errors_and_warnings.expect+3−0
@@ -77,3 +77,6 @@ · 76 unmodified lines
77 77
78[test_nested_types]78[test_nested_types]
7960_errors_and_warnings.c:166: error: struct/union/enum already defined7960_errors_and_warnings.c:166: error: struct/union/enum already defined
80
81[test_vla_1]
8260_errors_and_warnings.c:173: error: need explicit inner array size in VLAs

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t