-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Deref coercion &Box<[T]>
-> &[T]
can be translated incorrectly
#30478
Comments
cc @dotdash |
@petrochenkov I can't reproduce the segfault with that change on a current master. Do you know how far back I need to go? |
@petrochenkov Ah, great, fails for me on a 32bit build as well. |
Relevant fragments of valgrind report:
|
This is caused by a bad call to a |
`auto_ref()` currently returns an Rvalue datum for the ref'd value, which is fine for thin pointers, but for fat pointers this means that once the pointer is moved out of that datum, its memory will be marked as dead. And because there is not necessarily an intermediate temporary involved we can end up marking memory as dead that is actually still used. As I don't want to break the micro-optimization for thin pointers by always returning an Lvalue datum, I decided to only do so for fat pointers. Fix rust-lang#30478
`auto_ref()` currently returns an Rvalue datum for the ref'd value, which is fine for thin pointers, but for fat pointers this means that once the pointer is moved out of that datum, its memory will be marked as dead. And because there is not necessarily an intermediate temporary involved we can end up marking memory as dead that is actually still used. As I don't want to break the micro-optimization for thin pointers by always returning an Lvalue datum, I decided to only do so for fat pointers. Fix #30478
@petrochenkov probably in stage0? That's built with the snapshot compiler which doesn't have the fix yet. I tried it out by building stage 0 with the fix but without the change to libsyntax, and once it got past libsyntax, I made the change to it so stage1 and stage2 were built with it, and both succeeded. |
@petrochenkov well, the segfault happens in stage1 building libcore, but I guess you get what I meant. |
@dotdash |
I wasn't able to come up with a minimal example yet, but this was the reason of segfault in #30095
Here's a patch fixing that segfault on 32 bit Linux - petrochenkov@b225678
I.e. segfaults disappear when the deref coercion is not used.
Update: Segfault reproduces on https://github.com/rust-lang/rust/tree/master if
impl<T> Deref for P<[T]>
is modified to use coercion (fn deref(&self) -> &[T] { &self.ptr }
).The text was updated successfully, but these errors were encountered: