#33 CIL union bug

Bug
closed-fixed
nobody
8
2006-04-06
2006-03-21
eertbrud
No

Consider following type:

typedef struct tTimNetAddr
{
tBoolean isIPv4;
union
{
tIpAddr addr;
tIp6Addr addr6;
} u;
} tTimNetAddr;

CIL mistakenly does following transformation, which
fails to compile because the required .addr6 is not in
the transformed code:

tTimNetAddr isisPolChangePrefixV6 = {
.isIPv4 = FALSE,
.u = {
.addr6 = {
.__u6_addr = {
.__u6_addr8 = {
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
},
},
},
},
};

to

struct tTimNetAddr isisPolChangePrefixV6 =
{(unsigned char)0, {{{.__u6_addr8 = {(unsigned
char)255, (unsigned char)255, (unsigned char)255,
(unsigned
char)255, (unsigned char)255, (unsigned char)255,
(unsigned
char)255, (unsigned char)255, (unsigned char)255,
(unsigned
char)255, (unsigned char)255, (unsigned char)255,
(unsigned
char)255, (unsigned char)255, (unsigned char)255,
(unsigned
char)255}}}}};

Discussion

  • eertbrud

    eertbrud - 2006-03-22
    • priority: 5 --> 8
     
  • eertbrud

    eertbrud - 2006-03-22

    Logged In: YES
    user_id=1448966

    Also a problem with initialisation:
    Consider following struct defs:
    typedef struct
    {
    int b;
    } str2;
    typedef struct
    {
    int c;
    int d;
    } str4;
    typedef struct
    {
    int a;
    union
    {
    str2 m1;
    str4 m2;
    } u;
    } str3;

    CIL does following translation, leaving the str3
    incompletely initialised, and resulting in unpredictable
    behavior:

    int main(void)
    {
    str3 z = {0};
    }

    to

    int main(void)
    {
    str3 z ;

    {
    #line 47
    z.a = 0;
    #line 47
    z.u.m1.b = 0;
    }}

     
  • Matt Harren

    Matt Harren - 2006-04-06
     
  • Matt Harren

    Matt Harren - 2006-04-06

    Logged In: YES
    user_id=1278428

    Patch attached for the first problem. This was one of those
    silly bugs ... we got an if condition backwards, and printed
    the field name only when it *wasn't* needed.

    The second example looks fine to me. You can see CIL
    initializing z.a and z.u.m1 to zero. What behavior did you
    expect? It's true that z.u.m2.d is uninitialized, but I'm
    not sure whether the specs require it to be initialized in
    this case.

     
  • Matt Harren

    Matt Harren - 2006-04-06
    • status: open --> closed-fixed
     

Log in to post a comment.