From ecdac4190cd73713a938ae06773aa055e35f3cac Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Mon, 31 Oct 2016 21:31:32 +0300 Subject: [PATCH] added processing of the BLOCK_BODY, for Unit function IR doesn't contein RETURN: FUN public fun bar(i: kotlin.Int): kotlin.Unit BLOCK_BODY for code: fun bar(i:Int):Unit {} --- .../jetbrains/kotlin/backend/native/llvm/IrToBitcode.kt | 8 ++++++++ 1 file changed, 8 insertions(+) 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 99b05f03706..7837fe86e5f 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 @@ -2,6 +2,7 @@ package org.jetbrains.kotlin.backend.native.llvm import kotlin_native.interop.* import llvm.* +import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.LazyClassReceiverParameterDescriptor import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor @@ -72,6 +73,13 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid LLVMBuildRet(context.llvmBuilder, generator.load(thisValue!!, generator.tmpVariable())) } + override fun visitBlockBody(body: IrBlockBody) { + super.visitBlockBody(body) + if (KotlinBuiltIns.isUnit(generator.currentFunction!!.returnType!!)) { + LLVMBuildRet(context.llvmBuilder, null) + } + } + override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall) { evaluateCall(generator.tmpVariable(), expression) }