From 6ddb65d52914820342ea8b5f217287b662d568b0 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sat, 7 Dec 2024 02:02:00 -0500 Subject: [PATCH 1/2] Fix pass by reference for compare fn https://roc.zulipchat.com/#narrow/channel/463736-bugs/topic/LLVM.20IR.20output.20in.20compiler.20crash.20during.20AOC! --- crates/compiler/gen_llvm/src/llvm/bitcode.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/compiler/gen_llvm/src/llvm/bitcode.rs b/crates/compiler/gen_llvm/src/llvm/bitcode.rs index b040699f7d..9e8c57921a 100644 --- a/crates/compiler/gen_llvm/src/llvm/bitcode.rs +++ b/crates/compiler/gen_llvm/src/llvm/bitcode.rs @@ -12,8 +12,8 @@ use crate::llvm::refcounting::{ use inkwell::attributes::{Attribute, AttributeLoc}; use inkwell::types::{BasicType, BasicTypeEnum, StructType}; use inkwell::values::{ - BasicValue, BasicValueEnum, CallSiteValue, FunctionValue, InstructionValue, IntValue, - PointerValue, StructValue, + BasicMetadataValueEnum, BasicValue, BasicValueEnum, CallSiteValue, FunctionValue, + InstructionValue, IntValue, PointerValue, StructValue, }; use inkwell::AddressSpace; use roc_error_macros::internal_error; @@ -726,13 +726,18 @@ pub fn build_compare_wrapper<'a, 'ctx>( "load_opaque", ); - let closure_data = - env.builder - .new_build_load(closure_type, closure_cast, "load_opaque"); + let closure_data: BasicMetadataValueEnum = + if layout_interner.is_passed_by_reference(closure_data_repr) { + closure_cast.into() + } else { + env.builder + .new_build_load(closure_type, closure_cast, "load_opaque") + .into() + }; env.arena .alloc([value1.into(), value2.into(), closure_data.into()]) - as &[_] + as &[BasicMetadataValueEnum] } }; From f6f2830bac45f5184fbc8c01cecdf24cba26caeb Mon Sep 17 00:00:00 2001 From: Luke Boswell Date: Sat, 7 Dec 2024 20:36:31 +1100 Subject: [PATCH 2/2] clippy --- crates/compiler/gen_llvm/src/llvm/bitcode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/compiler/gen_llvm/src/llvm/bitcode.rs b/crates/compiler/gen_llvm/src/llvm/bitcode.rs index 9e8c57921a..d4a3e445ae 100644 --- a/crates/compiler/gen_llvm/src/llvm/bitcode.rs +++ b/crates/compiler/gen_llvm/src/llvm/bitcode.rs @@ -736,7 +736,7 @@ pub fn build_compare_wrapper<'a, 'ctx>( }; env.arena - .alloc([value1.into(), value2.into(), closure_data.into()]) + .alloc([value1.into(), value2.into(), closure_data]) as &[BasicMetadataValueEnum] } };