History

Fix complex static initializers (handle additional '}' and '{' brackets)

- added an example to test suite - the "warning: assignment discards qualifiers from pointer target type" is present but harmless

Jaroslav Kysela committed 15 years ago

Commit dbefae51 parent a3ebdd02 files · +34 −4Browse files

Unified · Split

2 files
  1. tccgen.c +8 −4
  2. tests/tcctest.c +26 −0
tccgen.c+8−4
@@ -4768,7 +4768,7 @@ static void init_putz(CType *t, Section *sec, unsigned long c, int size) · 4767 unmodified lines
4768static void decl_initializer(CType *type, Section *sec, unsigned long c, 4768static void decl_initializer(CType *type, Section *sec, unsigned long c,
4769 int first, int size_only)4769 int first, int size_only)
4770{4770{
4771 int index, array_length, n, no_oblock, nb, parlevel, i;4771 int index, array_length, n, no_oblock, nb, parlevel, parlevel1, i;
4772 int size1, align1, expr_type;4772 int size1, align1, expr_type;
4773 Sym *s, *f;4773 Sym *s, *f;
4774 CType *t1;4774 CType *t1;
@@ -4970,13 +4970,17 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 195 unmodified lines
4970 skip('}');4970 skip('}');
4971 } else if (size_only) {4971 } else if (size_only) {
4972 /* just skip expression */4972 /* just skip expression */
4973 parlevel = 0;4973 parlevel = parlevel1 = 0;
4974 while ((parlevel > 0 || (tok != '}' && tok != ',')) && 4974 while ((parlevel > 0 || parlevel1 > 0 ||
4975 tok != -1) {4975 (tok != '}' && tok != ',')) && tok != -1) {
4976 if (tok == '(')4976 if (tok == '(')
4977 parlevel++;4977 parlevel++;
4978 else if (tok == ')')4978 else if (tok == ')')
4979 parlevel--;4979 parlevel--;
4980 else if (tok == '{')
4981 parlevel1++;
4982 else if (tok == '}')
4983 parlevel1--;
4980 next();4984 next();
4981 }4985 }
4982 } else {4986 } else {
tests/tcctest.c+26−0
@@ -827,6 +827,27 @@ struct aligntest4 { · 826 unmodified lines
827 double a[0];827 double a[0];
828};828};
829 829
830struct complexinit0 {
831 int a;
832 int b;
833};
834
835struct complexinit {
836 int a;
837 struct complexinit0 *b;
838};
839
840const static struct complexinit cix[] = {
841 [0] = {
842 .a = 0xfefa,
843 .b = (const struct complexinit0[]) {
844 { 0x80, 0x81 },
845 { 0x82, 0x83 },
846 {}
847 }
848 }
849};
850
830void struct_test()851void struct_test()
831{852{
832 struct1 *s;853 struct1 *s;
@@ -856,6 +877,11 @@ void struct_test() · 23 unmodified lines
856 printf("st2: %d %d %d\n",877 printf("st2: %d %d %d\n",
857 s->f1, s->f2, s->f3);878 s->f1, s->f2, s->f3);
858 printf("str_addr=%x\n", (int)st1.str - (int)&st1.f1);879 printf("str_addr=%x\n", (int)st1.str - (int)&st1.f1);
880 printf("cix: %d %d %d %d %d %d %d\n",
881 cix[0].a,
882 cix[0].b[0].a, cix[0].b[0].b,
883 cix[0].b[1].a, cix[0].b[1].b,
884 cix[0].b[2].a, cix[0].b[2].b);
859 885
860 /* align / size tests */886 /* align / size tests */
861 printf("aligntest1 sizeof=%d alignof=%d\n",887 printf("aligntest1 sizeof=%d alignof=%d\n",

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