From 08bfdb652cf06be6b6544139d263d37e300814fc Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Tue, 1 Nov 2016 12:48:46 +0300 Subject: [PATCH] processing Call IR expressions and void functions (crash expected) --- .../jetbrains/kotlin/backend/native/llvm/CodeGenerator.kt | 2 +- .../org/jetbrains/kotlin/backend/native/llvm/IrToBitcode.kt | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/CodeGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/CodeGenerator.kt index ae4dc9a2e4c..f5416fbd781 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/CodeGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/CodeGenerator.kt @@ -125,7 +125,7 @@ internal class CodeGenerator(override val context:Context) : ContextUtils { fun load(value:LLVMOpaqueValue, varName: String):LLVMOpaqueValue = LLVMBuildLoad(context.llvmBuilder, value, varName)!! fun store(value:LLVMOpaqueValue, ptr:LLVMOpaqueValue):LLVMOpaqueValue = LLVMBuildStore(context.llvmBuilder, value, ptr)!! - fun call(descriptor: FunctionDescriptor, args: MutableList, result: String): LLVMOpaqueValue? { + fun call(descriptor: FunctionDescriptor, args: MutableList, result: String?): LLVMOpaqueValue? { if (args.size == 0) return LLVMBuildCall(context.llvmBuilder, descriptor.llvmFunction.getLlvmValue(), null, 0, result) memScoped { val rargs = alloc(array[args.size](Ref to LLVMOpaqueValue)) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/IrToBitcode.kt index 7837fe86e5f..f1ad24fc84e 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/IrToBitcode.kt @@ -84,8 +84,8 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid evaluateCall(generator.tmpVariable(), expression) } - override fun visitConstructor(declaration: IrConstructor, data: Nothing?) { - super.visitConstructor(declaration, data) + override fun visitCall(expression: IrCall) { + evaluateExpression(generator.tmpVariable(), expression) } override fun visitFunction(declaration: IrFunction) { @@ -183,6 +183,8 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid } private fun evaluateSimpleFunctionCall(tmpVariableName: String, value: IrCall, args: MutableList): LLVMOpaqueValue? { + if (KotlinBuiltIns.isUnit(value.descriptor.returnType!!)) + return generator.call(value.descriptor as FunctionDescriptor, args, null) return generator.call(value.descriptor as FunctionDescriptor, args, tmpVariableName) }