diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/RedundantLocalsEliminationMethodTransformer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/RedundantLocalsEliminationMethodTransformer.kt index ac7ae83c121..a563df6bc68 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/RedundantLocalsEliminationMethodTransformer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/RedundantLocalsEliminationMethodTransformer.kt @@ -136,7 +136,11 @@ private class UnitSourceInterpreter(private val localVariables: Set) : Basi override fun merge(value1: BasicValue?, value2: BasicValue?): BasicValue? = if (value1 is UnitValue && value2 is UnitValue) { - UnitValue(value1.insns.union(value2.insns)) + val newValue = UnitValue(value1.insns.union(value2.insns)) + if (newValue.insns.any { it in unspillableUnitValues }) { + markUnspillable(newValue) + } + newValue } else { // Mark unit values as unspillable if we merge them with non-unit values here. // This is conservative since the value could turn out to be unused. diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 22e2171c965..3a15526d9e5 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -8997,6 +8997,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT public void testRefinedIntTypesAnalysis() throws Exception { runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt"); } + + @TestMetadata("safeCallElvis.kt") + public void testSafeCallElvis() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.kt"); + } } } diff --git a/compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.kt b/compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.kt new file mode 100644 index 00000000000..b051207068b --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.kt @@ -0,0 +1,32 @@ +// WITH_RUNTIME + +import kotlin.coroutines.* + +var res: String = "FAIL" + +class Log { + fun error(message: Any?) { + res = message as String + } +} + +private val log = Log() + +class C { + fun method() {} +} + +fun df(t: T, r: suspend (T) -> Unit) { + r.startCoroutine(t, Continuation(EmptyCoroutineContext) {}) +} + +fun foo(s: String, c: C?) { + df(s) { + c?.method() ?: log.error(it) + } +} + +fun box(): String { + foo("OK", null) + return res +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index a118b4ccc18..32fd7f22933 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -10392,6 +10392,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { public void testRefinedIntTypesAnalysis() throws Exception { runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt"); } + + @TestMetadata("safeCallElvis.kt") + public void testSafeCallElvis() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.kt"); + } } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index a1bdcd49624..b25e36f18f0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -10392,6 +10392,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes public void testRefinedIntTypesAnalysis() throws Exception { runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt"); } + + @TestMetadata("safeCallElvis.kt") + public void testSafeCallElvis() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.kt"); + } } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index c07cb2cab4a..732fddfe1fc 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -8997,6 +8997,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes public void testRefinedIntTypesAnalysis() throws Exception { runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt"); } + + @TestMetadata("safeCallElvis.kt") + public void testSafeCallElvis() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.kt"); + } } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index 093c8ce7af9..d75de2fb3db 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -7622,6 +7622,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes public void testRefinedIntTypesAnalysis() throws Exception { runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt"); } + + @TestMetadata("safeCallElvis.kt") + public void testSafeCallElvis() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.kt"); + } } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index fe88e653616..018288b72c7 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -7622,6 +7622,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { public void testRefinedIntTypesAnalysis() throws Exception { runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt"); } + + @TestMetadata("safeCallElvis.kt") + public void testSafeCallElvis() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.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 fa1b3c1b08c..3f0791e7d79 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 @@ -7622,6 +7622,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { public void testRefinedIntTypesAnalysis() throws Exception { runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt"); } + + @TestMetadata("safeCallElvis.kt") + public void testSafeCallElvis() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/safeCallElvis.kt"); + } } } @@ -21419,6 +21424,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/ranges/unsigned/expression/emptyRange.kt"); } + @TestMetadata("inexactDownToMinValue.kt") + public void testInexactDownToMinValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/expression/inexactDownToMinValue.kt"); + } + @TestMetadata("inexactSteppedDownTo.kt") public void testInexactSteppedDownTo() throws Exception { runTest("compiler/testData/codegen/box/ranges/unsigned/expression/inexactSteppedDownTo.kt"); @@ -21464,11 +21474,21 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/ranges/unsigned/expression/openRange.kt"); } + @TestMetadata("overflowZeroDownToMaxValue.kt") + public void testOverflowZeroDownToMaxValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/expression/overflowZeroDownToMaxValue.kt"); + } + @TestMetadata("overflowZeroToMinValue.kt") public void testOverflowZeroToMinValue() throws Exception { runTest("compiler/testData/codegen/box/ranges/unsigned/expression/overflowZeroToMinValue.kt"); } + @TestMetadata("progressionDownToMinValue.kt") + public void testProgressionDownToMinValue() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/expression/progressionDownToMinValue.kt"); + } + @TestMetadata("progressionMaxValueMinusTwoToMaxValue.kt") public void testProgressionMaxValueMinusTwoToMaxValue() throws Exception { runTest("compiler/testData/codegen/box/ranges/unsigned/expression/progressionMaxValueMinusTwoToMaxValue.kt");