Skip to content

[clang][RecordLayoutBuilder] Inconsistent packing of _BitInt bit-fields with the same underlying size #161511

@KennethHilmersson

Description

@KennethHilmersson

Due to an overflow in
unsigned char LastBitfieldStorageUnitSize;
in ItaniumRecordLayoutBuilder there could be wrong packing of ms-bitfields.
When the storage size 256 is stored in LastBitfieldStorageUnitSize this will be zero and a new type is opened for storage of the next field.

godbolt

Code:

#pragma ms_struct on

// Error! struct a will be layout in two i256
// Due to an overflow in
// unsigned char LastBitfieldStorageUnitSize;
// in ItaniumRecordLayoutBuilder
// when storage size 256 is assigned -> zero.
// f3 will be packed in a new i256:
struct { _BitInt(250) f2 : 2;  _BitInt(250) f3 : 2; } __attribute__((packed, aligned(1))) a;

// Ok! f2 and f3 are packed in the same type:
struct { _BitInt(192) f2 : 2;  _BitInt(192) f3 : 2; } __attribute__((packed, aligned(1))) b;

// Ok! f2 and f3 are packed in the same type:
struct { _BitInt(128) f2 : 64;  _BitInt(128) f3 : 64; } __attribute__((packed, aligned(1))) c;

Command line args:

 -Xclang -fms-extensions -Xclang -fdump-record-layouts 

Metadata

Metadata

Assignees

No one assigned

    Labels

    ABIApplication Binary InterfaceclangClang issues not falling into any other categoryconfirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions