Skip to content

Carry the D type alignment on struct init memset - #5290

Open
thewilsonator wants to merge 2 commits into
ldc-developers:masterfrom
thewilsonator:struct-memset-align
Open

thewilsonator wants to merge 2 commits into
ldc-developers:masterfrom
thewilsonator:struct-memset-align

Conversation

@thewilsonator

Copy link
Copy Markdown
Contributor

Fission of #5279 to see what causes the problems with it

@thewilsonator
thewilsonator marked this pull request as ready for review September 11, 2026 05:27
@kinke

kinke commented Sep 16, 2026

Copy link
Copy Markdown
Member

I think this is pretty safe, as runtime-initializing an under-aligned variable seems exotic, e.g., align(1) MyStruct s; on the stack etc.

I'd strongly suggest a DtoMemSetZero() overload taking a frontend Type* though, to derive the alignment there, once.

@JohanEngelen

Copy link
Copy Markdown
Member

I think this is pretty safe, as runtime-initializing an under-aligned variable seems exotic, e.g., align(1) MyStruct s; on the stack etc.

But if we now start to miscompile such code, we should error on code like that. Otherwise it may lead to very hard to track down bugs.

Full example:

struct S { int a; }  // implicit align(4)

void foo() {
    bool b;
    align(1) S s; // miscompiled with this PR because the _type's_ alignment is used, not the variable's alignment.
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants