JVM_IR KT-45446 don't erase captured var if it's dead code
This commit is contained in:
committed by
TeamCityServer
parent
6bd34db725
commit
7fabc19326
+3
-1
@@ -57,6 +57,8 @@ class CapturedVarsOptimizationMethodTransformer : MethodTransformer() {
|
||||
override fun onUseAsTainted() {
|
||||
hazard = true
|
||||
}
|
||||
|
||||
fun canRewrite() = !hazard && initCallInsn != null
|
||||
}
|
||||
|
||||
private class Transformer(private val internalClassName: String, private val methodNode: MethodNode) {
|
||||
@@ -72,7 +74,7 @@ class CapturedVarsOptimizationMethodTransformer : MethodTransformer() {
|
||||
assignLocalVars(frames)
|
||||
|
||||
for (refValue in refValues) {
|
||||
if (!refValue.hazard) {
|
||||
if (refValue.canRewrite()) {
|
||||
rewriteRefValue(refValue)
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -5793,6 +5793,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt44347.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt45446.kt")
|
||||
public void testKt45446() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt45446.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("sharedSlotsWithCapturedVars.kt")
|
||||
public void testSharedSlotsWithCapturedVars() throws Exception {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: WASM
|
||||
// WASM_MUTE_REASON: EXCEPTIONS_NOT_IMPLEMENTED
|
||||
// This test checks that bytecode optimizer doesn't crash on unreachable code.
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
remove()
|
||||
}
|
||||
catch (e: Exception) {
|
||||
return e.message!!
|
||||
}
|
||||
return "Should fail with exception"
|
||||
}
|
||||
|
||||
fun remove() {
|
||||
throw Exception("OK")
|
||||
var captured = 0
|
||||
debug {
|
||||
captured = 1
|
||||
}
|
||||
}
|
||||
|
||||
private fun debug(f: () -> Unit) {
|
||||
f()
|
||||
}
|
||||
+6
@@ -5793,6 +5793,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt44347.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt45446.kt")
|
||||
public void testKt45446() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt45446.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("sharedSlotsWithCapturedVars.kt")
|
||||
public void testSharedSlotsWithCapturedVars() throws Exception {
|
||||
|
||||
+6
@@ -5793,6 +5793,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt44347.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt45446.kt")
|
||||
public void testKt45446() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt45446.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("sharedSlotsWithCapturedVars.kt")
|
||||
public void testSharedSlotsWithCapturedVars() throws Exception {
|
||||
|
||||
+5
@@ -5051,6 +5051,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt44347.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt45446.kt")
|
||||
public void testKt45446() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt45446.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sharedSlotsWithCapturedVars.kt")
|
||||
public void testSharedSlotsWithCapturedVars() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/sharedSlotsWithCapturedVars.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -4041,6 +4041,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt44347.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt45446.kt")
|
||||
public void testKt45446() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt45446.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sharedSlotsWithCapturedVars.kt")
|
||||
public void testSharedSlotsWithCapturedVars() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/sharedSlotsWithCapturedVars.kt");
|
||||
|
||||
Generated
+5
@@ -4041,6 +4041,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt44347.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt45446.kt")
|
||||
public void testKt45446() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt45446.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sharedSlotsWithCapturedVars.kt")
|
||||
public void testSharedSlotsWithCapturedVars() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/sharedSlotsWithCapturedVars.kt");
|
||||
|
||||
Generated
+5
@@ -4041,6 +4041,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt44347.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt45446.kt")
|
||||
public void testKt45446() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/kt45446.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sharedSlotsWithCapturedVars.kt")
|
||||
public void testSharedSlotsWithCapturedVars() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/closures/capturedVarsOptimization/sharedSlotsWithCapturedVars.kt");
|
||||
|
||||
Reference in New Issue
Block a user