Don't add unused label if variables are absent

This commit is contained in:
Mikhael Bogdanov
2019-11-15 14:47:46 +01:00
parent be3eed5f1f
commit 8adac2d1ea
4 changed files with 29 additions and 1 deletions
@@ -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())
}
}
}
@@ -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
@@ -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")
@@ -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")