History

reject invalid arrays in post_type()

Pascal Cuoq committed 7 years ago

Commit cbbba011 parent 942b73b3 files · +39 −3Browse files

Unified · Split

3 files
  1. tccgen.c +8 −3
  2. tests/tests2/60_errors_and_warnings.c +16 −0
  3. tests/tests2/60_errors_and_warnings.expect +15 −0
tccgen.c+8−3
@@ -4377,7 +4377,7 @@ static int asm_label_instr(void) · 4376 unmodified lines
4377 4377
4378static int post_type(CType *type, AttributeDef *ad, int storage, int td)4378static int post_type(CType *type, AttributeDef *ad, int storage, int td)
4379{4379{
4380 int n, l, t1, arg_size, align;4380 int n, l, t1, arg_size, align, unused_align;
4381 Sym **plast, *s, *first;4381 Sym **plast, *s, *first;
4382 AttributeDef ad1;4382 AttributeDef ad1;
4383 CType pt;4383 CType pt;
@@ -4503,10 +4503,15 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) · 119 unmodified lines
4503 skip(']');4503 skip(']');
4504 /* parse next post type */4504 /* parse next post type */
4505 post_type(type, ad, storage, 0);4505 post_type(type, ad, storage, 0);
4506 if (type->t == VT_FUNC)4506
4507 if ((type->t & VT_BTYPE) == VT_FUNC)
4507 tcc_error("declaration of an array of functions");4508 tcc_error("declaration of an array of functions");
4509 if ((type->t & VT_BTYPE) == VT_VOID
4510 || type_size(type, &unused_align) < 0)
4511 tcc_error("declaration of an array of incomplete type elements");
4512
4508 t1 |= type->t & VT_VLA;4513 t1 |= type->t & VT_VLA;
4509 4514
4510 if (t1 & VT_VLA) {4515 if (t1 & VT_VLA) {
4511 if (n < 0)4516 if (n < 0)
4512 tcc_error("need explicit inner array size in VLAs");4517 tcc_error("need explicit inner array size in VLAs");
tests/tests2/60_errors_and_warnings.c+16−0
@@ -182,4 +182,20 @@ void * _Alignas(16) p1; · 181 unmodified lines
182 _Static_assert(ONE == 0, "don't show me this");182 _Static_assert(ONE == 0, "don't show me this");
183 _Static_assert(ONE == 1, "ONE is not 1");183 _Static_assert(ONE == 1, "ONE is not 1");
184 184
185#elif defined test_void_array
186 void t[3];
187
188#elif defined test_incomplete_enum_array
189 enum e t[3];
190
191#elif defined test_incomplete_struct_array
192 struct s t[3];
193
194#elif defined test_const_fun_array
195 typedef void f(void);
196 const f t[3];
197
198#elif defined test_incomplete_array_array
199 int t[][3];
200
185#endif201#endif
tests/tests2/60_errors_and_warnings.expect+15−0
@@ -86,3 +86,18 @@ · 85 unmodified lines
86 86
87[test_static_assert]87[test_static_assert]
8860_errors_and_warnings.c:183: error: "ONE is not 1"8860_errors_and_warnings.c:183: error: "ONE is not 1"
89
90[test_void_array]
9160_errors_and_warnings.c:186: error: declaration of an array of incomplete type elements
92
93[test_incomplete_enum_array]
9460_errors_and_warnings.c:189: error: declaration of an array of incomplete type elements
95
96[test_incomplete_struct_array]
9760_errors_and_warnings.c:192: error: declaration of an array of incomplete type elements
98
99[test_const_fun_array]
10060_errors_and_warnings.c:196: error: declaration of an array of functions
101
102[test_incomplete_array_array]
10360_errors_and_warnings.c:199: error: unknown type size

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