From 3d5ddc60dc2b4ce51c099e211f317a72fbdfcbb9 Mon Sep 17 00:00:00 2001 From: sofia Date: Mon, 14 Jul 2025 19:16:52 +0300 Subject: [PATCH] Fix void function calls not discarding name --- reid-llvm-lib/src/compile.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/reid-llvm-lib/src/compile.rs b/reid-llvm-lib/src/compile.rs index 134fc0a..3444b85 100644 --- a/reid-llvm-lib/src/compile.rs +++ b/reid-llvm-lib/src/compile.rs @@ -205,14 +205,12 @@ impl FunctionHolder { let own_function = *module.functions.get(&self.value).unwrap(); if self.data.flags.is_extern { - LLVMSetLinkage( - own_function.value_ref, - LLVMLinkage::LLVMAvailableExternallyLinkage, - ); + LLVMSetLinkage(own_function.value_ref, LLVMLinkage::LLVMExternalLinkage); return; } - if self.data.flags.is_pub { - LLVMSetLinkage(own_function.value_ref, LLVMLinkage::LLVMCommonLinkage); + + if self.data.flags.is_pub || self.data.name == "main" { + LLVMSetLinkage(own_function.value_ref, LLVMLinkage::LLVMExternalLinkage); } else { LLVMSetLinkage(own_function.value_ref, LLVMLinkage::LLVMPrivateLinkage); } @@ -317,14 +315,22 @@ impl InstructionHolder { .map(|i| module.values.get(i).unwrap().value_ref) .collect(); - LLVMBuildCall2( + let is_void = module.builder.function_data(&*function_value).ret == Type::Void; + if is_void { + LLVMContextSetDiscardValueNames(module.context_ref, 1); + } + let value = LLVMBuildCall2( module.builder_ref, fun.type_ref, fun.value_ref, param_list.as_mut_ptr(), param_list.len() as u32, c"call".as_ptr(), - ) + ); + if is_void { + LLVMContextSetDiscardValueNames(module.context_ref, 0); + } + value } Phi(values) => { let mut inc_values = Vec::new(); @@ -491,7 +497,7 @@ impl Type { I64 | U64 => LLVMInt64TypeInContext(context), I128 | U128 => LLVMInt128TypeInContext(context), Bool => LLVMInt1TypeInContext(context), - Void => LLVMVoidType(), + Void => LLVMVoidTypeInContext(context), Ptr(ty) => LLVMPointerType(ty.as_llvm(context), 0), } }