backend: Generate exit block for "when" if it has no unconditional branch
This commit is contained in:
+6
-3
@@ -1034,11 +1034,14 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
var bbExit: LLVMBasicBlockRef? = null // By default "when" does not have "exit".
|
var bbExit: LLVMBasicBlockRef? = null // By default "when" does not have "exit".
|
||||||
val isUnit = KotlinBuiltIns.isUnit(expression.type)
|
val isUnit = KotlinBuiltIns.isUnit(expression.type)
|
||||||
val isNothing = KotlinBuiltIns.isNothing(expression.type)
|
val isNothing = KotlinBuiltIns.isNothing(expression.type)
|
||||||
|
val hasNoUnconditional = !isUnconditional(expression.branches.last())
|
||||||
|
|
||||||
if (!isNothing) // If "when" has "exit".
|
// If "when" has no unconditional branch we may continue execution even if it has type "Nothing".
|
||||||
bbExit = codegen.basicBlock() // Create basic block to process "exit".
|
// 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).
|
// (It is possible if IrWhen is used as statement).
|
||||||
|
|
||||||
val llvmType = codegen.getLLVMType(expression.type)
|
val llvmType = codegen.getLLVMType(expression.type)
|
||||||
|
|||||||
Reference in New Issue
Block a user