[IR] Not try Null constant in fold constant

^KT-46859 fixed
This commit is contained in:
Ilya Goncharov
2021-05-21 19:29:06 +03:00
committed by teamcityserver
parent b18d4af37b
commit c62a965180
10 changed files with 81 additions and 0 deletions
@@ -1638,6 +1638,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/boxingOptimization/kt19767_chain.kt");
}
@Test
@TestMetadata("kt46859.kt")
public void testKt46859() throws Exception {
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
}
@Test
@TestMetadata("kt5493.kt")
public void testKt5493() throws Exception {
@@ -130,6 +130,7 @@ class FoldConstantLowering(
operationName == "toString" -> constToString(operand)
// Disable toFloat folding on K/JS till `toFloat` is fixed (KT-35422)
operationName == "toFloat" && floatSpecial -> return call
operand.kind == IrConstKind.Null -> return call
else -> evaluateUnary(
operationName,
operand.kind.toString(),
@@ -161,6 +162,8 @@ class FoldConstantLowering(
val lhs = coerceToDouble(call.dispatchReceiver as? IrConst<*> ?: return call)
val rhs = coerceToDouble(call.getValueArgument(0) as? IrConst<*> ?: return call)
if (lhs.kind == IrConstKind.Null || rhs.kind == IrConstKind.Null) return call
val evaluated = try {
evaluateBinary(
call.symbol.owner.name.toString(),
@@ -189,6 +192,8 @@ class FoldConstantLowering(
val lhs = call.getValueArgument(0) as? IrConst<*> ?: return call
val rhs = call.getValueArgument(1) as? IrConst<*> ?: return call
if (lhs.kind == IrConstKind.Null || rhs.kind == IrConstKind.Null) return call
val evaluated = try {
val evaluator =
BINARY_OP_TO_EVALUATOR[BinaryOp(lhs.kind.toString(), rhs.kind.toString(), call.symbol.owner.name.toString())] ?: return call
@@ -0,0 +1,33 @@
fun box(): String {
return "OK"
}
fun foo() {
foldingUnary(null)
foldingBinary(null, null)
foldingBuiltinBinary(null, null)
}
class Foo {
fun foo() {}
fun foo(foo: Foo?) {}
}
inline fun foldingUnary(foo: Foo?) {
foo!!
foo.foo()
}
inline fun foldingBinary(foo1: Foo?, foo2: Foo?) {
foo1!!
foo2!!
foo1.foo(foo2)
}
inline fun foldingBuiltinBinary(int1: Int?, int2: Int?) {
int1!!
int2!!
int1 < int2
}
@@ -1638,6 +1638,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/boxingOptimization/kt19767_chain.kt");
}
@Test
@TestMetadata("kt46859.kt")
public void testKt46859() throws Exception {
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
}
@Test
@TestMetadata("kt5493.kt")
public void testKt5493() throws Exception {
@@ -1638,6 +1638,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/boxingOptimization/kt19767_chain.kt");
}
@Test
@TestMetadata("kt46859.kt")
public void testKt46859() throws Exception {
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
}
@Test
@TestMetadata("kt5493.kt")
public void testKt5493() throws Exception {
@@ -1444,6 +1444,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/boxingOptimization/kt19767_chain.kt");
}
@TestMetadata("kt46859.kt")
public void testKt46859() throws Exception {
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
}
@TestMetadata("kt5493.kt")
public void testKt5493() throws Exception {
runTest("compiler/testData/codegen/box/boxingOptimization/kt5493.kt");
@@ -939,6 +939,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/boxingOptimization/kt19767_chain.kt");
}
@TestMetadata("kt46859.kt")
public void testKt46859() throws Exception {
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
}
@TestMetadata("kt5493.kt")
public void testKt5493() throws Exception {
runTest("compiler/testData/codegen/box/boxingOptimization/kt5493.kt");
@@ -939,6 +939,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/boxingOptimization/kt19767_chain.kt");
}
@TestMetadata("kt46859.kt")
public void testKt46859() throws Exception {
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
}
@TestMetadata("kt5493.kt")
public void testKt5493() throws Exception {
runTest("compiler/testData/codegen/box/boxingOptimization/kt5493.kt");
@@ -939,6 +939,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/boxingOptimization/kt19767_chain.kt");
}
@TestMetadata("kt46859.kt")
public void testKt46859() throws Exception {
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
}
@TestMetadata("kt5493.kt")
public void testKt5493() throws Exception {
runTest("compiler/testData/codegen/box/boxingOptimization/kt5493.kt");
@@ -824,6 +824,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/boxingOptimization/kt19767_chain.kt");
}
@TestMetadata("kt46859.kt")
public void testKt46859() throws Exception {
runTest("compiler/testData/codegen/box/boxingOptimization/kt46859.kt");
}
@TestMetadata("kt5588.kt")
public void testKt5588() throws Exception {
runTest("compiler/testData/codegen/box/boxingOptimization/kt5588.kt");