From 2ca7123ce13e0f94d11c6484794a4bfa6941465f Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Fri, 6 Mar 2020 14:38:38 +0300 Subject: [PATCH] [devirtualization] Fixed bug with handling empty IrBlock --- .../konan/optimizations/Devirtualization.kt | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt index 05541c0adf3..b42a56d8d81 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt @@ -1729,26 +1729,30 @@ internal object Devirtualization { is IrBlock -> { val statements = expression.statements - val lastStatement = statements.last() as IrExpression - val foldedLastStatement = fold(lastStatement, coercion, cast, transformRecursively) - statements.transform { - if (it == lastStatement) - foldedLastStatement.expression - else - it.transformIfAsked() + if (statements.isEmpty()) + PossiblyFoldedExpression(expression, false) + else { + val lastStatement = statements.last() as IrExpression + val foldedLastStatement = fold(lastStatement, coercion, cast, transformRecursively) + statements.transform { + if (it == lastStatement) + foldedLastStatement.expression + else + it.transformIfAsked() + } + val transformedBlock = + if (!foldedLastStatement.folded) + expression + else with(expression) { + IrBlockImpl( + startOffset = startOffset, + endOffset = endOffset, + type = coercion.type, + origin = origin, + statements = statements) + } + PossiblyFoldedExpression(transformedBlock, foldedLastStatement.folded) } - val transformedBlock = - if (!foldedLastStatement.folded) - expression - else with(expression) { - IrBlockImpl( - startOffset = startOffset, - endOffset = endOffset, - type = coercion.type, - origin = origin, - statements = statements) - } - PossiblyFoldedExpression(transformedBlock, foldedLastStatement.folded) } is IrWhen -> {