From 4495c86c2c365a46bbcd7b22d3ff5e8d44078528 Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Thu, 17 Nov 2016 14:44:26 +0300 Subject: [PATCH] call of void function (cherry picked from commit feeacab2bb6e1789e91075dc1b519340cd4f4172) --- .../jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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) } //-------------------------------------------------------------------------//