JVM IR: Don't produce CHECKCASTs on null constants (KT-36650)

This commit is contained in:
Steven Schäfer
2020-08-04 16:03:05 +02:00
committed by Alexander Udalov
parent 7503f134c2
commit 53fe30eb45
7 changed files with 26 additions and 17 deletions
@@ -1,7 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// TODO KT-36650 Don't generate CHECKCAST on null values in JVM_IR
// KT-15411 Unnecessary CHECKCAST bytecode when dealing with null
fun test1(): String? {
return null
}
@@ -16,14 +16,12 @@ fun test(ss: List<String?>) {
}
}
// JVM_TEMPLATES
// 2 POP
// 0 INVOKESTATIC java/lang/Boolean\.valueOf
// 0 CHECKCAST java/lang/Boolean
// 0 ACONST_NULL
// JVM_IR_TEMPLATES
// JVM_TEMPLATES
// 2 POP
// 0 INVOKESTATIC java/lang/Boolean\.valueOf
// 1 CHECKCAST java/lang/Boolean
// 1 ACONST_NULL
// JVM_IR_TEMPLATES
// 1 POP
@@ -12,6 +12,12 @@ suspend fun test() {
blackhole(a)
}
// jsut before suspension point
// 2 PUTFIELD .*L\$0 : Ljava/lang/Object;
// JVM_TEMPLATES:
// just before suspension point
// 1 ACONST_NULL
// 2 PUTFIELD .*L\$0 : Ljava/lang/Object;
// JVM_IR_TEMPLATES:
// two stores to initialize the `a` variable and one null constant to store in the spill slot.
// 3 ACONST_NULL