Skip to content

align_to and align_to_mut contract and harnesses #405

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

AlexLB99
Copy link

@AlexLB99 AlexLB99 commented Jul 2, 2025

Towards solving #19

This PR adds harnesses and contracts for align_to() and align_to_mut(). For the contract for align_to_mut(), we're using a wrapper and writing a contract for that instead, due to model-checking/kani#3764.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@AlexLB99 AlexLB99 requested a review from a team as a code owner July 2, 2025 16:01
@tautschnig
Copy link
Member

Thank you! We should have a fix for the Kani issue with model-checking/kani#4151 really soon, so I'd love to hold off on this one for about a week so that we can get the Kani fix merged and have this repository use the updated Kani version.

@tautschnig tautschnig self-assigned this Jul 3, 2025
((middle.as_ptr()).add(middle.len()) as *const u8 == suffix.as_ptr() as *const u8) &&
((suffix.as_ptr()).add(suffix.len()) == (self.as_ptr()).add(self.len())) )
)
)]

Choose a reason for hiding this comment

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

I don't see in the ensures clauses the condition that the middle part is correctly aligned.

Copy link
Author

Choose a reason for hiding this comment

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

Actually, this is something I was wondering about -- my impression was that because it's UB to create a misaligned reference, it would be redundant to have a check for the middle part being aligned (since if it isn't, there would already be UB by the time the ensures clause is checked, meaning the check would either return true or something potentially invalid due to previous UB). But of course it's possible that Kani might have some way to circumvent this problem that I'm not familiar with (otherwise the only way I can think of would be to write this check as an assert inside the body of align_to, right before where there could potentially be UB). Would be happy to hear your thoughts on this whenever you have a chance!

((middle.as_ptr()).add(middle.len()) as *const u8 == suffix.as_ptr() as *const u8) &&
((suffix.as_ptr()).add(suffix.len()) == (self.as_ptr()).add(self.len())) )
)
)]

Choose a reason for hiding this comment

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

I don't see in the ensures clauses the condition that the middle part is correctly aligned.

@tautschnig
Copy link
Member

Thank you! We should have a fix for the Kani issue with model-checking/kani#4151 really soon, so I'd love to hold off on this one for about a week so that we can get the Kani fix merged and have this repository use the updated Kani version.

@AlexLB99 We now have the Kani fix merged and the version of Kani that this repository uses includes this fix. Could you please adjust your implementation so as not to use a workaround anymore?

@tautschnig tautschnig assigned AlexLB99 and unassigned tautschnig Jul 10, 2025
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