Skip to content

Commit

Permalink
WIP: fix passing small structs on AMD64
Browse files Browse the repository at this point in the history
This fixes #792.
  • Loading branch information
yorickpeterse committed Jan 9, 2025
1 parent 71a9d23 commit d0fa661
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion compiler/src/llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,20 @@ impl Context {
// To avoid the complexity of that we take the same approach
// as Rust: if the struct is larger than 8 bytes, we turn it
// into two 64 bits values.
ArgumentType::Regular(self.two_words().as_basic_type_enum())
let align = layouts.target_data.get_abi_alignment(&typ);
let rest = max(bytes - 8, align);
let a = self.i64_type().into();
let b = self.custom_int(size_in_bits(rest)).into();

// TODO: remove
println!(
"{} (align: {}) = struct {{ {}, {} }}",
typ, align, a, b
);

ArgumentType::Regular(
self.struct_type(&[a, b]).as_basic_type_enum(),
)
} else {
ArgumentType::StructValue(typ)
}
Expand Down

0 comments on commit d0fa661

Please sign in to comment.