Bug 21969 – importC: Error: bit fields are not supported
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-05-25T14:31:11Z
Last change time
2021-09-02T00:59:46Z
Keywords
ImportC, pull, rejects-valid
Assigned to
No Owner
Creator
Iain Buclaw
Comments
Comment #0 by ibuclaw — 2021-05-25T14:31:11Z
Bitfields can be supported by merging and replacing them with a representative field - ignoring any field name of the bitfield.
---
struct bitfieldsA
{
int start;
unsigned codes : 11;
int end;
};
struct bitfieldsB
{
int start;
unsigned codes : 11;
unsigned reserved : 5;
unsigned flags : 16;
int end;
};
struct bitfieldsC
{
int start;
unsigned codes : 11;
unsigned reserved : 5;
unsigned : 0;
unsigned flags : 16;
int end;
};
---
The above can be translated into the following D representation without compromising ABI.
---
struct bitfieldsA
{
int start;
ushort __bitfield_padding_0;
int end;
}
struct bitfieldsB
{
int start;
uint __bitfield_padding_0;
int end;
}
struct bitfieldsC
{
int start;
ushort __bitfield_padding_0;
ushort __bitfield_padding_1;
int end;
}
---
As per the specification:
C99 6.7.2.1-11:
An implementation may allocate any addressable storage unit large enough to hold a bit-field. If enough space remains, a bit-field that immediately follows another bit-field in a structure shall be packed into adjacent bits of the same unit. If insufficient space remains,whether a bit-field that does not fit is put into the next unit or overlaps adjacent units is implementation-defined.
C99 6.7.2.1-12:
A bit-field declaration with no declarator, but only a colon and a width, indicates an unnamed bit-field. As a special case, a bit-field structure member with a width of 0 indicates that no further bit-field is to be packed into the unit in which the previous bit-field, if any, was placed.
Comment #1 by ibuclaw — 2021-05-25T16:07:35Z
(In reply to Iain Buclaw from comment #0)
> The above can be translated into the following D representation without
> compromising ABI.
> ---
> struct bitfieldsA
> {
> int start;
> ushort __bitfield_padding_0;
> int end;
> }
>
If we need to expose the original names of the bit-fields, then @property functions and bitmasks will also suffice.
Comment #2 by dlang-bot — 2021-06-21T15:14:18Z
@ibuclaw created dlang/dmd pull request #12722 "importC: Implement C99 bit-fields - front-end semantic only" mentioning this issue:
- partial fix Issue 21969 - importC: Error: bit fields are not supported
https://github.com/dlang/dmd/pull/12722
Comment #3 by dlang-bot — 2021-08-30T13:21:32Z
@ibuclaw created dlang/dmd pull request #13033 "fix Issue 21969 - importC: Error: bit fields are not supported" fixing this issue:
- fix Issue 21969 - importC: Error: bit fields are not supported
https://github.com/dlang/dmd/pull/13033
Comment #4 by dlang-bot — 2021-08-30T22:41:57Z
dlang/dmd pull request #13033 "fix Issue 21969 - importC: Error: bit fields are not supported" was merged into master:
- 580a16b91ca1a7dee3d2aa66fd7b11da73b507b5 by Iain Buclaw:
fix Issue 21969 - importC: Error: bit fields are not supported
https://github.com/dlang/dmd/pull/13033
Comment #5 by dlang-bot — 2021-09-02T00:59:46Z
dlang/dmd pull request #13037 "[stable] Cherry-pick bit-field fixes from master" was merged into stable:
- 497464b45bd972426685a33606922dbef3216a52 by Iain Buclaw:
fix Issue 21969 - importC: Error: bit fields are not supported
https://github.com/dlang/dmd/pull/13037