Skip to content

Commit

Permalink
more ZST fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
simvux committed Dec 1, 2024
1 parent 17d972e commit 9c0d11f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lumina-compiler/src/backend/cranelift/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,12 @@ impl<'a> Structs<'a> {
}

let (_, align) = self.size_and_align_of_field(&struct_.fields[field]);
let end_padding = (align - offset % align) % align;
if align != 0 {
let end_padding = (align - offset % align) % align;
offset += end_padding;
}

ByteOffset(end_padding + offset)
ByteOffset(offset)
}

fn calculate_align_of(&mut self, ty: &MonoType) -> u32 {
Expand Down
1 change: 1 addition & 0 deletions lumina-compiler/src/backend/cranelift/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub fn run(target: Target, dwarf: BinDebugInfo, lir: lir::Output) -> Vec<u8> {
shared_builder.set("opt_level", "speed").unwrap();
shared_builder.enable("preserve_frame_pointers").unwrap();
shared_builder.enable("unwind_info").unwrap();
shared_builder.enable("alias_analysis").unwrap();
let shared_flags = settings::Flags::new(shared_builder);
assert!(shared_flags.unwind_info());

Expand Down
2 changes: 2 additions & 0 deletions lumina-compiler/src/backend/cranelift/ssa/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ impl<'f, 's, 'a> InstHelper<'f, 's, 'a> {
}

Layout::AutoBoxed(ty, ptr) => self.field_of_structptr(ty.as_key(), ptr, field),
// We can't assert here so I really hope we're never accidentally constructing ZST incorrectly
Layout::ZST => VLayout::ZST,
other => panic!("field of non-struct: {other:?}"),
}
}
Expand Down

0 comments on commit 9c0d11f

Please sign in to comment.