Skip to content

Instantly share code, notes, and snippets.

@cbecerescu cbecerescu/bitfields_bug.mkd Secret
Created Nov 25, 2019

Embed
What would you like to do?

The following C struct declaration

struct Bad {
    int a : 1;
    int b : 1;
    struct C *ptr; // C is undeclared
}

would be translated in D to

struct Bad
{
    import std.bitmanip: bitfields;

    align(4);
    mixin(bitfields!(
        int, "a", 1,
        int, "b", 1,
        uint, "_padding_0", 6
    ));
        uint, "_padding_1", 8
    ));
    C* ptr;
}

The issue is that the bitfields final padding would be added twice:

  • for the StructDecl type (we handle bitfields before the skipMember check is done)
  • for the actual FieldDecl type

This issue doesn't occur when C is a pre-declared struct, as we will only have a FieldDecl for that line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.