Menu

#2840 Initialization of bit field in anonymous union broken

open
nobody
None
Front-end
5
2018-11-24
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,
};

Discussion


Log in to post a comment.

MongoDB Logo MongoDB