During inlining, remove POP instructions popping inlined lambdas
In cases like KT-17384, where 'break' or 'continue' happens in an argument to an inlined lambda call, fix-stack transformation sees corresponding ALOAD for lambda, and inserts corresponding POP instruction before jump. However, this ALOAD is later removed during inlining. So, we should also remove the related POP instructions.
This commit is contained in:
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.codegen.ClosureCodegen;
|
||||
import org.jetbrains.kotlin.codegen.StackValue;
|
||||
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods;
|
||||
import org.jetbrains.kotlin.codegen.optimization.FixStackWithLabelNormalizationMethodTransformer;
|
||||
import org.jetbrains.kotlin.codegen.optimization.fixStack.StackTransformationUtilsKt;
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper;
|
||||
import org.jetbrains.kotlin.utils.SmartList;
|
||||
import org.jetbrains.kotlin.utils.SmartSet;
|
||||
@@ -512,7 +513,12 @@ public class MethodInliner {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
else if (cur.getOpcode() == Opcodes.POP) {
|
||||
LambdaInfo lambda = getLambdaIfExists(MethodInlinerUtilKt.singleOrNullInsn(StackTransformationUtilsKt.top(frame)));
|
||||
if (lambda != null) {
|
||||
toDelete.add(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
AbstractInsnNode prevNode = cur;
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
fun returnNullable(): String? = null
|
||||
|
||||
inline fun Array<String>.matchAll(fn: (String) -> Unit) {
|
||||
for (string in this) {
|
||||
fn(returnNullable() ?: continue)
|
||||
}
|
||||
}
|
||||
|
||||
fun Array<String>.matchAll2(fn: (String) -> Unit) {
|
||||
matchAll(fn)
|
||||
}
|
||||
|
||||
inline fun Array<String>.matchAll3(crossinline fn: (String) -> Unit) {
|
||||
matchAll2 { fn(it) }
|
||||
}
|
||||
|
||||
fun test(a: Array<String>) {
|
||||
a.matchAll {}
|
||||
a.matchAll2 {}
|
||||
a.matchAll3 {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(arrayOf(""))
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -4630,6 +4630,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt17384.kt")
|
||||
public void testKt17384() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/kt17384.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt9022And.kt")
|
||||
public void testKt9022And() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/kt9022And.kt");
|
||||
|
||||
@@ -4630,6 +4630,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt17384.kt")
|
||||
public void testKt17384() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/kt17384.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt9022And.kt")
|
||||
public void testKt9022And() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/kt9022And.kt");
|
||||
|
||||
@@ -4630,6 +4630,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt17384.kt")
|
||||
public void testKt17384() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/kt17384.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt9022And.kt")
|
||||
public void testKt9022And() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/kt9022And.kt");
|
||||
|
||||
@@ -5339,6 +5339,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt17384.kt")
|
||||
public void testKt17384() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/kt17384.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt9022And.kt")
|
||||
public void testKt9022And() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/kt9022And.kt");
|
||||
|
||||
Reference in New Issue
Block a user