-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fix undefined behavior in Rc/Arc allocation #54922
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
This comment has been minimized.
This comment has been minimized.
r? @RalfJung |
Could you add a comment saying why we do it this way and not the old way? Other than that, I agree the alignment problem is gone. However, I do not know nearly enough about layouts to say if that's a correct way to compute these things. Assigning to someone who knows more (feel free to pick someone else). r? @eddyb |
Ping from triage! This PR requires your review @eddyb. Also this PR was references from rust-lang/unsafe-code-guidelines#35, is it blocked on that issue? |
This is not a compiler layout, but I suspect it's correct. |
Thanks for the PR and sorry for the delay! This looks good to go to me with @RalfJung's comment |
If possible, it'd also be great to have a regression test for this! |
We'll have one in miri. I have no idea how to make one with rustc only. |
Manually calculate allocation layout for `Rc`/`Arc` to avoid undefined behavior
I've added a more detailed comment and the tests have passed. |
@bors: r+ |
📌 Commit d60290f has been approved by |
Fix undefined behavior in Rc/Arc allocation Manually calculate allocation layout for `Rc`/`Arc` to avoid undefined behavior Closes #54908
☀️ Test successful - status-appveyor, status-travis |
Hm, this RFC made miri fail even if validation is turned off. Still investigating. |
The error is that an allocation has size 32 but gets deallocated with size 28. I assume the layout computations done here are incorrect. |
Reported as #55747. |
Manually calculate allocation layout for
Rc
/Arc
to avoid undefined behaviorCloses #54908