sanity_check_layout: less rightwards drift
This commit is contained in:
parent
df04d28163
commit
58dd62a756
1 changed files with 269 additions and 266 deletions
|
@ -20,7 +20,11 @@ pub(super) fn sanity_check_layout<'tcx>(
|
||||||
bug!("size is not a multiple of align, in the following layout:\n{layout:#?}");
|
bug!("size is not a multiple of align, in the following layout:\n{layout:#?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg!(debug_assertions) {
|
if !cfg!(debug_assertions) {
|
||||||
|
// Stop here, the rest is kind of expensive.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/// Yields non-ZST fields of the type
|
/// Yields non-ZST fields of the type
|
||||||
fn non_zst_fields<'tcx, 'a>(
|
fn non_zst_fields<'tcx, 'a>(
|
||||||
cx: &'a LayoutCx<'tcx, TyCtxt<'tcx>>,
|
cx: &'a LayoutCx<'tcx, TyCtxt<'tcx>>,
|
||||||
|
@ -115,10 +119,7 @@ pub(super) fn sanity_check_layout<'tcx>(
|
||||||
Size::ZERO,
|
Size::ZERO,
|
||||||
"`Scalar` field at non-0 offset in {inner:#?}",
|
"`Scalar` field at non-0 offset in {inner:#?}",
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(field.size, size, "`Scalar` field with bad size in {inner:#?}",);
|
||||||
field.size, size,
|
|
||||||
"`Scalar` field with bad size in {inner:#?}",
|
|
||||||
);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
field.align.abi, align,
|
field.align.abi, align,
|
||||||
"`Scalar` field with bad align in {inner:#?}",
|
"`Scalar` field with bad align in {inner:#?}",
|
||||||
|
@ -177,10 +178,14 @@ pub(super) fn sanity_check_layout<'tcx>(
|
||||||
}
|
}
|
||||||
let mut fields = non_zst_fields(cx, &inner);
|
let mut fields = non_zst_fields(cx, &inner);
|
||||||
let (offset1, field1) = fields.next().unwrap_or_else(|| {
|
let (offset1, field1) = fields.next().unwrap_or_else(|| {
|
||||||
panic!("`ScalarPair` layout for type with not even one non-ZST field: {inner:#?}")
|
panic!(
|
||||||
|
"`ScalarPair` layout for type with not even one non-ZST field: {inner:#?}"
|
||||||
|
)
|
||||||
});
|
});
|
||||||
let (offset2, field2) = fields.next().unwrap_or_else(|| {
|
let (offset2, field2) = fields.next().unwrap_or_else(|| {
|
||||||
panic!("`ScalarPair` layout for type with less than two non-ZST fields: {inner:#?}")
|
panic!(
|
||||||
|
"`ScalarPair` layout for type with less than two non-ZST fields: {inner:#?}"
|
||||||
|
)
|
||||||
});
|
});
|
||||||
assert!(
|
assert!(
|
||||||
fields.next().is_none(),
|
fields.next().is_none(),
|
||||||
|
@ -279,9 +284,8 @@ pub(super) fn sanity_check_layout<'tcx>(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// The top-level ABI and the ABI of the variants should be coherent.
|
// The top-level ABI and the ABI of the variants should be coherent.
|
||||||
let scalar_coherent = |s1: Scalar, s2: Scalar| {
|
let scalar_coherent =
|
||||||
s1.size(cx) == s2.size(cx) && s1.align(cx) == s2.align(cx)
|
|s1: Scalar, s2: Scalar| s1.size(cx) == s2.size(cx) && s1.align(cx) == s2.align(cx);
|
||||||
};
|
|
||||||
let abi_coherent = match (layout.abi, variant.abi) {
|
let abi_coherent = match (layout.abi, variant.abi) {
|
||||||
(Abi::Scalar(s1), Abi::Scalar(s2)) => scalar_coherent(s1, s2),
|
(Abi::Scalar(s1), Abi::Scalar(s2)) => scalar_coherent(s1, s2),
|
||||||
(Abi::ScalarPair(a1, b1), Abi::ScalarPair(a2, b2)) => {
|
(Abi::ScalarPair(a1, b1), Abi::ScalarPair(a2, b2)) => {
|
||||||
|
@ -299,5 +303,4 @@ pub(super) fn sanity_check_layout<'tcx>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue