JVM: Fix IEEE 754 comparison generation for boxed numbers

This commit is contained in:
Dmitry Petrov
2020-01-14 10:12:50 +03:00
parent 26f435eb90
commit d5ff1047a5
7 changed files with 78 additions and 1 deletions
@@ -4044,7 +4044,8 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
boolean properIeee754Comparisons = shouldUseProperIeee754Comparisons();
if (properIeee754Comparisons && left754Type != null && right754Type != null) {
type = comparisonOperandType(leftType, rightType);
type = comparisonOperandType(left754Type.type, right754Type.type);
//type = comparisonOperandType(leftType, rightType);
leftValue = gen(left);
rightValue = gen(right);
}
@@ -0,0 +1,19 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// reason - multifile tests are not supported in JS tests
//FILE: Holder.java
import org.jetbrains.annotations.*;
class Holder {
public @NotNull Double value;
public Holder(Double value) { this.value = value; }
}
//FILE: test.kt
import Holder
fun box(): String {
val j = Holder(0.99)
return if (j.value > 0) "OK" else "fail"
}
@@ -0,0 +1,17 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// reason - multifile tests are not supported in JS tests
//FILE: JavaClass.java
import org.jetbrains.annotations.*;
class JavaClass {
public static @NotNull Long get() { return 2364137526064485012L; }
}
//FILE: test.kt
import JavaClass
fun box(): String {
return if (JavaClass.get() > 0) "OK" else "fail"
}
@@ -1101,6 +1101,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/binaryOp/compareWithBoxedLong.kt");
}
@TestMetadata("compareWithBoxedNotNullDouble.kt")
public void testCompareWithBoxedNotNullDouble() throws Exception {
runTest("compiler/testData/codegen/box/binaryOp/compareWithBoxedNotNullDouble.kt");
}
@TestMetadata("compareWithBoxedNotNullLong.kt")
public void testCompareWithBoxedNotNullLong() throws Exception {
runTest("compiler/testData/codegen/box/binaryOp/compareWithBoxedNotNullLong.kt");
}
@TestMetadata("divisionByZero.kt")
public void testDivisionByZero() throws Exception {
runTest("compiler/testData/codegen/box/binaryOp/divisionByZero.kt");
@@ -1101,6 +1101,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/binaryOp/compareWithBoxedLong.kt");
}
@TestMetadata("compareWithBoxedNotNullDouble.kt")
public void testCompareWithBoxedNotNullDouble() throws Exception {
runTest("compiler/testData/codegen/box/binaryOp/compareWithBoxedNotNullDouble.kt");
}
@TestMetadata("compareWithBoxedNotNullLong.kt")
public void testCompareWithBoxedNotNullLong() throws Exception {
runTest("compiler/testData/codegen/box/binaryOp/compareWithBoxedNotNullLong.kt");
}
@TestMetadata("divisionByZero.kt")
public void testDivisionByZero() throws Exception {
runTest("compiler/testData/codegen/box/binaryOp/divisionByZero.kt");
@@ -1081,6 +1081,16 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/binaryOp/compareWithBoxedLong.kt");
}
@TestMetadata("compareWithBoxedNotNullDouble.kt")
public void testCompareWithBoxedNotNullDouble() throws Exception {
runTest("compiler/testData/codegen/box/binaryOp/compareWithBoxedNotNullDouble.kt");
}
@TestMetadata("compareWithBoxedNotNullLong.kt")
public void testCompareWithBoxedNotNullLong() throws Exception {
runTest("compiler/testData/codegen/box/binaryOp/compareWithBoxedNotNullLong.kt");
}
@TestMetadata("divisionByZero.kt")
public void testDivisionByZero() throws Exception {
runTest("compiler/testData/codegen/box/binaryOp/divisionByZero.kt");
@@ -1081,6 +1081,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/binaryOp/compareWithBoxedLong.kt");
}
@TestMetadata("compareWithBoxedNotNullDouble.kt")
public void testCompareWithBoxedNotNullDouble() throws Exception {
runTest("compiler/testData/codegen/box/binaryOp/compareWithBoxedNotNullDouble.kt");
}
@TestMetadata("compareWithBoxedNotNullLong.kt")
public void testCompareWithBoxedNotNullLong() throws Exception {
runTest("compiler/testData/codegen/box/binaryOp/compareWithBoxedNotNullLong.kt");
}
@TestMetadata("divisionByZero.kt")
public void testDivisionByZero() throws Exception {
runTest("compiler/testData/codegen/box/binaryOp/divisionByZero.kt");