From d0fa661dcc21dac6f1a6942afdb58a16d93c6cf8 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 9 Jan 2025 02:28:52 +0100 Subject: [PATCH] WIP: fix passing small structs on AMD64 This fixes https://github.com/inko-lang/inko/issues/792. --- compiler/src/llvm/context.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/compiler/src/llvm/context.rs b/compiler/src/llvm/context.rs index e3c78d2e..fa53b251 100644 --- a/compiler/src/llvm/context.rs +++ b/compiler/src/llvm/context.rs @@ -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) }