Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Issue 22624 - ImportC: struct members in static initializer misal… #13564

Merged
merged 1 commit into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/dmd/todt.d
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ private void membersToDt(AggregateDeclaration ad, ref DtBuilder dtb,
}
}
dtb.checkInitialized();
//printf("+dtb.length: %d\n", dtb.length);

/* Order:
* { base class } or { __vptr, __monitor }
Expand Down Expand Up @@ -863,6 +864,7 @@ private void membersToDt(AggregateDeclaration ad, ref DtBuilder dtb,
{
if (bitOffset)
{
//printf("finishInFlightBitField() offset %d bitOffset %d bitFieldSize %d\n", offset, bitOffset, bitFieldSize);
assert(bitFieldSize);
dtb.nbytes(bitFieldSize, cast(char*)&bitFieldValue);
offset += bitFieldSize;
Expand Down Expand Up @@ -957,7 +959,7 @@ private void membersToDt(AggregateDeclaration ad, ref DtBuilder dtb,
assert(offset <= vd.offset);
if (offset < vd.offset)
dtb.nzeros(vd.offset - offset);
//printf("vd: %s offset: %u, vd.offset: %u\n", vd.toChars(), offset, vd.offset);
//printf("offset: %u, vd: %s vd.offset: %u\n", offset, vd.toChars(), vd.offset);

auto dtbx = DtBuilder(0);
if (elements)
Expand All @@ -979,7 +981,7 @@ private void membersToDt(AggregateDeclaration ad, ref DtBuilder dtb,
else
Expression_toDt(e, dtbx); // convert e to an initializer dt
}
else
else if (!bf)
{
if (Initializer init = vd._init)
{
Expand Down Expand Up @@ -1021,6 +1023,7 @@ private void membersToDt(AggregateDeclaration ad, ref DtBuilder dtb,

if (offset < ad.structsize)
dtb.nzeros(ad.structsize - offset);
//printf("-dtb.length: %d\n", dtb.length);
}


Expand Down
18 changes: 18 additions & 0 deletions test/runnable/fix22624.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// https://issues.dlang.org/show_bug.cgi?id=22624

import core.stdc.stdio;
import imports.imp22624;

struct S
{
B b;
ulong y = 0x1234_0000_5678;
}

int main()
{
S s;
//printf("%llx\n", s.y);
assert(s.y == 0x1234_0000_5678);
return 0;
}
6 changes: 6 additions & 0 deletions test/runnable/imports/imp22624.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

struct B
{
unsigned int x : 1;
// unsigned int x;
};