diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index a6e5643b723..5f5469c2868 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -3680,8 +3680,17 @@ public class ExpressionCodegen extends KtVisitor impleme } private StackValue genCmpWithZero(KtExpression exp, IElementType opToken, @Nullable StackValue pregeneratedExpr) { + StackValue argument; + if (pregeneratedExpr == null) { + KotlinType kotlinType = kotlinType(exp); + assert kotlinType != null : "No KotlinType for expression " + exp.getText(); + argument = genLazy(exp, asmType(kotlinType), kotlinType); + } + else { + argument = pregeneratedExpr; + } return StackValue.compareIntWithZero( - pregeneratedExpr != null ? pregeneratedExpr : gen(exp), + argument, (KtTokens.EQEQ == opToken || KtTokens.EQEQEQ == opToken) ? IFNE : IFEQ ); } diff --git a/compiler/testData/codegen/box/unsignedTypes/boxedUnsignedEqualsZero.kt b/compiler/testData/codegen/box/unsignedTypes/boxedUnsignedEqualsZero.kt new file mode 100644 index 00000000000..2d6d2fa3aa9 --- /dev/null +++ b/compiler/testData/codegen/box/unsignedTypes/boxedUnsignedEqualsZero.kt @@ -0,0 +1,36 @@ +// WITH_UNSIGNED +// IGNORE_BACKEND: JVM_IR + +fun isZeroUInt(n: UInt?) = n!! == 0U +fun isZeroUInt2(n: UInt?) = 0U == n!! +fun isZeroULong(n: ULong?) = n!! == 0UL +fun isZeroULong2(n: ULong?) = 0UL == n!! + +fun isNullUInt(n: UInt?) = n == null +fun isNullUInt2(n: UInt?) = null == n +fun isNullULong(n: ULong?) = n == null +fun isNullULong2(n: ULong?) = null == n + +fun box(): String { + if (isZeroUInt(1U)) throw AssertionError() + if (isZeroUInt2(1U)) throw AssertionError() + if (!isZeroUInt(0U)) throw AssertionError() + if (!isZeroUInt2(0U)) throw AssertionError() + + if (isZeroULong(1UL)) throw AssertionError() + if (isZeroULong2(1UL)) throw AssertionError() + if (!isZeroULong(0UL)) throw AssertionError() + if (!isZeroULong2(0UL)) throw AssertionError() + + if (isNullUInt(1U)) throw AssertionError() + if (isNullUInt2(1U)) throw AssertionError() + if (!isNullUInt(null)) throw AssertionError() + if (!isNullUInt2(null)) throw AssertionError() + + if (isNullULong(1UL)) throw AssertionError() + if (isNullULong2(1UL)) throw AssertionError() + if (!isNullULong(null)) throw AssertionError() + if (!isNullULong2(null)) throw AssertionError() + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/unsignedTypes/nullableUnsignedEqualsLiteral.kt b/compiler/testData/codegen/box/unsignedTypes/nullableUnsignedEqualsLiteral.kt index 6fd91aa8668..fe8c1f5a98c 100644 --- a/compiler/testData/codegen/box/unsignedTypes/nullableUnsignedEqualsLiteral.kt +++ b/compiler/testData/codegen/box/unsignedTypes/nullableUnsignedEqualsLiteral.kt @@ -2,6 +2,7 @@ // IGNORE_BACKEND: JVM_IR fun isZeroUInt(n: UInt?) = n == 0U +fun isZeroUInt2(n: UInt?): Boolean = n != null && n == 0u fun isZeroULong(n: ULong?) = n == 0UL fun box(): String { @@ -9,6 +10,10 @@ fun box(): String { if (isZeroUInt(1U)) throw AssertionError() if (!isZeroUInt(0U)) throw AssertionError() + if (isZeroUInt2(null)) throw AssertionError() + if (isZeroUInt2(1U)) throw AssertionError() + if (!isZeroUInt2(0U)) throw AssertionError() + if (isZeroULong(null)) throw AssertionError() if (isZeroULong(1UL)) throw AssertionError() if (!isZeroULong(0UL)) throw AssertionError() diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index bd0180fe5fb..8ac45d6036f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -23877,6 +23877,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/unsignedTypes/boxConstValOfUnsignedType.kt"); } + @TestMetadata("boxedUnsignedEqualsZero.kt") + public void testBoxedUnsignedEqualsZero() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/boxedUnsignedEqualsZero.kt"); + } + @TestMetadata("checkBasicUnsignedLiterals.kt") public void testCheckBasicUnsignedLiterals() throws Exception { runTest("compiler/testData/codegen/box/unsignedTypes/checkBasicUnsignedLiterals.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 03165328fce..3e7b4e26124 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -23877,6 +23877,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/unsignedTypes/boxConstValOfUnsignedType.kt"); } + @TestMetadata("boxedUnsignedEqualsZero.kt") + public void testBoxedUnsignedEqualsZero() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/boxedUnsignedEqualsZero.kt"); + } + @TestMetadata("checkBasicUnsignedLiterals.kt") public void testCheckBasicUnsignedLiterals() throws Exception { runTest("compiler/testData/codegen/box/unsignedTypes/checkBasicUnsignedLiterals.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 96479727422..8a2993db288 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -23882,6 +23882,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/unsignedTypes/boxConstValOfUnsignedType.kt"); } + @TestMetadata("boxedUnsignedEqualsZero.kt") + public void testBoxedUnsignedEqualsZero() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/boxedUnsignedEqualsZero.kt"); + } + @TestMetadata("checkBasicUnsignedLiterals.kt") public void testCheckBasicUnsignedLiterals() throws Exception { runTest("compiler/testData/codegen/box/unsignedTypes/checkBasicUnsignedLiterals.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java index 69546412a10..0f4430db5fe 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java @@ -21042,6 +21042,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/unsignedTypes/boxConstValOfUnsignedType.kt"); } + @TestMetadata("boxedUnsignedEqualsZero.kt") + public void testBoxedUnsignedEqualsZero() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/boxedUnsignedEqualsZero.kt"); + } + @TestMetadata("checkBasicUnsignedLiterals.kt") public void testCheckBasicUnsignedLiterals() throws Exception { runTest("compiler/testData/codegen/box/unsignedTypes/checkBasicUnsignedLiterals.kt"); 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 64d588900f5..a097aab4ada 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 @@ -22087,6 +22087,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/unsignedTypes/boxConstValOfUnsignedType.kt"); } + @TestMetadata("boxedUnsignedEqualsZero.kt") + public void testBoxedUnsignedEqualsZero() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/boxedUnsignedEqualsZero.kt"); + } + @TestMetadata("checkBasicUnsignedLiterals.kt") public void testCheckBasicUnsignedLiterals() throws Exception { runTest("compiler/testData/codegen/box/unsignedTypes/checkBasicUnsignedLiterals.kt");