From f9506db20a4ccead0f91e2e9f4753c10317acb9c Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Wed, 21 Aug 2019 19:39:01 +0300 Subject: [PATCH] Ignore sources which are not LOADs in refinedIntTypeAnalysis #KT-33414 Fixed --- .../coroutines/refinedIntTypesAnalysis.kt | 25 +++++--------- .../varSpilling/refinedIntTypesAnalysis.kt | 34 +++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 5 +++ .../LightAnalysisModeTestGenerated.java | 5 +++ .../ir/IrBlackBoxCodegenTestGenerated.java | 5 +++ .../IrJsCodegenBoxTestGenerated.java | 5 +++ .../semantics/JsCodegenBoxTestGenerated.java | 5 +++ 7 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/refinedIntTypesAnalysis.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/refinedIntTypesAnalysis.kt index 99bb17ea49c..4c21f80a686 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/refinedIntTypesAnalysis.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/refinedIntTypesAnalysis.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.codegen.coroutines @@ -47,14 +36,16 @@ internal fun performRefinedTypeAnalysis(methodNode: MethodNode, thisName: String if (value == null) return if (expectedType.sort !in REFINED_INT_SORTS) return - value.insns.forEach { - val index = insnList.indexOf(it) + for (insn in value.insns) { + // If source is something like ICONST_0, ignore it + if (!insn.isIntLoad()) continue + val index = insnList.indexOf(insn) checkUpdatedExpectedType(expectedTypeAndSourcesByInsnIndex[index]?.first, expectedType) expectedTypeAndSourcesByInsnIndex[index] = - Pair(expectedType, - expectedTypeAndSourcesByInsnIndex[index]?.second.orEmpty() + value) + Pair(expectedType, + expectedTypeAndSourcesByInsnIndex[index]?.second.orEmpty() + value) } } diff --git a/compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt b/compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt new file mode 100644 index 00000000000..4afd452fac4 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt @@ -0,0 +1,34 @@ +// IGNORE_BACKEND: JVM_IR +// WITH_RUNTIME +// FULL_JDK + +import java.nio.ByteBuffer + +class Test { + suspend fun discardSuspend(discarded0: Long, max: Long) { + while (isClosedForRead) { + // this assignment is required + val rc = reading { + true + } + + if (!readSuspend(1)) break + } + } + + + private inline fun reading(block: () -> Boolean): Boolean { + setupStateForRead() ?: return false + try { + return block() + } finally { + } + } + + val isClosedForRead = false + + private suspend fun readSuspend(size: Int): Boolean = true + private fun setupStateForRead(): Any? = null +} + +fun box() = "OK" \ 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 cfe6f47a6f1..0ce793e1b96 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -8524,6 +8524,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { public void testNullSpilling_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/varSpilling/nullSpilling.kt", "kotlin.coroutines"); } + + @TestMetadata("refinedIntTypesAnalysis.kt") + public void testRefinedIntTypesAnalysis() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt"); + } } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 2bc5638820b..f7dbf7d5973 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -8524,6 +8524,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes public void testNullSpilling_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/varSpilling/nullSpilling.kt", "kotlin.coroutines"); } + + @TestMetadata("refinedIntTypesAnalysis.kt") + public void testRefinedIntTypesAnalysis() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt"); + } } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 7393235be63..fb6cef019fb 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -7409,6 +7409,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes public void testNullSpilling_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/varSpilling/nullSpilling.kt", "kotlin.coroutines"); } + + @TestMetadata("refinedIntTypesAnalysis.kt") + public void testRefinedIntTypesAnalysis() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.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 1fd598bd052..2a27b427eb3 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 @@ -6309,6 +6309,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { public void testNullSpilling_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/varSpilling/nullSpilling.kt", "kotlin.coroutines"); } + + @TestMetadata("refinedIntTypesAnalysis.kt") + public void testRefinedIntTypesAnalysis() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.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 f31ef3d3270..8a94906af44 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 @@ -7394,6 +7394,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { public void testNullSpilling_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/varSpilling/nullSpilling.kt", "kotlin.coroutines"); } + + @TestMetadata("refinedIntTypesAnalysis.kt") + public void testRefinedIntTypesAnalysis() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/refinedIntTypesAnalysis.kt"); + } } }