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
47684768 static void decl_initializer(CType *type, Section *sec, unsigned long c,
47694769 int first, int size_only)
47704770 {
4771− int index, array_length, n, no_oblock, nb, parlevel, i;
4771+ int index, array_length, n, no_oblock, nb, parlevel, parlevel1, i;
47724772 int size1, align1, expr_type;
47734773 Sym *s, *f;
47744774 CType *t1;
@@ -4970,13 +4970,17 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 195 unmodified lines
49704970 skip('}');
49714971 } else if (size_only) {
49724972 /* just skip expression */
4973− parlevel = 0;
4974− while ((parlevel > 0 || (tok != '}' && tok != ',')) &&
4975− tok != -1) {
4973+ parlevel = parlevel1 = 0;
4974+ while ((parlevel > 0 || parlevel1 > 0 ||
4975+ (tok != '}' && tok != ',')) && tok != -1) {
49764976 if (tok == '(')
49774977 parlevel++;
49784978 else if (tok == ')')
49794979 parlevel--;
4980+ else if (tok == '{')
4981+ parlevel1++;
4982+ else if (tok == '}')
4983+ parlevel1--;
49804984 next();
49814985 }
49824986 } else {
tests/tcctest.c+26−0
@@ -827,6 +827,27 @@ struct aligntest4 { · 826 unmodified lines
827827 double a[0];
828828 };
829829
830+struct complexinit0 {
831+ int a;
832+ int b;
833+};
834+
835+struct complexinit {
836+ int a;
837+ struct complexinit0 *b;
838+};
839+
840+const 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+
830851 void struct_test()
831852 {
832853 struct1 *s;
@@ -856,6 +877,11 @@ void struct_test() · 23 unmodified lines
856877 printf("st2: %d %d %d\n",
857878 s->f1, s->f2, s->f3);
858879 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);
859885
860886 /* align / size tests */
861887 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