Howard M. Harte - 2026-08-02

This one looks fixed by patches/508. The reproducer from the report:

struct s {
    union {
        int a;
        int b;
    };
    int c;
    int d;
};

struct s s2 = { .a = 0, .c = 3, .d = 4 };

compiled to assembly against [r16747] and against [r16747] plus that patch set:

port    r16747                              with patches/508
z80     warning 147 x2, data 0000 0000 0003  no warning, data 0000 0003 0004
stm8    same                                 correct
hc08    same                                 correct
s08     same                                 correct
mcs51   correct already                      correct

The two warnings are the visible symptom; the data is the reason it matters. c was taking the initializer meant for the member after it and d's 4 was dropped as excess, so s2 came out {0, 0, 3} instead of {0, 3, 4}.

What made it survive this long is probably that it never showed on mcs51: the defect is in the copy path (printIvalStruct()), and mcs51 initializes globals with generated stores instead, which was already correct. Everything that emits an initializer image - z80, stm8, hc08, s08 - got the wrong bytes.

The patch that does it is 0005 of the set, an initializer after a designated one belongs to the member following it (C11 6.7.9p17), and the walk must not undo the designated alternative. It carries bug-3393-designated.c, which covers the designator shapes but not this exact one; happy to add the reproducer from this report to that test if you would like it recorded.

 

Related

Commit: [r16747]


Last edit: Howard M. Harte 2026-08-02