diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt index 980395a1057..088b859bd92 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt @@ -1510,7 +1510,10 @@ internal abstract class FunctionGenerationContext( processReturns() - if (!needCleanupLandingpadAndLeaveFrame) { + // If cleanup landingpad is trivial or unused, remove it. + // It would be great not to generate it in the first place in this case, + // but this would be complicated without a major refactoring. + if (!needCleanupLandingpadAndLeaveFrame || invokeInstructions.isEmpty()) { // Replace invokes with calls and branches. invokeInstructions.forEach { functionInvokeInfo -> positionBefore(functionInvokeInfo.invokeInstruction)