Apparently, there is an issue with the initialization of union inside struct for some backends (I saw the problem in stm8, z80 and hc08, but not mcs51-small).
An initialization of a union nested in a struct seems to result in initializations for other global variables being wrong.
I'm giving this higher-than-average priority, since bad code is generated silently.
Philipp
Diff:
This bug applies to anonymous unions (stm8).
Last edit: Rajmund Szymański 2017-08-21
It seems practically all backends are affected. So far mcs51 with the small memory model is the only exception I found.
Affected are at least: mcs51 with large or huge memory model, stm8, z80, hc08 and ds390.
Basically only backends that generate iCode for the initialization of global variables (as opposed to using some xinit/initializer/whatever copy mechanism) are not affected.
In [r10206], I added a (disabled) regression test for this bug. If fixing the bug is too hard for 3.6.0, we should at least try to introduce some assertion that catches the issue in SDCC (basically emitting an initalizer that has more bytes than the size of the initialized type), so we no longer genrate bad code silently.
Philipp
It seems by the time the intializer bytes are emitted in printIvalStruct() in SDCCglue.c, the information that there is a union has been lost in case the union is anonymous.
Philipp
Fixed in [r10207].
Philipp
The fix for this bug broke structs where the first member is a zero-width bit-field: [bugs:#3542].
Related
Bugs:
#3542