-
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
mem::size_of_val
returns wrong value for DSTs with certain field layouts
#35815
Comments
mem::size_of_val
returns wrong value for DSTs with certain alignmentsmem::size_of_val
returns wrong value for DSTs with certain field layouts
This is probably for drop flags, in which case it should get fixed by #35764 |
Reduced: struct Foo<T: ?Sized> {
a: i64,
b: bool,
c: T,
}
fn main() {
let a: &Foo<i32> = &Foo { a: 1, b: false, c: 2i32 };
println!("{}", std::mem::size_of_val(a));
let a: &Foo<Send> = a;
println!("{}", std::mem::size_of_val(a));
} |
@eddyb where would there be a drop flag here? |
@durka My point isn't that there is, but that the code assumes all trait objects have drop flags. I could be wrong though, it might be a bug in the alignment logic. |
Not fixed by #35764, will have to investigate further. |
Uhhhh, the computation starts with: rustc_trans::glue: DST Foo<std::marker::Send> sizing_type: { i64, i8 }
rustc_trans::glue: DST Foo<std::marker::Send> statically sized prefix size: 16 align: 8 Which is completely wrong, because you want no trailing padding, i.e. EDIT: getting a field pointer might also be broken, needs looking into. |
rustc_trans: don't round up the DST prefix size to its alignment. Fixes #35815 by using `ty::layout` and `min_size` to compute the size of the DST prefix. `ty::layout::Struct::min_size` is not rounded up to alignment, which could be smaller for the DST field.
On stable, beta, and nightly, the follow code prints
16
followed by24
:CC #27023
The text was updated successfully, but these errors were encountered: