History

tccgen.c: Fix flex array members some more

Last fix didn't work for function f1int in the added testcase.

Michael Matz committed 10 years ago

Commit ceccd3e1 parent 7e0ad4f3 files · +31 −2Browse files

Unified · Split

3 files
  1. tccgen.c +6 −2
  2. tests/tests2/80_flexarray.c +25 −0
  3. tests/tests2/80_flexarray.expect +0 −0
tccgen.c+6−2
@@ -5846,8 +5846,12 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 5845 unmodified lines
5846 if (size < 0) 5846 if (size < 0)
5847 tcc_error("unknown type size");5847 tcc_error("unknown type size");
5848 }5848 }
5849 if (flexible_array)5849 /* If there's a flex member and it was used in the initializer
5850 size += flexible_array->type.ref->c * pointed_size(&flexible_array->type) + 1;5850 adjust size. */
5851 if (flexible_array &&
5852 flexible_array->type.ref->c > 0)
5853 size += flexible_array->type.ref->c
5854 * pointed_size(&flexible_array->type);
5851 /* take into account specified alignment if bigger */5855 /* take into account specified alignment if bigger */
5852 if (ad->a.aligned) {5856 if (ad->a.aligned) {
5853 if (ad->a.aligned > align)5857 if (ad->a.aligned > align)
tests/tests2/80_flexarray.c+25−0
@@ -0,0 +1,25 @@
1#include <stdio.h>
2struct wchar {
3 char *data; char mem[];
4};
5struct wint {
6 char *data; int mem[];
7};
8int f1char (void) {
9 char s[9]="nonono";
10 struct wchar q = {"bugs"};
11 return !s[0];
12}
13int f1int (void) {
14 char s[9]="nonono";
15 struct wint q = {"bugs"};
16 return !s[0];
17}
18int main (void) {
19 char s[9]="nonono";
20 static struct wchar q = {"bugs", {'c'}};
21 //printf ("tcc has %s %s\n", s, q.data);
22 if (f1char() || f1int())
23 printf ("bla\n");
24 return !s[0];
25}
tests/tests2/80_flexarray.expect+0−0

Empty file added.