Skip to content

Make sure that the future fragment's storage pointer is properly aligned #39821

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

Conversation

aschwaighofer
Copy link
Contributor

No description provided.

return reinterpret_cast<OpaqueValue *>(
reinterpret_cast<char *>(this) + storageOffset(resultType));
reinterpret_cast<char *>(startAddrVal));
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. Normally this would be problematic because of the potential mismatch between an abstract offset calculation and an adjustment on an actual pointer. I guess this particular example might be fine because the overall allocation is known to be aligned at least as well as alignment, so in (mod K) arithmetic we get the same result? Is that true? If so, it's at least worth a comment.

Copy link
Contributor Author

@aschwaighofer aschwaighofer Oct 20, 2021

Choose a reason for hiding this comment

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

That is a good question. I had assume when writing this that we would be just calling swift_alloc which would have been ‘max alignment’ aligned. Reading this code: https://github.com/apple/swift/blob/1ab88ed090aadaceb295c22abd503b5d85017fd0/stdlib/public/Concurrency/Task.cpp#L534 I am not sure. There is a call to plain malloc which on Linux I don’t know what it returns. And there is that pointer that we get from some preallocated buffer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, if we're allocating tasks with just malloc, we might need to adjust that. We can do that in a separate PR, though.

@rjmccall
Copy link
Contributor

I'm taking this over as #39829. I'll throw up a 5.5 PR as well.

@rjmccall rjmccall closed this Oct 20, 2021
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