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
45214521 } else {
45224522 if (!is_integer_btype(vtop->type.t & VT_BTYPE))
45234523 tcc_error("size of variable length array should be an integer");
4524+ n = 0;
45244525 t1 = VT_VLA;
45254526 }
45264527 }
@@ -4532,6 +4533,8 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) · 5 unmodified lines
45324533 t1 |= type->t & VT_VLA;
45334534
45344535 if (t1 & VT_VLA) {
4536+ if (n < 0)
4537+ tcc_error("need explicit inner array size in VLAs");
45354538 loc -= type_size(&int_type, &align);
45364539 loc &= -align;
45374540 n = loc;
tests/tests2/60_errors_and_warnings.c+6−0
@@ -166,4 +166,10 @@ union u { · 165 unmodified lines
166166 int i;
167167 } m;
168168 };
169+#elif defined test_vla_1
170+int X=1;
171+
172+int main(void) {
173+ int t[][][X];
174+}
169175 #endif
tests/tests2/60_errors_and_warnings.expect+3−0
@@ -77,3 +77,6 @@ · 76 unmodified lines
7777
7878 [test_nested_types]
7979 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

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