Bug 22624 – ImportC: struct members in static initializer misaligned following bit field
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-12-23T01:17:13Z
Last change time
2022-01-23T09:17:45Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
duser
Comments
Comment #0 by duser — 2021-12-23T01:17:13Z
mod.c:
---
struct cstruct {
unsigned int bit : 1;
};
---
main.d:
---
import std.stdio;
import mod;
struct dstruct
{
cstruct x;
ubyte[8] msg = [1, 2, 3, 4, 5, 6, 7, 8];
}
void main()
{
dstruct v;
writeln(v.msg);
assert(dstruct.init.msg == [1, 2, 3, 4, 5, 6, 7, 8]); // ok
assert(v.msg == [1, 2, 3, 4, 5, 6, 7, 8]); // error
}
---
it should print the array as written in the source, but instead it prints [0, 0, 0, 0, 1, 2, 3, 4]
version: DMD64 D Compiler v2.098.0-361-g415e58e6d (current git master)
Comment #1 by bugzilla — 2022-01-23T05:05:41Z
A simpler test case:
import core.stdc.stdio;
import mod;
struct S
{
cstruct b;
ulong y = 0x1234_0000_5678;
}
void main()
{
S s;
printf("%llx\n", s.y);
}
prints 567800000000
Comment #2 by dlang-bot — 2022-01-23T06:47:36Z
@WalterBright created dlang/dmd pull request #13564 "fix Issue 22624 - ImportC: struct members in static initializer misal…" fixing this issue:
- fix Issue 22624 - ImportC: struct members in static initializer misaligned following bit field
https://github.com/dlang/dmd/pull/13564
Comment #3 by dlang-bot — 2022-01-23T09:17:45Z
dlang/dmd pull request #13564 "fix Issue 22624 - ImportC: struct members in static initializer misal…" was merged into master:
- 687bcb3fd6e51110a469b33161d8f1f4785e9acb by Walter Bright:
fix Issue 22624 - ImportC: struct members in static initializer misaligned following bit field
https://github.com/dlang/dmd/pull/13564