reject invalid arrays in post_type()

This commit is contained in:
Pascal Cuoq 2019-06-24 10:28:36 +02:00
parent 942b73bbbb
commit cbbba01b46
3 changed files with 39 additions and 3 deletions

View File

@ -4377,7 +4377,7 @@ static int asm_label_instr(void)
static int post_type(CType *type, AttributeDef *ad, int storage, int td)
{
int n, l, t1, arg_size, align;
int n, l, t1, arg_size, align, unused_align;
Sym **plast, *s, *first;
AttributeDef ad1;
CType pt;
@ -4503,10 +4503,15 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td)
skip(']');
/* parse next post type */
post_type(type, ad, storage, 0);
if (type->t == VT_FUNC)
if ((type->t & VT_BTYPE) == VT_FUNC)
tcc_error("declaration of an array of functions");
if ((type->t & VT_BTYPE) == VT_VOID
|| type_size(type, &unused_align) < 0)
tcc_error("declaration of an array of incomplete type elements");
t1 |= type->t & VT_VLA;
if (t1 & VT_VLA) {
if (n < 0)
tcc_error("need explicit inner array size in VLAs");

View File

@ -182,4 +182,20 @@ void * _Alignas(16) p1;
_Static_assert(ONE == 0, "don't show me this");
_Static_assert(ONE == 1, "ONE is not 1");
#elif defined test_void_array
void t[3];
#elif defined test_incomplete_enum_array
enum e t[3];
#elif defined test_incomplete_struct_array
struct s t[3];
#elif defined test_const_fun_array
typedef void f(void);
const f t[3];
#elif defined test_incomplete_array_array
int t[][3];
#endif

View File

@ -86,3 +86,18 @@
[test_static_assert]
60_errors_and_warnings.c:183: error: "ONE is not 1"
[test_void_array]
60_errors_and_warnings.c:186: error: declaration of an array of incomplete type elements
[test_incomplete_enum_array]
60_errors_and_warnings.c:189: error: declaration of an array of incomplete type elements
[test_incomplete_struct_array]
60_errors_and_warnings.c:192: error: declaration of an array of incomplete type elements
[test_const_fun_array]
60_errors_and_warnings.c:196: error: declaration of an array of functions
[test_incomplete_array_array]
60_errors_and_warnings.c:199: error: unknown type size