Skip to content

Commit

Permalink
Reorder to keep duplicate checks in sync.
Browse files Browse the repository at this point in the history
  • Loading branch information
luqmana committed May 5, 2023
1 parent 012f9a3 commit 8e7714d
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions compiler/rustc_abi/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,20 +744,28 @@ pub trait LayoutCalculator {
for field in only_variant {
assert!(field.0.is_sized());

if !field.0.is_zst() && !common_non_zst_abi_and_align.is_err() {
align = align.max(field.align());
size = cmp::max(size, field.size());

if field.0.is_zst() {
// Nothing more to do for ZST fields
continue;
}

if let Ok(common) = common_non_zst_abi_and_align {
// Discard valid range information and allow undef
let field_abi = field.abi().to_union();

if let Ok(Some((common_abi, common_align))) = &mut common_non_zst_abi_and_align {
if *common_abi != field_abi {
if let Some((common_abi, common_align)) = common {
if common_abi != field_abi {
// Different fields have different ABI: disable opt
common_non_zst_abi_and_align = Err(AbiMismatch);
} else {
// Fields with the same non-Aggregate ABI should also
// have the same alignment
if !matches!(common_abi, Abi::Aggregate { .. }) {
assert_eq!(
*common_align,
common_align,
field.align().abi,
"non-Aggregate field with matching ABI but differing alignment"
);
Expand All @@ -768,9 +776,6 @@ pub trait LayoutCalculator {
common_non_zst_abi_and_align = Ok(Some((field_abi, field.align().abi)));
}
}

align = align.max(field.align());
size = cmp::max(size, field.size());
}

if let Some(pack) = repr.pack {
Expand Down

0 comments on commit 8e7714d

Please sign in to comment.