diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index ee14a1a3ed7..c711351a0a2 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -289,7 +289,9 @@ class ExpressionCodegen( val info = BlockInfo(data) // Force materialization to avoid reading from out-of-scope variables. return super.visitBlock(expression, info).materialized.also { - writeLocalVariablesInTable(info, markNewLabel()) + if (info.variables.isNotEmpty()) { + writeLocalVariablesInTable(info, markNewLabel()) + } } } diff --git a/compiler/testData/codegen/bytecodeText/disabledOptimizations/noUnusedLabel.kt b/compiler/testData/codegen/bytecodeText/disabledOptimizations/noUnusedLabel.kt new file mode 100644 index 00000000000..8fd1433dd2b --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/disabledOptimizations/noUnusedLabel.kt @@ -0,0 +1,16 @@ +// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_OPTIMIZATION + +fun bar() {} + +fun foo(a: Boolean) { if (a) { foo(a) } } + +// method start +// 5 L0 + +//return +// 3 L1 + +// method end +// 2 L2 + +// 0 L3 diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 61073a818cf..555fc6d1498 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -1650,6 +1650,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { public void testNoUnitInstanceOnVoidFunctionCall() throws Exception { runTest("compiler/testData/codegen/bytecodeText/disabledOptimizations/noUnitInstanceOnVoidFunctionCall.kt"); } + + @TestMetadata("noUnusedLabel.kt") + public void testNoUnusedLabel() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/disabledOptimizations/noUnusedLabel.kt"); + } } @TestMetadata("compiler/testData/codegen/bytecodeText/enum") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java index 592aa87a8c7..d6834e93c5f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java @@ -1605,6 +1605,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { public void testNoUnitInstanceOnVoidFunctionCall() throws Exception { runTest("compiler/testData/codegen/bytecodeText/disabledOptimizations/noUnitInstanceOnVoidFunctionCall.kt"); } + + @TestMetadata("noUnusedLabel.kt") + public void testNoUnusedLabel() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/disabledOptimizations/noUnusedLabel.kt"); + } } @TestMetadata("compiler/testData/codegen/bytecodeText/enum")