From 9bc13264a75dcc84990f3c162dffdb805a531801 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Fri, 17 Feb 2017 11:24:12 +0300 Subject: [PATCH] backend: Generate exit block for "when" if it has no unconditional branch --- .../jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 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 1f6a6f4ee6a..49d5f8eb49c 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 @@ -1034,11 +1034,14 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid var bbExit: LLVMBasicBlockRef? = null // By default "when" does not have "exit". val isUnit = KotlinBuiltIns.isUnit(expression.type) val isNothing = KotlinBuiltIns.isNothing(expression.type) + val hasNoUnconditional = !isUnconditional(expression.branches.last()) - if (!isNothing) // If "when" has "exit". - bbExit = codegen.basicBlock() // Create basic block to process "exit". + // If "when" has no unconditional branch we may continue execution even if it has type "Nothing". + // So we need an exit block. + if (!isNothing || hasNoUnconditional) // If "when" has "exit". + bbExit = codegen.basicBlock() // Create basic block to process "exit". - val hasNoValue = !isUnconditional(expression.branches.last()) + val hasNoValue = hasNoUnconditional // (It is possible if IrWhen is used as statement). val llvmType = codegen.getLLVMType(expression.type)