Bug 22710 – CTFE on bitfields does not account for field width

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-01-28T19:15:55Z
Last change time
2022-01-31T13:15:47Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
moonlightsentinel

Comments

Comment #0 by moonlightsentinel — 2022-01-28T19:15:55Z
The CTFE engine ins't aware of the subtle differences of bitfields vs normal variables. This manifests e.g. in incorrect overflow behaviour: --- app.d import bitfields; extern(C) int main() { HasBitfield bf; bf.a += 4; assert(bf.a == 0); // Fails during CTFE assert(bf.b == 0); return 0; } enum test = main(); --- bitfields.c struct HasBitfield { int a : 2; int b : 2; };
Comment #1 by dlang-bot — 2022-01-31T09:40:20Z
@WalterBright created dlang/dmd pull request #13591 "fix Issue 22710 - CTFE on bitfields does not account for field width" fixing this issue: - fix Issue 22710 - CTFE on bitfields does not account for field width https://github.com/dlang/dmd/pull/13591
Comment #2 by dlang-bot — 2022-01-31T13:15:47Z
dlang/dmd pull request #13591 "fix Issue 22710 - CTFE on bitfields does not account for field width" was merged into master: - 22b5617b852ab209b250ffc22a520c41e0ae8509 by Walter Bright: fix Issue 22710 - CTFE on bitfields does not account for field width https://github.com/dlang/dmd/pull/13591