-
-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Assertion failure when a struct contains a struct which contains bit fields spanning [17, 25) or [33, 57) bits. #4646
Comments
Thx for the report. Converted to D, compilable via struct BitField {
uint _0 : 1;
uint _1 : 1;
uint _2 : 1;
uint _3 : 1;
uint _4 : 1;
uint _5 : 1;
uint _6 : 1;
uint _7 : 1;
uint _8 : 1;
uint _9 : 1;
uint _10 : 1;
uint _11 : 1;
uint _12 : 1;
uint _13 : 1;
uint _14 : 1;
uint _15 : 1;
uint _16 : 1;
}
struct Foo {
BitField bf;
}
pragma(msg, BitField.sizeof, ", ", BitField.alignof); // 4, 4
pragma(msg, Foo.sizeof, ", ", Foo.alignof); // 4, 4 Compiling via
so that LLVM is indeed free to add some implicit padding. There might be a missing assertion checking the final aggregate size (IR vs. AST) too, catching this shouldn't require using the type as field of another aggregate. |
Oh wait, the type-alloc size of a packed |
A quick test case:
In a C file, define
BitFlags
like:or like:
then define a struct which contains
BitFlags
, e.g.The following failure will occur upon compilation:
As far as I can tell, this is the cause:
Within the context of a call to
IrTypeStruct::get
for theBitFlags
struct, inAggrTypeBuilder::addAggregate
when the bitfield-grouping'sgroup.sizeInBytes
(and thus the actual field'ssize
) is 3, 5, 6, or 7 the LLVM type for that bitfield-grouping ends up beingi24
,i40
,i48
, ori56
.Then, because
sd->structsize
is 4 or 8,AggrTypeBuilder::addTailPadding
ends up adding some bytes of padding after the bitfield's non-power-of-two-sized integer.But as
i24
has same ABI alignment asi32
, andi40
,i48
,i56
the same asi64
, they have their own implicit padding from LLVM's data-layout, so the tail-padding added by LDC ends up making theBitFlags
struct bigger than it should be.The text was updated successfully, but these errors were encountered: