mirror of
https://github.com/mirror/tinycc.git
synced 2024-12-26 03:50:07 +08:00
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.
This commit is contained in:
parent
5ac2a26666
commit
2a417b50ee
3
tccgen.c
3
tccgen.c
@ -4521,6 +4521,7 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td)
|
||||
} else {
|
||||
if (!is_integer_btype(vtop->type.t & VT_BTYPE))
|
||||
tcc_error("size of variable length array should be an integer");
|
||||
n = 0;
|
||||
t1 = VT_VLA;
|
||||
}
|
||||
}
|
||||
@ -4532,6 +4533,8 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td)
|
||||
t1 |= type->t & VT_VLA;
|
||||
|
||||
if (t1 & VT_VLA) {
|
||||
if (n < 0)
|
||||
tcc_error("need explicit inner array size in VLAs");
|
||||
loc -= type_size(&int_type, &align);
|
||||
loc &= -align;
|
||||
n = loc;
|
||||
|
@ -166,4 +166,10 @@ union u {
|
||||
int i;
|
||||
} m;
|
||||
};
|
||||
#elif defined test_vla_1
|
||||
int X=1;
|
||||
|
||||
int main(void) {
|
||||
int t[][][X];
|
||||
}
|
||||
#endif
|
||||
|
@ -77,3 +77,6 @@
|
||||
|
||||
[test_nested_types]
|
||||
60_errors_and_warnings.c:166: error: struct/union/enum already defined
|
||||
|
||||
[test_vla_1]
|
||||
60_errors_and_warnings.c:173: error: need explicit inner array size in VLAs
|
||||
|
Loading…
Reference in New Issue
Block a user