hi,
tcc stores the items that follow a chained designator in the wrong place:
struct { struct { int a, b; } x[3]; } y[] = { [1].x[0].b = 5, 6, 7 };
printf("%zu: %d %d %d %d\n", sizeof y/sizeof *y,
y[1].x[0].a, y[1].x[0].b, y[1].x[1].a, y[1].x[1].b);
gcc 13.3 prints "2: 0 5 6 7", tcc (mob 32d1c0a5) prints "3: 0 5 0 0". after
[1].x[0].b the next item should go to x[1].a (6.7.9p17-20), but decl_designator
walks the whole chain and returns to the outermost array, so 6 and 7 land in
y[2].
the fix makes decl_designator handle only the first designator of a chain and
hand the rest to decl_initializer as an elided sub-list, which already fills an
aggregate and then returns to the parent. an elided list now also ends when a
designator follows, so "{ [1].x[0].b = 5, [0].x[1].a = 1 }" works (it was an
"array type expected" error). a small DIF_DIRTY flag keeps the duplicate
initialization handling (relocation removal, zero stores) working in the nested
list.
tests: new tests/tests2/152_designator_chain.c, expected output is gcc's. it
fails without the fix and passes with it. make test on aarch64 and x86_64
passes before and after.
i pushed it to mob as 2d3eea20:
https://repo.or.cz/tinycc.git/commit/2d3eea20
review welcome, happy to change it.
konstantin
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel