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

Use align_offset to check alignment #176

Merged
merged 1 commit into from Sep 5, 2023

Conversation

sarah-ek
Copy link
Contributor

check for alignment using (ptr as *const ()).align_offset(align) == 0
This is in a way better than ptr as usize % align == 0, because casting a pointer to an integer has the side effect that it exposes the pointer's provenance, which may theoretically inhibit some compiler optimizations.

@Lokathor
Copy link
Owner

Since this method isn't available in 1.34 we'd have to put the change behind a feature gate.

But also, a compiler "should" be able to see that even the integer form of the pointer doesn't escape and so I would hope that the cast does not hurt optimizations in practice.

@Lokathor
Copy link
Owner

Lokathor commented Sep 5, 2023

I want the basics of the PR, but since sarah hasn't replied i'll just accept it as-is and fix it up with a new feature.

@Lokathor Lokathor merged commit caff759 into Lokathor:main Sep 5, 2023
@Lokathor Lokathor added the semver-minor semver minor change label Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor semver minor change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants