diff --git a/compiler/testData/codegen/bytecodeText/defaultArguments/noEmptyArray.kt b/compiler/testData/codegen/bytecodeText/defaultArguments/noEmptyArray.kt new file mode 100644 index 00000000000..451839b7684 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/defaultArguments/noEmptyArray.kt @@ -0,0 +1,9 @@ +// IGNORE_BACKEND: JVM_IR + +// There is one ANEWARRAY instruction here, to generate the default parameter value. +fun default(vararg s: String = arrayOf("OK")) = s[0] + +// This call on the other hand shouldn't allocate anything. +fun callDefault() = default() + +// 1 ANEWARRAY \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/defaultParametersDontBox.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/defaultParametersDontBox.kt new file mode 100644 index 00000000000..625223c486f --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/defaultParametersDontBox.kt @@ -0,0 +1,23 @@ +// LANGUAGE: +InlineClasses +// IGNORE_BACKEND: JVM_IR +// FILE: classes.kt + +inline class A(val i: Int) +inline class B(val a: A) + +// FILE: test.kt + +fun defaultA(a: A = A(1)) = a.i +fun defaultB(b: B = B(A(1))) = b.a.i + +fun box(): String { + if (defaultA() != 1) return "Fail 1" + if (defaultB() != 1) return "Fail 2" + return "OK" +} + +// @TestKt.class: +// 0 B.box-impl +// 0 A.box-impl +// 0 B.unbox-impl +// 0 A.unbox-impl \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index f0e1f5a857e..a09d276ae6f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -1579,6 +1579,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { public void testMethodHandlerElimination() throws Exception { runTest("compiler/testData/codegen/bytecodeText/defaultArguments/methodHandlerElimination.kt"); } + + @TestMetadata("noEmptyArray.kt") + public void testNoEmptyArray() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/defaultArguments/noEmptyArray.kt"); + } } @TestMetadata("compiler/testData/codegen/bytecodeText/directInvoke") @@ -2448,6 +2453,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/checkOuterInlineFunctionCall.kt"); } + @TestMetadata("defaultParametersDontBox.kt") + public void testDefaultParametersDontBox() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/inlineClasses/defaultParametersDontBox.kt"); + } + @TestMetadata("equalsIsCalledByInlineClass.kt") public void testEqualsIsCalledByInlineClass() throws Exception { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/equalsIsCalledByInlineClass.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java index 6a420f47226..a4c48f5eca1 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java @@ -1534,6 +1534,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { public void testMethodHandlerElimination() throws Exception { runTest("compiler/testData/codegen/bytecodeText/defaultArguments/methodHandlerElimination.kt"); } + + @TestMetadata("noEmptyArray.kt") + public void testNoEmptyArray() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/defaultArguments/noEmptyArray.kt"); + } } @TestMetadata("compiler/testData/codegen/bytecodeText/directInvoke") @@ -2418,6 +2423,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/checkOuterInlineFunctionCall.kt"); } + @TestMetadata("defaultParametersDontBox.kt") + public void testDefaultParametersDontBox() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/inlineClasses/defaultParametersDontBox.kt"); + } + @TestMetadata("equalsIsCalledByInlineClass.kt") public void testEqualsIsCalledByInlineClass() throws Exception { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/equalsIsCalledByInlineClass.kt");