Menu

#2840 Initialization of bit field in anonymous union broken

closed-fixed
None
Front-end
5
17 hours ago
2018-11-24
No

Problem:

The following code generates incorrect assembly code for bug1 & bug2 (even field f corrupted).
reproducable for at least mcs51/stm8/z80.
(may related to [#2643] too)

SDCC Version

SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/TININative/ds400/hc08/s08/stm8 3.8.3 #10674 (Mac OS X x86_64)

Source to reproduce

#include <stdint.h>

struct SS
{
    uint8_t a;
    union {
        uint8_t b;
        struct {
            uint8_t c : 2;
            uint8_t d : 3;
            uint8_t e : 3;
        };
    };
    uint8_t f;
};

const struct SS ok = {
    1,
    2,
    3
};

const struct SS bug1 = {
    .a = 1,
    .b = 2,
    .f = 3,
};
const struct SS bug2 = {
    .a = 1,
    .c = 2,
    .d = 3,
    .e = 4,
    .f = 5,
};

Related

Bugs: #2643
Patches: #506

Discussion

  • Maarten Brock

    Maarten Brock - 2026-07-29
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,7 +1,7 @@
     # Problem:
     The following code generates incorrect assembly code for bug1 &amp; bug2 (even field f corrupted).
     reproducable for at least mcs51/stm8/z80.
    -(may related to #2643 too)
    +(may related to [#2643] too)
     # SDCC Version
     SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/TININative/ds400/hc08/s08/stm8 3.8.3 #10674 (Mac OS X x86_64)
    
     

    Related

    Bugs: #2643

  • Maarten Brock

    Maarten Brock - 17 hours ago
    • status: open --> closed-fixed
    • assigned_to: Benedikt Freisen
     
  • Maarten Brock

    Maarten Brock - 17 hours ago

    This should now be fixed by [pathes:#508] applied in [r16762].

     

    Related

    Commit: [r16762]


Log in to post a comment.