-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Merged by Bors] - Respect alignment for zero-sized types stored in the world #6618
Conversation
Just so I understand the context more: why would you want to mess with the alignment of ZSTs? Definitely agree that this is needed, but I'm trying to piece this together better. |
I'm not aware of any actual use cases for this kind of alignment fiddling. This PR is about correctness more than anything -- I would be surprised if this issue caused any problems in practice. |
Merging: either we make a 0.9.1 release and it's in there, or we don't and there's no harm done by merging early. bors r+ |
# Objective Fixes #6615. `BlobVec` does not respect alignment for zero-sized types, which results in UB whenever a ZST with alignment other than 1 is used in the world. ## Solution Add the fn `bevy_ptr::dangling_with_align`. --- ## Changelog + Added the function `dangling_with_align` to `bevy_ptr`, which creates a well-aligned dangling pointer to a type whose alignment is not known at compile time.
# Objective Fixes #6615. `BlobVec` does not respect alignment for zero-sized types, which results in UB whenever a ZST with alignment other than 1 is used in the world. ## Solution Add the fn `bevy_ptr::dangling_with_align`. --- ## Changelog + Added the function `dangling_with_align` to `bevy_ptr`, which creates a well-aligned dangling pointer to a type whose alignment is not known at compile time.
…e#6618) # Objective Fixes bevyengine#6615. `BlobVec` does not respect alignment for zero-sized types, which results in UB whenever a ZST with alignment other than 1 is used in the world. ## Solution Add the fn `bevy_ptr::dangling_with_align`. --- ## Changelog + Added the function `dangling_with_align` to `bevy_ptr`, which creates a well-aligned dangling pointer to a type whose alignment is not known at compile time.
So apparently this actually can matter in practice: https://doc.rust-lang.org/reference/type-layout.html According to this, |
Objective
Fixes #6615.
BlobVec
does not respect alignment for zero-sized types, which results in UB whenever a ZST with alignment other than 1 is used in the world.Solution
Add the fn
bevy_ptr::dangling_with_align
.Changelog
dangling_with_align
tobevy_ptr
, which creates a well-aligned dangling pointer to a type whose alignment is not known at compile time.