Skip to content

Use aligned memcpy for struct assignment - #5292

Draft
thewilsonator wants to merge 1 commit into
ldc-developers:masterfrom
thewilsonator:struct-memalign-2
Draft

thewilsonator wants to merge 1 commit into
ldc-developers:masterfrom
thewilsonator:struct-memalign-2

Conversation

@thewilsonator

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread gen/llvmhelpers.cpp
if (src != dst) {
unsigned align = DtoAlignment(lhs->type);
DtoMemCpy(DtoType(lhs->type), dst, src, false,
align ? align : 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add a DtoMemCpy() overload taking both alignments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem here (see failing CI) is that the call gIR->ir->CreateMemCpy(dst, A, src, A, nbytes, false /*isVolatile*/); (where A is an alignment generated from the argument to DtoMemCpy) actually needs to derive the alignment from src/dst (which I presume are going to be alloca's?) through the Align/MaybeAlign.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming the rhs is always of the same (non-)qualified type as the lhs, we wouldn't need the separate alignments. Unless we really have assignments to/from under-aligned structs in the frontend, triggering this error, then we can't simply use the type alignments.

which I presume are going to be alloca's?

No, they can be anything.

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.

2 participants