diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java index 53f2d0d70bb..950974d7af4 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java @@ -138,6 +138,10 @@ public class AsmUtil { return type == Type.INT_TYPE || type == Type.SHORT_TYPE || type == Type.BYTE_TYPE || type == Type.CHAR_TYPE; } + public static boolean isNumberPrimitiveOrBoolean(Type type) { + return isNumberPrimitive(type) || type.getSort() == Type.BOOLEAN; + } + public static boolean isNumberPrimitive(Type type) { return isIntPrimitive(type) || type == Type.FLOAT_TYPE || type == Type.DOUBLE_TYPE || type == Type.LONG_TYPE; } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 1ec518deb32..189f7313dcf 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -424,13 +424,12 @@ public class ExpressionCodegen extends KtVisitor impleme @NotNull public Type expressionType(@Nullable KtExpression expression) { - KotlinType type = expressionJetType(expression); - return type == null ? Type.VOID_TYPE : asmType(type); + return CodegenUtilKt.asmType(expression, typeMapper, bindingContext); } @Nullable - public KotlinType expressionJetType(@Nullable KtExpression expression) { - return expression != null ? bindingContext.getType(expression) : null; + private KotlinType expressionJetType(@Nullable KtExpression expression) { + return CodegenUtilKt.kotlinType(expression, bindingContext); } @Override @@ -3624,7 +3623,7 @@ public class ExpressionCodegen extends KtVisitor impleme return StackValue.or(gen(expression.getLeft()), gen(expression.getRight())); } - private StackValue generateEquals(KtExpression left, KtExpression right, IElementType opToken) { + private StackValue generateEquals(@Nullable KtExpression left, @Nullable KtExpression right, @NotNull IElementType opToken) { Type leftType = expressionType(left); Type rightType = expressionType(right); @@ -3649,16 +3648,36 @@ public class ExpressionCodegen extends KtVisitor impleme rightType = boxType(rightType); } - StackValue leftValue = genLazy(left, leftType); - StackValue rightValue = genLazy(right, rightType); - if (opToken == KtTokens.EQEQEQ || opToken == KtTokens.EXCLEQEQEQ) { // TODO: always casting to the type of the left operand in case of primitives looks wrong Type operandType = isPrimitive(leftType) ? leftType : OBJECT_TYPE; - return StackValue.cmp(opToken, operandType, leftValue, rightValue); + return StackValue.cmp(opToken, operandType, genLazy(left, leftType), genLazy(right, rightType)); } - return genEqualsForExpressionsOnStack(opToken, leftValue, rightValue); + return genEqualsForExpressionsPreferIEEE754Arithmetic(left, right, opToken, leftType, rightType, null); + } + + /*tries to use IEEE 754 arithmetic*/ + private StackValue genEqualsForExpressionsPreferIEEE754Arithmetic( + @Nullable KtExpression left, + @Nullable KtExpression right, + @NotNull IElementType opToken, + @NotNull Type leftType, + @NotNull Type rightType, + @Nullable StackValue pregeneratedLeft + ) { + Type left754Type = calcTypeForIEEE754ArithmeticIfNeeded(left); + Type right754Type = calcTypeForIEEE754ArithmeticIfNeeded(right); + if (left754Type != null && right754Type != null && left754Type.equals(right754Type)) { + leftType = left754Type; + rightType = right754Type; + } + + return genEqualsForExpressionsOnStack( + opToken, + pregeneratedLeft != null ? StackValue.coercion(pregeneratedLeft, leftType) : genLazy(left, leftType), + genLazy(right, rightType) + ); } private boolean isIntZero(KtExpression expr, Type exprType) { @@ -3722,9 +3741,12 @@ public class ExpressionCodegen extends KtVisitor impleme StackValue rightValue; Type leftType = expressionType(left); Type rightType = expressionType(right); + Type left754Type = calcTypeForIEEE754ArithmeticIfNeeded(left); + Type right754Type = calcTypeForIEEE754ArithmeticIfNeeded(right); Callable callable = resolveToCallable((FunctionDescriptor) resolvedCall.getResultingDescriptor(), false, resolvedCall); - if (isPrimitive(leftType) && isPrimitive(rightType) && callable instanceof IntrinsicCallable) { - type = comparisonOperandType(leftType, rightType); + boolean is754Arithmetic = left754Type != null && right754Type != null && left754Type.equals(right754Type); + if (callable instanceof IntrinsicCallable && ((isPrimitive(leftType) && isPrimitive(rightType)) || is754Arithmetic)) { + type = is754Arithmetic ? left754Type : comparisonOperandType(leftType, rightType); leftValue = gen(left); rightValue = gen(right); } @@ -3736,6 +3758,10 @@ public class ExpressionCodegen extends KtVisitor impleme return StackValue.cmp(expression.getOperationToken(), type, leftValue, rightValue); } + private Type calcTypeForIEEE754ArithmeticIfNeeded(@Nullable KtExpression expression) { + return CodegenUtilKt.calcTypeForIEEE754ArithmeticIfNeeded(expression, bindingContext, context.getFunctionDescriptor()); + } + private StackValue generateAssignmentExpression(final KtBinaryExpression expression) { return StackValue.operation(Type.VOID_TYPE, new Function1() { @Override @@ -4491,24 +4517,24 @@ The "returned" value of try expression with no finally is either the last expres return generateIsCheck(match, expression.getTypeReference(), expression.isNegated()); } - private StackValue generateExpressionMatch(StackValue expressionToMatch, KtExpression patternExpression) { + private StackValue generateExpressionMatch(StackValue expressionToMatch, KtExpression subjectExpression, KtExpression patternExpression) { if (expressionToMatch != null) { Type subjectType = expressionToMatch.type; markStartLineNumber(patternExpression); KotlinType condJetType = bindingContext.getType(patternExpression); Type condType; - if (isNumberPrimitive(subjectType) || subjectType.getSort() == Type.BOOLEAN) { + if (isNumberPrimitiveOrBoolean(subjectType)) { assert condJetType != null; condType = asmType(condJetType); - if (!(isNumberPrimitive(condType) || condType.getSort() == Type.BOOLEAN)) { + if (!isNumberPrimitiveOrBoolean(condType)) { subjectType = boxType(subjectType); } } else { condType = OBJECT_TYPE; } - StackValue condition = genLazy(patternExpression, condType); - return genEqualsForExpressionsOnStack(KtTokens.EQEQ, StackValue.coercion(expressionToMatch, subjectType), condition); + + return genEqualsForExpressionsPreferIEEE754Arithmetic(subjectExpression, patternExpression, KtTokens.EQEQ, subjectType, condType, expressionToMatch); } else { return gen(patternExpression); @@ -4616,7 +4642,7 @@ The "returned" value of try expression with no finally is either the last expres if (!whenEntry.isElse()) { KtWhenCondition[] conditions = whenEntry.getConditions(); for (int i = 0; i < conditions.length; i++) { - StackValue conditionValue = generateWhenCondition(subjectType, subjectLocal, conditions[i]); + StackValue conditionValue = generateWhenCondition(expr, subjectType, subjectLocal, conditions[i]); BranchedValue.Companion.condJump(conditionValue, nextCondition, true, v); if (i < conditions.length - 1) { v.goTo(thisEntry); @@ -4671,7 +4697,7 @@ The "returned" value of try expression with no finally is either the last expres } } - private StackValue generateWhenCondition(Type subjectType, int subjectLocal, KtWhenCondition condition) { + private StackValue generateWhenCondition(KtExpression subjectExpression, Type subjectType, int subjectLocal, KtWhenCondition condition) { if (condition instanceof KtWhenConditionInRange) { KtWhenConditionInRange conditionInRange = (KtWhenConditionInRange) condition; return generateIn(StackValue.local(subjectLocal, subjectType), @@ -4685,7 +4711,7 @@ The "returned" value of try expression with no finally is either the last expres } else if (condition instanceof KtWhenConditionWithExpression) { KtExpression patternExpression = ((KtWhenConditionWithExpression) condition).getExpression(); - return generateExpressionMatch(match, patternExpression); + return generateExpressionMatch(match, subjectExpression, patternExpression); } else { throw new UnsupportedOperationException("unsupported kind of when condition"); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt index f36063fc792..e42b1efbd51 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/codegenUtil.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.codegen import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.codegen.context.FieldOwnerContext import org.jetbrains.kotlin.codegen.context.PackageContext import org.jetbrains.kotlin.codegen.intrinsics.TypeIntrinsics @@ -31,12 +32,15 @@ import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature. import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor import org.jetbrains.kotlin.psi.KtClassOrObject +import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtObjectDeclaration import org.jetbrains.kotlin.psi.KtProperty import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.annotations.hasJvmStaticAnnotation +import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfoBefore +import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin import org.jetbrains.kotlin.serialization.deserialization.PLATFORM_DEPENDENT_ANNOTATION_FQ_NAME @@ -44,6 +48,7 @@ import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.utils.DFS +import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult import org.jetbrains.org.objectweb.asm.Label import org.jetbrains.org.objectweb.asm.Type import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter @@ -257,3 +262,38 @@ private fun CallableDescriptor.isJvmStaticIn(predicate: (DeclarationDescriptor) } fun Collection.filterOutDescriptorsWithSpecialNames() = filterNot { it.name.isSpecial } + + +fun calcTypeForIEEE754ArithmeticIfNeeded(expression: KtExpression?, bindingContext: BindingContext, descriptor: DeclarationDescriptor): Type? { + val ktType = expression.kotlinType(bindingContext) ?: return null + + if (KotlinBuiltIns.isDoubleOrNullableDouble(ktType)) { + return Type.DOUBLE_TYPE + } + + if (KotlinBuiltIns.isFloatOrNullableFloat(ktType)) { + return Type.FLOAT_TYPE + } + + val dataFlow = DataFlowValueFactory.createDataFlowValue(expression!!, ktType, bindingContext, descriptor) + val stableTypes = bindingContext.getDataFlowInfoBefore(expression).getStableTypes(dataFlow) + return stableTypes.firstNotNullResult { + if (KotlinBuiltIns.isDoubleOrNullableDouble(it)) { + Type.DOUBLE_TYPE + } + else if (KotlinBuiltIns.isFloatOrNullableFloat(it)) { + Type.FLOAT_TYPE + } + else { + null + } + } +} + +fun KotlinType.asmType(typeMapper: KotlinTypeMapper) = typeMapper.mapType(this) + +fun KtExpression?.asmType(typeMapper: KotlinTypeMapper, bindingContext: BindingContext): Type = + this.kotlinType(bindingContext)?.asmType(typeMapper) ?: Type.VOID_TYPE + +fun KtExpression?.kotlinType(bindingContext: BindingContext) = this?.let(bindingContext::getType) + diff --git a/compiler/testData/codegen/box/ieee754/anyToReal.kt b/compiler/testData/codegen/box/ieee754/anyToReal.kt new file mode 100644 index 00000000000..3ba490d870e --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/anyToReal.kt @@ -0,0 +1,15 @@ +fun box(): String { + val plusZero: Any = 0.0 + val minusZero: Any = -0.0 + if ((minusZero as Double) < (plusZero as Double)) return "fail 0" + + val plusZeroF: Any = 0.0F + val minusZeroF: Any = -0.0F + if ((minusZeroF as Float) < (plusZeroF as Float)) return "fail 1" + + if ((minusZero as Double) != (plusZero as Double)) return "fail 3" + + if ((minusZeroF as Float) != (plusZeroF as Float)) return "fail 4" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ieee754/comparableTypeCast.kt b/compiler/testData/codegen/box/ieee754/comparableTypeCast.kt new file mode 100644 index 00000000000..a4298207118 --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/comparableTypeCast.kt @@ -0,0 +1,14 @@ +// IGNORE_BACKEND: JS +fun box(): String { + if ((-0.0 as Comparable) >= 0.0) return "fail 0" + if ((-0.0F as Comparable) >= 0.0F) return "fail 1" + + + if ((-0.0 as Comparable) == 0.0) return "fail 3" + if (-0.0 == (0.0 as Comparable)) return "fail 4" + + if ((-0.0F as Comparable) == 0.0F) return "fail 5" + if (-0.0F == (0.0F as Comparable)) return "fail 6" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ieee754/dataClass.kt b/compiler/testData/codegen/box/ieee754/dataClass.kt new file mode 100644 index 00000000000..415c6814408 --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/dataClass.kt @@ -0,0 +1,9 @@ +// IGNORE_BACKEND: JS +data class Test(val z1: Double, val z2: Double?) + +fun box(): String { + val x = Test(Double.NaN, Double.NaN) + val y = Test(Double.NaN, Double.NaN) + + return if (x == y) "OK" else "fail" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ieee754/equalsDouble.kt b/compiler/testData/codegen/box/ieee754/equalsDouble.kt new file mode 100644 index 00000000000..28d5c90e7f6 --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/equalsDouble.kt @@ -0,0 +1,22 @@ +fun equals1(a: Double, b: Double) = a == b + +fun equals2(a: Double?, b: Double?) = a!! == b!! + +fun equals3(a: Double?, b: Double?) = a != null && b != null && a == b + +fun equals4(a: Double?, b: Double?) = if (a is Double && b is Double) a == b else null!! + +fun equals5(a: Any?, b: Any?) = if (a is Double && b is Double) a == b else null!! + + +fun box(): String { + if (-0.0 != 0.0) return "fail 0" + if (!equals1(-0.0, 0.0)) return "fail 1" + if (!equals2(-0.0, 0.0)) return "fail 2" + if (!equals3(-0.0, 0.0)) return "fail 3" + if (!equals4(-0.0, 0.0)) return "fail 4" + if (!equals5(-0.0, 0.0)) return "fail 5" + + return "OK" +} + diff --git a/compiler/testData/codegen/box/ieee754/equalsFloat.kt b/compiler/testData/codegen/box/ieee754/equalsFloat.kt new file mode 100644 index 00000000000..26187f688d0 --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/equalsFloat.kt @@ -0,0 +1,22 @@ +fun equals1(a: Float, b: Float) = a == b + +fun equals2(a: Float?, b: Float?) = a!! == b!! + +fun equals3(a: Float?, b: Float?) = a != null && b != null && a == b + +fun equals4(a: Float?, b: Float?) = if (a is Float && b is Float) a == b else null!! + +fun equals5(a: Any?, b: Any?) = if (a is Float && b is Float) a == b else null!! + + +fun box(): String { + if (-0.0F != 0.0F) return "fail 0" + if (!equals1(-0.0F, 0.0F)) return "fail 1" + if (!equals2(-0.0F, 0.0F)) return "fail 2" + if (!equals3(-0.0F, 0.0F)) return "fail 3" + if (!equals4(-0.0F, 0.0F)) return "fail 4" + if (!equals5(-0.0F, 0.0F)) return "fail 5" + + return "OK" +} + diff --git a/compiler/testData/codegen/box/ieee754/equalsNullableDouble.kt b/compiler/testData/codegen/box/ieee754/equalsNullableDouble.kt new file mode 100644 index 00000000000..229629cb1e5 --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/equalsNullableDouble.kt @@ -0,0 +1,30 @@ +fun equals1(a: Double, b: Double?) = a == b + +fun equals2(a: Double?, b: Double?) = a!! == b!! + +fun equals3(a: Double?, b: Double?) = a != null && a == b + +fun equals4(a: Double?, b: Double?) = if (a is Double) a == b else null!! + +fun equals5(a: Any?, b: Any?) = if (a is Double && b is Double?) a == b else null!! + +fun equals6(a: Any?, b: Any?) = if (a is Double? && b is Double) a == b else null!! + +fun equals7(a: Double?, b: Double?) = a == b + +fun equals8(a: Any?, b: Any?) = if (a is Double? && b is Double?) a == b else null!! + + +fun box(): String { + if (!equals1(-0.0, 0.0)) return "fail 1" + if (!equals2(-0.0, 0.0)) return "fail 2" + if (!equals3(-0.0, 0.0)) return "fail 3" + if (!equals4(-0.0, 0.0)) return "fail 4" + if (!equals5(-0.0, 0.0)) return "fail 5" + if (!equals6(-0.0, 0.0)) return "fail 6" + if (!equals7(-0.0, 0.0)) return "fail 7" + if (!equals8(-0.0, 0.0)) return "fail 8" + + return "OK" +} + diff --git a/compiler/testData/codegen/box/ieee754/explicitCompareCall.kt b/compiler/testData/codegen/box/ieee754/explicitCompareCall.kt new file mode 100644 index 00000000000..40409e20e4c --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/explicitCompareCall.kt @@ -0,0 +1,20 @@ +// IGNORE_BACKEND: JS +fun less1(a: Double, b: Double) = a.compareTo(b) == -1 + +fun less2(a: Double?, b: Double?) = a!!.compareTo(b!!) == -1 + +fun less3(a: Double?, b: Double?) = a != null && b != null && a.compareTo(b) == -1 + +fun less4(a: Double?, b: Double?) = if (a is Double && b is Double) a.compareTo(b) == -1 else null!! + +fun less5(a: Any?, b: Any?) = if (a is Double && b is Double) a.compareTo(b) == -1 else null!! + +fun box(): String { + if (!less1(-0.0, 0.0)) return "fail 1" + if (!less2(-0.0, 0.0)) return "fail 2" + if (!less3(-0.0, 0.0)) return "fail 3" + if (!less4(-0.0, 0.0)) return "fail 4" + if (!less5(-0.0, 0.0)) return "fail 5" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ieee754/explicitEqualsCall.kt b/compiler/testData/codegen/box/ieee754/explicitEqualsCall.kt new file mode 100644 index 00000000000..4a6f495d576 --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/explicitEqualsCall.kt @@ -0,0 +1,21 @@ +// IGNORE_BACKEND: JS + +fun equals1(a: Double, b: Double) = a.equals(b) + +fun equals2(a: Double?, b: Double?) = a!!.equals(b!!) + +fun equals3(a: Double?, b: Double?) = a != null && b != null && a.equals(b) + +fun equals4(a: Double?, b: Double?) = if (a is Double && b is Double) a.equals(b) else null!! + + +fun box(): String { + if ((-0.0).equals(0.0)) return "fail 0" + if (equals1(-0.0, 0.0)) return "fail 1" + if (equals2(-0.0, 0.0)) return "fail 2" + if (equals3(-0.0, 0.0)) return "fail 3" + if (equals4(-0.0, 0.0)) return "fail 4" + + return "OK" +} + diff --git a/compiler/testData/codegen/box/ieee754/generic.kt b/compiler/testData/codegen/box/ieee754/generic.kt new file mode 100644 index 00000000000..6d621ffd2c0 --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/generic.kt @@ -0,0 +1,18 @@ +// FILE: b.kt + +class Foo(val minus0: T, val plus0: T) { + +} + +fun box(): String { + val foo = Foo(-0.0, 0.0) + val fooF = Foo(-0.0F, 0.0F) + + if (foo.minus0 < foo.plus0) return "fail 0" + if (fooF.minus0 < fooF.plus0) return "fail 1" + + if (foo.minus0 != foo.plus0) return "fail 3" + if (fooF.minus0 != fooF.plus0) return "fail 4" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ieee754/greaterDouble.kt b/compiler/testData/codegen/box/ieee754/greaterDouble.kt new file mode 100644 index 00000000000..2359ca5d077 --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/greaterDouble.kt @@ -0,0 +1,20 @@ +fun greater1(a: Double, b: Double) = a > b + +fun greater2(a: Double?, b: Double?) = a!! > b!! + +fun greater3(a: Double?, b: Double?) = a != null && b != null && a > b + +fun greater4(a: Double?, b: Double?) = if (a is Double && b is Double) a > b else null!! + +fun greater5(a: Any?, b: Any?) = if (a is Double && b is Double) a > b else null!! + +fun box(): String { + if (0.0 > -0.0) return "fail 0" + if (greater1(0.0, -0.0)) return "fail 1" + if (greater2(0.0, -0.0)) return "fail 2" + if (greater3(0.0, -0.0)) return "fail 3" + if (greater4(0.0, -0.0)) return "fail 4" + if (greater5(0.0, -0.0)) return "fail 5" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ieee754/greaterFloat.kt b/compiler/testData/codegen/box/ieee754/greaterFloat.kt new file mode 100644 index 00000000000..ebcf4ef7147 --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/greaterFloat.kt @@ -0,0 +1,20 @@ +fun greater1(a: Float, b: Float) = a > b + +fun greater2(a: Float?, b: Float?) = a!! > b!! + +fun greater3(a: Float?, b: Float?) = a != null && b != null && a > b + +fun greater4(a: Float?, b: Float?) = if (a is Float && b is Float) a > b else null!! + +fun greater5(a: Any?, b: Any?) = if (a is Float && b is Float) a > b else null!! + +fun box(): String { + if (0.0F > -0.0F) return "fail 0" + if (greater1(0.0F, -0.0F)) return "fail 1" + if (greater2(0.0F, -0.0F)) return "fail 2" + if (greater3(0.0F, -0.0F)) return "fail 3" + if (greater4(0.0F, -0.0F)) return "fail 4" + if (greater5(0.0F, -0.0F)) return "fail 5" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ieee754/inline.kt b/compiler/testData/codegen/box/ieee754/inline.kt new file mode 100644 index 00000000000..58a844412bc --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/inline.kt @@ -0,0 +1,49 @@ +// IGNORE_BACKEND: JS + +inline fun less(a: Comparable, b: Double): Boolean { + return a < b +} + +inline fun equals(a: Comparable, b: Comparable): Boolean { + return a == b +} + +inline fun > lessGeneric(a: T, b: Double): Boolean { + return a < b +} + +inline fun > equalsGeneric(a: T, b: Double): Boolean { + return a == b +} + +inline fun > lessReified(a: T, b: Double): Boolean { + return a < b +} + +inline fun > equalsReified(a: T, b: T): Boolean { + return a == b +} + +inline fun less754(a: Double, b: Double): Boolean { + return a < b +} + +inline fun equals754(a: Double, b: Double): Boolean { + return a == b +} + +fun box(): String { + if (!less(-0.0, 0.0)) return "fail 1" + if (equals(-0.0, 0.0)) return "fail 2" + + if (!lessGeneric(-0.0, 0.0)) return "fail 3" + if (equalsGeneric(-0.0, 0.0)) return "fail 4" + + if (!lessReified(-0.0, 0.0)) return "fail 5" + if (equalsReified(-0.0, 0.0)) return "fail 6" + + if (less754(-0.0, 0.0)) return "fail 7" + if (!equals754(-0.0, 0.0)) return "fail 8" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ieee754/lessDouble.kt b/compiler/testData/codegen/box/ieee754/lessDouble.kt new file mode 100644 index 00000000000..b25363bdb65 --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/lessDouble.kt @@ -0,0 +1,20 @@ +fun less1(a: Double, b: Double) = a < b + +fun less2(a: Double?, b: Double?) = a!! < b!! + +fun less3(a: Double?, b: Double?) = a != null && b != null && a < b + +fun less4(a: Double?, b: Double?) = if (a is Double && b is Double) a < b else null!! + +fun less5(a: Any?, b: Any?) = if (a is Double && b is Double) a < b else null!! + +fun box(): String { + if (-0.0 < 0.0) return "fail 0" + if (less1(-0.0, 0.0)) return "fail 1" + if (less2(-0.0, 0.0)) return "fail 2" + if (less3(-0.0, 0.0)) return "fail 3" + if (less4(-0.0, 0.0)) return "fail 4" + if (less5(-0.0, 0.0)) return "fail 5" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ieee754/lessFloat.kt b/compiler/testData/codegen/box/ieee754/lessFloat.kt new file mode 100644 index 00000000000..efea2decef4 --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/lessFloat.kt @@ -0,0 +1,20 @@ +fun less1(a: Float, b: Float) = a < b + +fun less2(a: Float?, b: Float?) = a!! < b!! + +fun less3(a: Float?, b: Float?) = a != null && b != null && a < b + +fun less4(a: Float?, b: Float?) = if (a is Float && b is Float) a < b else true + +fun less5(a: Any?, b: Any?) = if (a is Float && b is Float) a < b else true + +fun box(): String { + if (-0.0F < 0.0F) return "fail 0" + if (less1(-0.0F, 0.0F)) return "fail 1" + if (less2(-0.0F, 0.0F)) return "fail 2" + if (less3(-0.0F, 0.0F)) return "fail 3" + if (less4(-0.0F, 0.0F)) return "fail 4" + if (less5(-0.0F, 0.0F)) return "fail 5" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ieee754/nullableAnyToReal.kt b/compiler/testData/codegen/box/ieee754/nullableAnyToReal.kt new file mode 100644 index 00000000000..7c4a950202f --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/nullableAnyToReal.kt @@ -0,0 +1,15 @@ +fun box(): String { + val plusZero: Any? = 0.0 + val minusZero: Any? = -0.0 + if ((minusZero as Double) < (plusZero as Double)) return "fail 0" + + val plusZeroF: Any? = 0.0F + val minusZeroF: Any? = -0.0F + if ((minusZeroF as Float) < (plusZeroF as Float)) return "fail 1" + + if ((minusZero as Double) != (plusZero as Double)) return "fail 3" + + if ((minusZeroF as Float) != (plusZeroF as Float)) return "fail 4" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ieee754/safeCall.kt b/compiler/testData/codegen/box/ieee754/safeCall.kt new file mode 100644 index 00000000000..06160ead6c5 --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/safeCall.kt @@ -0,0 +1,14 @@ +// IGNORE_BACKEND: JS +fun box(): String { + val plusZero: Double? = 0.0 + val minusZero: Double = -0.0 + if (plusZero?.equals(minusZero) ?: null!!) { + return "fail 1" + } + + if (plusZero?.compareTo(minusZero) ?: null!! != 1) { + return "fail 2" + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ieee754/smartCastToDifferentTypes.kt b/compiler/testData/codegen/box/ieee754/smartCastToDifferentTypes.kt new file mode 100644 index 00000000000..e3a06426db3 --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/smartCastToDifferentTypes.kt @@ -0,0 +1,14 @@ +// IGNORE_BACKEND: JS +fun box(): String { + val zero: Any = 0.0 + val floatZero: Any = -0.0F + if (zero is Double && floatZero is Float) { + if (zero == floatZero) return "fail 1" + + if (zero <= floatZero) return "fail 2" + + return "OK" + } + + return "fail" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ieee754/when.kt b/compiler/testData/codegen/box/ieee754/when.kt new file mode 100644 index 00000000000..c57947e17bf --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/when.kt @@ -0,0 +1,21 @@ +fun box(): String { + val plusZero: Any = 0.0 + val minusZero: Any = -0.0 + if (plusZero is Double) { + when (plusZero) { + -0.0 -> { + } + else -> return "fail 1" + } + + if (minusZero is Double) { + when (plusZero) { + minusZero -> { + } + else -> return "fail 2" + } + } + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ieee754/whenNoSubject.kt b/compiler/testData/codegen/box/ieee754/whenNoSubject.kt new file mode 100644 index 00000000000..308c9a24cfe --- /dev/null +++ b/compiler/testData/codegen/box/ieee754/whenNoSubject.kt @@ -0,0 +1,26 @@ +fun box(): String { + val plusZero: Any = 0.0 + val minusZero: Any = -0.0 + if (plusZero is Double && minusZero is Double) { + when { + plusZero < minusZero -> { + return "fail 1" + } + + plusZero > minusZero -> { + return "fail 2" + } + else -> { + } + } + + + when { + plusZero == minusZero -> { + } + else -> return "fail 3" + } + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxAgainstJava/ieee754/anyToReal.kt b/compiler/testData/codegen/boxAgainstJava/ieee754/anyToReal.kt new file mode 100644 index 00000000000..82b0e52c706 --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/ieee754/anyToReal.kt @@ -0,0 +1,27 @@ +// FILE: JavaClass.java + +public class JavaClass { + + public Object minus0() + { + return -0.0; + } + + public Object plus0() + { + return 0.0; + } + +} + +// FILE: b.kt + +fun box(): String { + val jClass = JavaClass() + + if ((jClass.minus0() as Double) < (jClass.plus0() as Double)) return "fail 1" + + if ((jClass.minus0() as Double) != (jClass.plus0() as Double)) return "fail 2" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxAgainstJava/ieee754/comparableTypeCast.kt b/compiler/testData/codegen/boxAgainstJava/ieee754/comparableTypeCast.kt new file mode 100644 index 00000000000..a6669e1491c --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/ieee754/comparableTypeCast.kt @@ -0,0 +1,26 @@ +// FILE: JavaClass.java + +public class JavaClass { + + public Double minus0() + { + return -0.0; + } + + public Double plus0() + { + return 0.0; + } +} + +// FILE: b.kt + +fun box(): String { + val jClass = JavaClass() + + if ((jClass.minus0() as Comparable) >= jClass.plus0()) return "fail 1" + if ((jClass.minus0() as Comparable) == jClass.plus0()) return "fail 2" + if (jClass.minus0() == (jClass.plus0() as Comparable)) return "fail 3" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxAgainstJava/ieee754/double.kt b/compiler/testData/codegen/boxAgainstJava/ieee754/double.kt new file mode 100644 index 00000000000..ffb123d332e --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/ieee754/double.kt @@ -0,0 +1,43 @@ +// FILE: JavaClass.java + +public class JavaClass { + + public Double minus0(){ + return -0.0; + } + + public Double plus0(){ + return 0.0; + } + + public Double null0(){ + return null; + } + +} + + +// FILE: b.kt + +fun box(): String { + val jClass = JavaClass() + + if (jClass.minus0() < jClass.plus0()) return "fail 1" + + //TODO: KT-14989 + //if (jClass.null0() < jClass.plus0()) return "fail 2" + + + if (jClass.plus0() > jClass.minus0()) return "fail 3" + + //TODO: KT-14989 + //if (jClass.null0() < jClass.plus0()) return "fail 4" + + if (jClass.minus0() != jClass.plus0()) return "fail 5" + + //TODO: KT-14989 + //if (jClass.null0() != jClass.plus0()) return "fail 6" + + return "OK" +} + diff --git a/compiler/testData/codegen/boxAgainstJava/ieee754/explicitCompareCall.kt b/compiler/testData/codegen/boxAgainstJava/ieee754/explicitCompareCall.kt new file mode 100644 index 00000000000..049ca1717c3 --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/ieee754/explicitCompareCall.kt @@ -0,0 +1,38 @@ +// FILE: JavaClass.java + +public class JavaClass { + + public Double minus0(){ + return -0.0; + } + + public Double plus0(){ + return 0.0; + } + + public Double null0(){ + return null; + } + +} + +// FILE: b.kt + + +fun box(): String { + + val jClass = JavaClass() + + if (jClass.minus0().compareTo(jClass.plus0()) != -1) return "fail 1" + + //TODO: KT-14989 + //if (jClass.null0().compareTo(jClass.plus0())) return "fail 2" + try { + if (jClass.minus0().compareTo(jClass.null0()) != -2) return "fail 3" + return "fail: exception expected"; + } catch (e: IllegalStateException) { + + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxAgainstJava/ieee754/explicitEqualsCall.kt b/compiler/testData/codegen/boxAgainstJava/ieee754/explicitEqualsCall.kt new file mode 100644 index 00000000000..d5937b6d5c7 --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/ieee754/explicitEqualsCall.kt @@ -0,0 +1,31 @@ +// FILE: JavaClass.java + +public class JavaClass { + + public Double minus0(){ + return -0.0; + } + + public Double plus0(){ + return 0.0; + } + + public Double null0(){ + return null; + } + +} + + +// FILE: b.kt + +fun box(): String { + val jClass = JavaClass() + + if (jClass.minus0().equals(jClass.plus0())) return "fail 5" + + if (jClass.null0().equals(jClass.plus0())) return "fail 6" + if (jClass.minus0().equals(jClass.null0())) return "fail 7" + return "OK" +} + diff --git a/compiler/testData/codegen/boxAgainstJava/ieee754/float.kt b/compiler/testData/codegen/boxAgainstJava/ieee754/float.kt new file mode 100644 index 00000000000..2d0478c060b --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/ieee754/float.kt @@ -0,0 +1,46 @@ +// FILE: JavaClass.java + +public class JavaClass { + + public Float minus0() + { + return -0.0F; + } + + public Float plus0() + { + return 0.0F; + } + + public Float null0() + { + return null; + } + +} + + +// FILE: b.kt + +fun box(): String { + val jClass = JavaClass() + + if (jClass.minus0() < jClass.plus0()) return "fail 1" + + //TODO: KT-14989 + //if (jClass.null0() < jClass.plus0()) return "fail 2" + + if (jClass.plus0() > jClass.minus0()) return "fail 3" + + //TODO: KT-14989 + //if (jClass.null0() < jClass.plus0()) return "fail 4" + + + if (jClass.minus0() != jClass.plus0()) return "fail 5" + + //TODO: KT-14989 + //if (jClass.null0() != jClass.plus0()) return "fail 6" + + return "OK" +} + diff --git a/compiler/testData/codegen/boxAgainstJava/ieee754/generic.kt b/compiler/testData/codegen/boxAgainstJava/ieee754/generic.kt new file mode 100644 index 00000000000..88c63bd7a4e --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/ieee754/generic.kt @@ -0,0 +1,36 @@ +// FILE: JavaClass.java + +public class JavaClass { + + private T minus0; + + private T plus0; + + JavaClass(T minus0, T plus0) + { + this.minus0 = minus0; + this.plus0 = plus0; + } + + public T minus0() + { + return minus0; + } + + public T plus0() + { + return plus0; + } + +} + +// FILE: b.kt + +fun box(): String { + val jClass = JavaClass(-0.0, 0.0) + + if (jClass.minus0() < jClass.plus0()) return "fail 2" + if (jClass.minus0() != jClass.plus0()) return "fail 5" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxAgainstJava/ieee754/nullableAnyToReal.kt b/compiler/testData/codegen/boxAgainstJava/ieee754/nullableAnyToReal.kt new file mode 100644 index 00000000000..a751c11917c --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/ieee754/nullableAnyToReal.kt @@ -0,0 +1,26 @@ +// FILE: JavaClass.java + +public class JavaClass { + + public Object minus0() + { + return -0.0; + } + + public Object plus0() + { + return 0.0; + } +} + +// FILE: b.kt + +fun box(): String { + + val jClass = JavaClass() + + if ((jClass.minus0() as Double) < (jClass.plus0() as Double)) return "fail 2" + if ((jClass.minus0() as Double) != (jClass.plus0() as Double)) return "fail 5" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast.kt b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast.kt new file mode 100644 index 00000000000..2d6a5b3c59d --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast.kt @@ -0,0 +1,16 @@ +fun equals3(a: Byte?, b: Byte?) = a != null && b != null && a == b + +fun equals4(a: Byte?, b: Byte?) = if (a is Byte && b is Byte) a == b else null!! + +fun equals5(a: Any?, b: Any?) = if (a is Byte && b is Byte) a == b else null!! + +fun less3(a: Byte?, b: Byte?) = a != null && b != null && a < b + +fun less4(a: Byte?, b: Byte?) = if (a is Byte && b is Byte) a < b else true + +fun less5(a: Any?, b: Any?) = if (a is Byte && b is Byte) a < b else true + +// 3 Intrinsics\.areEqual +// 3 Intrinsics\.compare +// for compare: +// 3 IF_ICMPGE diff --git a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/charSmartCast.kt b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/charSmartCast.kt new file mode 100644 index 00000000000..7b7dea65e66 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/charSmartCast.kt @@ -0,0 +1,16 @@ +fun equals3(a: Char?, b: Char?) = a != null && b != null && a == b + +fun equals4(a: Char?, b: Char?) = if (a is Char && b is Char) a == b else null!! + +fun equals5(a: Any?, b: Any?) = if (a is Char && b is Char) a == b else null!! + +fun less3(a: Char?, b: Char?) = a != null && b != null && a < b + +fun less4(a: Char?, b: Char?) = if (a is Char && b is Char) a < b else true + +fun less5(a: Any?, b: Any?) = if (a is Char && b is Char) a < b else true + +// 3 Intrinsics\.areEqual +// 3 Intrinsics\.compare +// for compare: +// 3 IF_ICMPGE diff --git a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes.kt b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes.kt new file mode 100644 index 00000000000..e7437c18cd6 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes.kt @@ -0,0 +1,16 @@ +fun box(): String { + val zero: Any = 0.0 + val floatZero: Any = -0.0F + if (zero is Double && floatZero is Float) { + if (zero == floatZero) return "fail 1" + + if (zero <= floatZero) return "fail 2" + + return "OK" + } + + return "fail" +} + +// 1 Intrinsics\.areEqual +// 1 Double\.compare diff --git a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast.kt b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast.kt new file mode 100644 index 00000000000..fb6171fd899 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast.kt @@ -0,0 +1,16 @@ +fun equals3(a: Int?, b: Int?) = a != null && b != null && a == b + +fun equals4(a: Int?, b: Int?) = if (a is Int && b is Int) a == b else null!! + +fun equals5(a: Any?, b: Any?) = if (a is Int && b is Int) a == b else null!! + +fun less3(a: Int?, b: Int?) = a != null && b != null && a < b + +fun less4(a: Int?, b: Int?) = if (a is Int && b is Int) a < b else true + +fun less5(a: Any?, b: Any?) = if (a is Int && b is Int) a < b else true + +// 3 Intrinsics\.areEqual +// 3 Intrinsics\.compare +// for compare: +// 3 IF_ICMPGE diff --git a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/longSmartCast.kt b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/longSmartCast.kt new file mode 100644 index 00000000000..815ea69d576 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/longSmartCast.kt @@ -0,0 +1,16 @@ +fun equals3(a: Long?, b: Long?) = a != null && b != null && a == b + +fun equals4(a: Long?, b: Long?) = if (a is Long && b is Long) a == b else null!! + +fun equals5(a: Any?, b: Any?) = if (a is Long && b is Long) a == b else null!! + +fun less3(a: Long?, b: Long?) = a != null && b != null && a < b + +fun less4(a: Long?, b: Long?) = if (a is Long && b is Long) a < b else true + +fun less5(a: Any?, b: Any?) = if (a is Long && b is Long) a < b else true + +// 3 Intrinsics\.areEqual +// 3 Intrinsics\.compare +// for compare: +// 3 IF_ICMPGE diff --git a/compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast.kt b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast.kt new file mode 100644 index 00000000000..b6c36c8e754 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast.kt @@ -0,0 +1,16 @@ +fun equals3(a: Short?, b: Short?) = a != null && b != null && a == b + +fun equals4(a: Short?, b: Short?) = if (a is Short && b is Short) a == b else null!! + +fun equals5(a: Any?, b: Any?) = if (a is Short && b is Short) a == b else null!! + +fun less3(a: Short?, b: Short?) = a != null && b != null && a < b + +fun less4(a: Short?, b: Short?) = if (a is Short && b is Short) a < b else true + +fun less5(a: Any?, b: Any?) = if (a is Short && b is Short) a < b else true + +// 3 Intrinsics\.areEqual +// 3 Intrinsics\.compare +// for compare: +// 3 IF_ICMPGE diff --git a/compiler/testData/codegen/light-analysis/ieee754/anyToReal.txt b/compiler/testData/codegen/light-analysis/ieee754/anyToReal.txt new file mode 100644 index 00000000000..00b4e2f6095 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/anyToReal.txt @@ -0,0 +1,3 @@ +public final class AnyToRealKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/comparableTypeCast.txt b/compiler/testData/codegen/light-analysis/ieee754/comparableTypeCast.txt new file mode 100644 index 00000000000..73f1897bf29 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/comparableTypeCast.txt @@ -0,0 +1,3 @@ +public final class ComparableTypeCastKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/dataClass.txt b/compiler/testData/codegen/light-analysis/ieee754/dataClass.txt new file mode 100644 index 00000000000..db41284cca9 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/dataClass.txt @@ -0,0 +1,19 @@ +public final class DataClassKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} + + +public final class Test { + private final field z1: double + private final @org.jetbrains.annotations.Nullable field z2: java.lang.Double + public method (p0: double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): void + public final method component1(): double + public final @org.jetbrains.annotations.Nullable method component2(): java.lang.Double + public synthetic static method copy$default(p0: Test, p1: double, p2: java.lang.Double, p3: int, p4: java.lang.Object): Test + public final @org.jetbrains.annotations.NotNull method copy(p0: double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): Test + public method equals(p0: java.lang.Object): boolean + public final method getZ1(): double + public final @org.jetbrains.annotations.Nullable method getZ2(): java.lang.Double + public method hashCode(): int + public method toString(): java.lang.String +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/equalsDouble.txt b/compiler/testData/codegen/light-analysis/ieee754/equalsDouble.txt new file mode 100644 index 00000000000..bbaeb46bf79 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/equalsDouble.txt @@ -0,0 +1,8 @@ +public final class EqualsDoubleKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static method equals1(p0: double, p1: double): boolean + public final static method equals2(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method equals3(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method equals4(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method equals5(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): boolean +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/equalsFloat.txt b/compiler/testData/codegen/light-analysis/ieee754/equalsFloat.txt new file mode 100644 index 00000000000..da88eb1d7d9 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/equalsFloat.txt @@ -0,0 +1,8 @@ +public final class EqualsFloatKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static method equals1(p0: float, p1: float): boolean + public final static method equals2(@org.jetbrains.annotations.Nullable p0: java.lang.Float, @org.jetbrains.annotations.Nullable p1: java.lang.Float): boolean + public final static method equals3(@org.jetbrains.annotations.Nullable p0: java.lang.Float, @org.jetbrains.annotations.Nullable p1: java.lang.Float): boolean + public final static method equals4(@org.jetbrains.annotations.Nullable p0: java.lang.Float, @org.jetbrains.annotations.Nullable p1: java.lang.Float): boolean + public final static method equals5(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): boolean +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/equalsNullableDouble.txt b/compiler/testData/codegen/light-analysis/ieee754/equalsNullableDouble.txt new file mode 100644 index 00000000000..f2a1b918239 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/equalsNullableDouble.txt @@ -0,0 +1,11 @@ +public final class EqualsNullableDoubleKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static method equals1(p0: double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method equals2(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method equals3(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method equals4(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method equals5(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): boolean + public final static method equals6(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): boolean + public final static method equals7(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method equals8(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): boolean +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/explicitCompareCall.txt b/compiler/testData/codegen/light-analysis/ieee754/explicitCompareCall.txt new file mode 100644 index 00000000000..9c528e045fb --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/explicitCompareCall.txt @@ -0,0 +1,8 @@ +public final class ExplicitCompareCallKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static method less1(p0: double, p1: double): boolean + public final static method less2(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method less3(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method less4(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method less5(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): boolean +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/explicitEqualsCall.txt b/compiler/testData/codegen/light-analysis/ieee754/explicitEqualsCall.txt new file mode 100644 index 00000000000..1e60b3ac4dc --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/explicitEqualsCall.txt @@ -0,0 +1,7 @@ +public final class ExplicitEqualsCallKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static method equals1(p0: double, p1: double): boolean + public final static method equals2(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method equals3(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method equals4(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/generic.txt b/compiler/testData/codegen/light-analysis/ieee754/generic.txt new file mode 100644 index 00000000000..c9a46713c09 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/generic.txt @@ -0,0 +1,12 @@ +public final class BKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} + + +public final class Foo { + private final field minus0: java.lang.Object + private final field plus0: java.lang.Object + public method (p0: java.lang.Object, p1: java.lang.Object): void + public final method getMinus0(): java.lang.Object + public final method getPlus0(): java.lang.Object +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/greaterDouble.txt b/compiler/testData/codegen/light-analysis/ieee754/greaterDouble.txt new file mode 100644 index 00000000000..ac717d23aa6 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/greaterDouble.txt @@ -0,0 +1,8 @@ +public final class GreaterDoubleKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static method greater1(p0: double, p1: double): boolean + public final static method greater2(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method greater3(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method greater4(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method greater5(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): boolean +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/greaterFloat.txt b/compiler/testData/codegen/light-analysis/ieee754/greaterFloat.txt new file mode 100644 index 00000000000..e511c01c0ad --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/greaterFloat.txt @@ -0,0 +1,8 @@ +public final class GreaterFloatKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static method greater1(p0: float, p1: float): boolean + public final static method greater2(@org.jetbrains.annotations.Nullable p0: java.lang.Float, @org.jetbrains.annotations.Nullable p1: java.lang.Float): boolean + public final static method greater3(@org.jetbrains.annotations.Nullable p0: java.lang.Float, @org.jetbrains.annotations.Nullable p1: java.lang.Float): boolean + public final static method greater4(@org.jetbrains.annotations.Nullable p0: java.lang.Float, @org.jetbrains.annotations.Nullable p1: java.lang.Float): boolean + public final static method greater5(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): boolean +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/inline.txt b/compiler/testData/codegen/light-analysis/ieee754/inline.txt new file mode 100644 index 00000000000..5e312b15e08 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/inline.txt @@ -0,0 +1,11 @@ +public final class InlineKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static method equals(@org.jetbrains.annotations.NotNull p0: java.lang.Comparable, @org.jetbrains.annotations.NotNull p1: java.lang.Comparable): boolean + public final static method equals754(p0: double, p1: double): boolean + public final static method equalsGeneric(@org.jetbrains.annotations.NotNull p0: java.lang.Comparable, p1: double): boolean + private final static method equalsReified(p0: java.lang.Comparable, p1: java.lang.Comparable): boolean + public final static method less(@org.jetbrains.annotations.NotNull p0: java.lang.Comparable, p1: double): boolean + public final static method less754(p0: double, p1: double): boolean + public final static method lessGeneric(@org.jetbrains.annotations.NotNull p0: java.lang.Comparable, p1: double): boolean + private final static method lessReified(p0: java.lang.Comparable, p1: double): boolean +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/lessDouble.txt b/compiler/testData/codegen/light-analysis/ieee754/lessDouble.txt new file mode 100644 index 00000000000..38667f136c5 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/lessDouble.txt @@ -0,0 +1,8 @@ +public final class LessDoubleKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static method less1(p0: double, p1: double): boolean + public final static method less2(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method less3(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method less4(@org.jetbrains.annotations.Nullable p0: java.lang.Double, @org.jetbrains.annotations.Nullable p1: java.lang.Double): boolean + public final static method less5(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): boolean +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/lessFloat.txt b/compiler/testData/codegen/light-analysis/ieee754/lessFloat.txt new file mode 100644 index 00000000000..5ec6126df27 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/lessFloat.txt @@ -0,0 +1,8 @@ +public final class LessFloatKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static method less1(p0: float, p1: float): boolean + public final static method less2(@org.jetbrains.annotations.Nullable p0: java.lang.Float, @org.jetbrains.annotations.Nullable p1: java.lang.Float): boolean + public final static method less3(@org.jetbrains.annotations.Nullable p0: java.lang.Float, @org.jetbrains.annotations.Nullable p1: java.lang.Float): boolean + public final static method less4(@org.jetbrains.annotations.Nullable p0: java.lang.Float, @org.jetbrains.annotations.Nullable p1: java.lang.Float): boolean + public final static method less5(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Object): boolean +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/nullableAnyToReal.txt b/compiler/testData/codegen/light-analysis/ieee754/nullableAnyToReal.txt new file mode 100644 index 00000000000..2d78a7f22eb --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/nullableAnyToReal.txt @@ -0,0 +1,3 @@ +public final class NullableAnyToRealKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/safeCall.txt b/compiler/testData/codegen/light-analysis/ieee754/safeCall.txt new file mode 100644 index 00000000000..96027514a75 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/safeCall.txt @@ -0,0 +1,3 @@ +public final class SafeCallKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/smartCastToDifferentTypes.txt b/compiler/testData/codegen/light-analysis/ieee754/smartCastToDifferentTypes.txt new file mode 100644 index 00000000000..103ace9e7df --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/smartCastToDifferentTypes.txt @@ -0,0 +1,3 @@ +public final class SmartCastToDifferentTypesKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/when.txt b/compiler/testData/codegen/light-analysis/ieee754/when.txt new file mode 100644 index 00000000000..5870ec795b5 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/when.txt @@ -0,0 +1,3 @@ +public final class WhenKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} diff --git a/compiler/testData/codegen/light-analysis/ieee754/whenNoSubject.txt b/compiler/testData/codegen/light-analysis/ieee754/whenNoSubject.txt new file mode 100644 index 00000000000..88a20babde6 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/ieee754/whenNoSubject.txt @@ -0,0 +1,3 @@ +public final class WhenNoSubjectKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index f7de3f8137d..410ca6545af 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -7761,6 +7761,129 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes } } + @TestMetadata("compiler/testData/codegen/box/ieee754") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Ieee754 extends AbstractIrBlackBoxCodegenTest { + public void testAllFilesPresentInIeee754() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ieee754"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("anyToReal.kt") + public void testAnyToReal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/anyToReal.kt"); + doTest(fileName); + } + + @TestMetadata("comparableTypeCast.kt") + public void testComparableTypeCast() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/comparableTypeCast.kt"); + doTest(fileName); + } + + @TestMetadata("dataClass.kt") + public void testDataClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/dataClass.kt"); + doTest(fileName); + } + + @TestMetadata("equalsDouble.kt") + public void testEqualsDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/equalsDouble.kt"); + doTest(fileName); + } + + @TestMetadata("equalsFloat.kt") + public void testEqualsFloat() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/equalsFloat.kt"); + doTest(fileName); + } + + @TestMetadata("equalsNullableDouble.kt") + public void testEqualsNullableDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/equalsNullableDouble.kt"); + doTest(fileName); + } + + @TestMetadata("explicitCompareCall.kt") + public void testExplicitCompareCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/explicitCompareCall.kt"); + doTest(fileName); + } + + @TestMetadata("explicitEqualsCall.kt") + public void testExplicitEqualsCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/explicitEqualsCall.kt"); + doTest(fileName); + } + + @TestMetadata("generic.kt") + public void testGeneric() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/generic.kt"); + doTest(fileName); + } + + @TestMetadata("greaterDouble.kt") + public void testGreaterDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/greaterDouble.kt"); + doTest(fileName); + } + + @TestMetadata("greaterFloat.kt") + public void testGreaterFloat() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/greaterFloat.kt"); + doTest(fileName); + } + + @TestMetadata("inline.kt") + public void testInline() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/inline.kt"); + doTest(fileName); + } + + @TestMetadata("lessDouble.kt") + public void testLessDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/lessDouble.kt"); + doTest(fileName); + } + + @TestMetadata("lessFloat.kt") + public void testLessFloat() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/lessFloat.kt"); + doTest(fileName); + } + + @TestMetadata("nullableAnyToReal.kt") + public void testNullableAnyToReal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/nullableAnyToReal.kt"); + doTest(fileName); + } + + @TestMetadata("safeCall.kt") + public void testSafeCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/safeCall.kt"); + doTest(fileName); + } + + @TestMetadata("smartCastToDifferentTypes.kt") + public void testSmartCastToDifferentTypes() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/smartCastToDifferentTypes.kt"); + doTest(fileName); + } + + @TestMetadata("when.kt") + public void testWhen() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/when.kt"); + doTest(fileName); + } + + @TestMetadata("whenNoSubject.kt") + public void testWhenNoSubject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/whenNoSubject.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/increment") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxAgainstJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxAgainstJavaCodegenTestGenerated.java index 7f441f558e1..ae14dd1d35d 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxAgainstJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxAgainstJavaCodegenTestGenerated.java @@ -291,6 +291,63 @@ public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxAga } } + @TestMetadata("compiler/testData/codegen/boxAgainstJava/ieee754") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Ieee754 extends AbstractBlackBoxAgainstJavaCodegenTest { + public void testAllFilesPresentInIeee754() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxAgainstJava/ieee754"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("anyToReal.kt") + public void testAnyToReal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/ieee754/anyToReal.kt"); + doTest(fileName); + } + + @TestMetadata("comparableTypeCast.kt") + public void testComparableTypeCast() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/ieee754/comparableTypeCast.kt"); + doTest(fileName); + } + + @TestMetadata("double.kt") + public void testDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/ieee754/double.kt"); + doTest(fileName); + } + + @TestMetadata("explicitCompareCall.kt") + public void testExplicitCompareCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/ieee754/explicitCompareCall.kt"); + doTest(fileName); + } + + @TestMetadata("explicitEqualsCall.kt") + public void testExplicitEqualsCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/ieee754/explicitEqualsCall.kt"); + doTest(fileName); + } + + @TestMetadata("float.kt") + public void testFloat() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/ieee754/float.kt"); + doTest(fileName); + } + + @TestMetadata("generic.kt") + public void testGeneric() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/ieee754/generic.kt"); + doTest(fileName); + } + + @TestMetadata("nullableAnyToReal.kt") + public void testNullableAnyToReal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/ieee754/nullableAnyToReal.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/boxAgainstJava/innerClass") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 7841ca3ee44..50d5da0d54f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -7761,6 +7761,129 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } } + @TestMetadata("compiler/testData/codegen/box/ieee754") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Ieee754 extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInIeee754() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ieee754"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("anyToReal.kt") + public void testAnyToReal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/anyToReal.kt"); + doTest(fileName); + } + + @TestMetadata("comparableTypeCast.kt") + public void testComparableTypeCast() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/comparableTypeCast.kt"); + doTest(fileName); + } + + @TestMetadata("dataClass.kt") + public void testDataClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/dataClass.kt"); + doTest(fileName); + } + + @TestMetadata("equalsDouble.kt") + public void testEqualsDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/equalsDouble.kt"); + doTest(fileName); + } + + @TestMetadata("equalsFloat.kt") + public void testEqualsFloat() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/equalsFloat.kt"); + doTest(fileName); + } + + @TestMetadata("equalsNullableDouble.kt") + public void testEqualsNullableDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/equalsNullableDouble.kt"); + doTest(fileName); + } + + @TestMetadata("explicitCompareCall.kt") + public void testExplicitCompareCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/explicitCompareCall.kt"); + doTest(fileName); + } + + @TestMetadata("explicitEqualsCall.kt") + public void testExplicitEqualsCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/explicitEqualsCall.kt"); + doTest(fileName); + } + + @TestMetadata("generic.kt") + public void testGeneric() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/generic.kt"); + doTest(fileName); + } + + @TestMetadata("greaterDouble.kt") + public void testGreaterDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/greaterDouble.kt"); + doTest(fileName); + } + + @TestMetadata("greaterFloat.kt") + public void testGreaterFloat() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/greaterFloat.kt"); + doTest(fileName); + } + + @TestMetadata("inline.kt") + public void testInline() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/inline.kt"); + doTest(fileName); + } + + @TestMetadata("lessDouble.kt") + public void testLessDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/lessDouble.kt"); + doTest(fileName); + } + + @TestMetadata("lessFloat.kt") + public void testLessFloat() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/lessFloat.kt"); + doTest(fileName); + } + + @TestMetadata("nullableAnyToReal.kt") + public void testNullableAnyToReal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/nullableAnyToReal.kt"); + doTest(fileName); + } + + @TestMetadata("safeCall.kt") + public void testSafeCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/safeCall.kt"); + doTest(fileName); + } + + @TestMetadata("smartCastToDifferentTypes.kt") + public void testSmartCastToDifferentTypes() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/smartCastToDifferentTypes.kt"); + doTest(fileName); + } + + @TestMetadata("when.kt") + public void testWhen() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/when.kt"); + doTest(fileName); + } + + @TestMetadata("whenNoSubject.kt") + public void testWhenNoSubject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/whenNoSubject.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/increment") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 77943bfc1ee..e9344bd067a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -1215,6 +1215,51 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { } } + @TestMetadata("compiler/testData/codegen/bytecodeText/intrinsicsCompare") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class IntrinsicsCompare extends AbstractBytecodeTextTest { + public void testAllFilesPresentInIntrinsicsCompare() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeText/intrinsicsCompare"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("byteSmartCast.kt") + public void testByteSmartCast() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/intrinsicsCompare/byteSmartCast.kt"); + doTest(fileName); + } + + @TestMetadata("charSmartCast.kt") + public void testCharSmartCast() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/intrinsicsCompare/charSmartCast.kt"); + doTest(fileName); + } + + @TestMetadata("differentTypes.kt") + public void testDifferentTypes() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/intrinsicsCompare/differentTypes.kt"); + doTest(fileName); + } + + @TestMetadata("intSmartCast.kt") + public void testIntSmartCast() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/intrinsicsCompare/intSmartCast.kt"); + doTest(fileName); + } + + @TestMetadata("longSmartCast.kt") + public void testLongSmartCast() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/intrinsicsCompare/longSmartCast.kt"); + doTest(fileName); + } + + @TestMetadata("shortSmartCast.kt") + public void testShortSmartCast() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/intrinsicsCompare/shortSmartCast.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/bytecodeText/jackAndJill") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java index 55aa7677260..d22976ef59d 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java @@ -7761,6 +7761,129 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis } } + @TestMetadata("compiler/testData/codegen/box/ieee754") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Ieee754 extends AbstractLightAnalysisModeCodegenTest { + public void testAllFilesPresentInIeee754() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ieee754"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("anyToReal.kt") + public void testAnyToReal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/anyToReal.kt"); + doTest(fileName); + } + + @TestMetadata("comparableTypeCast.kt") + public void testComparableTypeCast() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/comparableTypeCast.kt"); + doTest(fileName); + } + + @TestMetadata("dataClass.kt") + public void testDataClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/dataClass.kt"); + doTest(fileName); + } + + @TestMetadata("equalsDouble.kt") + public void testEqualsDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/equalsDouble.kt"); + doTest(fileName); + } + + @TestMetadata("equalsFloat.kt") + public void testEqualsFloat() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/equalsFloat.kt"); + doTest(fileName); + } + + @TestMetadata("equalsNullableDouble.kt") + public void testEqualsNullableDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/equalsNullableDouble.kt"); + doTest(fileName); + } + + @TestMetadata("explicitCompareCall.kt") + public void testExplicitCompareCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/explicitCompareCall.kt"); + doTest(fileName); + } + + @TestMetadata("explicitEqualsCall.kt") + public void testExplicitEqualsCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/explicitEqualsCall.kt"); + doTest(fileName); + } + + @TestMetadata("generic.kt") + public void testGeneric() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/generic.kt"); + doTest(fileName); + } + + @TestMetadata("greaterDouble.kt") + public void testGreaterDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/greaterDouble.kt"); + doTest(fileName); + } + + @TestMetadata("greaterFloat.kt") + public void testGreaterFloat() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/greaterFloat.kt"); + doTest(fileName); + } + + @TestMetadata("inline.kt") + public void testInline() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/inline.kt"); + doTest(fileName); + } + + @TestMetadata("lessDouble.kt") + public void testLessDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/lessDouble.kt"); + doTest(fileName); + } + + @TestMetadata("lessFloat.kt") + public void testLessFloat() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/lessFloat.kt"); + doTest(fileName); + } + + @TestMetadata("nullableAnyToReal.kt") + public void testNullableAnyToReal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/nullableAnyToReal.kt"); + doTest(fileName); + } + + @TestMetadata("safeCall.kt") + public void testSafeCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/safeCall.kt"); + doTest(fileName); + } + + @TestMetadata("smartCastToDifferentTypes.kt") + public void testSmartCastToDifferentTypes() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/smartCastToDifferentTypes.kt"); + doTest(fileName); + } + + @TestMetadata("when.kt") + public void testWhen() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/when.kt"); + doTest(fileName); + } + + @TestMetadata("whenNoSubject.kt") + public void testWhenNoSubject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/whenNoSubject.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/increment") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java index 530202f7e76..fa90f446a54 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java @@ -931,11 +931,19 @@ public abstract class KotlinBuiltIns { } public static boolean isFloat(@NotNull KotlinType type) { - return isConstructedFromGivenClassAndNotNullable(type, FQ_NAMES._float); + return isFloatOrNullableFloat(type) && !type.isMarkedNullable(); + } + + public static boolean isFloatOrNullableFloat(@NotNull KotlinType type) { + return isConstructedFromGivenClass(type, FQ_NAMES._float); } public static boolean isDouble(@NotNull KotlinType type) { - return isConstructedFromGivenClassAndNotNullable(type, FQ_NAMES._double); + return isDoubleOrNullableDouble(type) && !type.isMarkedNullable(); + } + + public static boolean isDoubleOrNullableDouble(@NotNull KotlinType type) { + return isConstructedFromGivenClass(type, FQ_NAMES._double); } private static boolean isConstructedFromGivenClassAndNotNullable(@NotNull KotlinType type, @NotNull FqNameUnsafe fqName) { diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 316380cc34d..476b2362373 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -9328,6 +9328,171 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/ieee754") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Ieee754 extends AbstractJsCodegenBoxTest { + public void testAllFilesPresentInIeee754() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/ieee754"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("anyToReal.kt") + public void testAnyToReal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/anyToReal.kt"); + doTest(fileName); + } + + @TestMetadata("comparableTypeCast.kt") + public void testComparableTypeCast() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/comparableTypeCast.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("dataClass.kt") + public void testDataClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/dataClass.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("equalsDouble.kt") + public void testEqualsDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/equalsDouble.kt"); + doTest(fileName); + } + + @TestMetadata("equalsFloat.kt") + public void testEqualsFloat() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/equalsFloat.kt"); + doTest(fileName); + } + + @TestMetadata("equalsNullableDouble.kt") + public void testEqualsNullableDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/equalsNullableDouble.kt"); + doTest(fileName); + } + + @TestMetadata("explicitCompareCall.kt") + public void testExplicitCompareCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/explicitCompareCall.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("explicitEqualsCall.kt") + public void testExplicitEqualsCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/explicitEqualsCall.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("generic.kt") + public void testGeneric() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/generic.kt"); + doTest(fileName); + } + + @TestMetadata("greaterDouble.kt") + public void testGreaterDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/greaterDouble.kt"); + doTest(fileName); + } + + @TestMetadata("greaterFloat.kt") + public void testGreaterFloat() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/greaterFloat.kt"); + doTest(fileName); + } + + @TestMetadata("inline.kt") + public void testInline() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/inline.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("lessDouble.kt") + public void testLessDouble() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/lessDouble.kt"); + doTest(fileName); + } + + @TestMetadata("lessFloat.kt") + public void testLessFloat() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/lessFloat.kt"); + doTest(fileName); + } + + @TestMetadata("nullableAnyToReal.kt") + public void testNullableAnyToReal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/nullableAnyToReal.kt"); + doTest(fileName); + } + + @TestMetadata("safeCall.kt") + public void testSafeCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/safeCall.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("smartCastToDifferentTypes.kt") + public void testSmartCastToDifferentTypes() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/smartCastToDifferentTypes.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("when.kt") + public void testWhen() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/when.kt"); + doTest(fileName); + } + + @TestMetadata("whenNoSubject.kt") + public void testWhenNoSubject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ieee754/whenNoSubject.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/increment") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)