diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index 82cab823105..7e3faba48ec 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -652,7 +652,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid fun callDirect(descriptor: FunctionDescriptor, args: List, result: String?): LLVMOpaqueValue? { val llvmFunction = codegen.functionLlvmValue(descriptor) - return codegen.call(llvmFunction, args, result) + return call(descriptor, llvmFunction, args, result) } //-------------------------------------------------------------------------// @@ -680,7 +680,13 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid val functionPtrType = pointerType(getLlvmFunctionType(descriptor)) // Construct type of the method to be invoked val function = codegen.bitcast(functionPtrType, llvmMethod!!, codegen.newVar()) // Cast method address to the type - return codegen.call(function, args, result) // Invoke the method + return call(descriptor, function, args, result) // Invoke the method + } + + //-------------------------------------------------------------------------// + + private fun call(descriptor: FunctionDescriptor, function: LLVMOpaqueValue?, args: List, result: String?): LLVMOpaqueValue? { + return codegen.call(function, args, if (KotlinBuiltIns.isUnit(descriptor.returnType!!)) "" else result) } //-------------------------------------------------------------------------//