From 9c0d11f3ba1cb19d8e7f6e2c3799707c9353f125 Mon Sep 17 00:00:00 2001 From: Simon Larsson Date: Sun, 1 Dec 2024 10:38:14 +0100 Subject: [PATCH] more ZST fixes --- lumina-compiler/src/backend/cranelift/layout.rs | 7 +++++-- lumina-compiler/src/backend/cranelift/mod.rs | 1 + lumina-compiler/src/backend/cranelift/ssa/record.rs | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lumina-compiler/src/backend/cranelift/layout.rs b/lumina-compiler/src/backend/cranelift/layout.rs index 4f4ca7d..83bedea 100644 --- a/lumina-compiler/src/backend/cranelift/layout.rs +++ b/lumina-compiler/src/backend/cranelift/layout.rs @@ -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 { diff --git a/lumina-compiler/src/backend/cranelift/mod.rs b/lumina-compiler/src/backend/cranelift/mod.rs index dbcad96..6ceed3e 100644 --- a/lumina-compiler/src/backend/cranelift/mod.rs +++ b/lumina-compiler/src/backend/cranelift/mod.rs @@ -37,6 +37,7 @@ pub fn run(target: Target, dwarf: BinDebugInfo, lir: lir::Output) -> Vec { 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()); diff --git a/lumina-compiler/src/backend/cranelift/ssa/record.rs b/lumina-compiler/src/backend/cranelift/ssa/record.rs index 89a0213..8ab8343 100644 --- a/lumina-compiler/src/backend/cranelift/ssa/record.rs +++ b/lumina-compiler/src/backend/cranelift/ssa/record.rs @@ -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:?}"), } }