JVM IR: Avoid optimizing comparisons between boxed primitives and null

A comparison of the form `x == null` where `x` is of type `Int` might not
be vacuous if `x` is a boxed value coming from Java code.
This commit is contained in:
Steven Schäfer
2020-02-13 14:45:49 +01:00
committed by Dmitry Petrov
parent 32e1ec8e98
commit 4b954c347a
2 changed files with 1 additions and 27 deletions
@@ -1,6 +1,5 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM_IR
// FILE: Unsound.java
import test.Wrap;
@@ -17,6 +16,4 @@ package test
class Wrap<T>(val x: T)
// JVM IR generates bytecode that fails with NPE because it unwraps the value with `Number.intValue()`,
// whereas JVM generates a simple null check without unwrapping the box.
fun box(): String = if ((Unsound.get<Int>() as Wrap<Int>).x == null) "OK" else "Fail"