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 4fc07b69956..f01bfb8d222 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 @@ -475,7 +475,7 @@ internal abstract class FunctionGenerationContext( private val entryBb = basicBlockInFunction("entry", startLocation) protected val cleanupLandingpad = basicBlockInFunction("cleanup_landingpad", endLocation) - private val needLeaveFrameInUnwindEpilogue: Boolean + protected open val needLeaveFrameInUnwindEpilogue: Boolean get() = irFunction?.annotations?.hasAnnotation(RuntimeNames.exportForCppRuntime) == true || forwardingForeignExceptionsTerminatedWith != null || irFunction?.origin == CBridgeOrigin.C_TO_KOTLIN_BRIDGE @@ -894,7 +894,7 @@ internal abstract class FunctionGenerationContext( fun extractValue(aggregate: LLVMValueRef, index: Int, name: String = ""): LLVMValueRef = LLVMBuildExtractValue(builder, aggregate, index, name)!! - fun gxxLandingpad(numClauses: Int, name: String = "", switchThreadState: Boolean = false, callFromCleanupBlock: Boolean = false): LLVMValueRef { + fun gxxLandingpad(numClauses: Int, name: String = "", switchThreadState: Boolean = false): LLVMValueRef { val personalityFunction = context.llvm.gxxPersonalityFunction.llvmValue // Type of `landingpad` instruction result (depends on personality function): @@ -907,8 +907,7 @@ internal abstract class FunctionGenerationContext( } call(context.llvm.setCurrentFrameFunction, listOf(slotsPhi!!)) setCurrentFrameIsCalled = true - if (!callFromCleanupBlock) - handleEpilogueForExperimentalMM(context.llvm.Kotlin_mm_safePointExceptionUnwind) + //handleEpilogueForExperimentalMM(context.llvm.Kotlin_mm_safePointExceptionUnwind) return landingpad } @@ -1495,7 +1494,7 @@ internal abstract class FunctionGenerationContext( if (shouldHaveCleanupLandingpad) { appendingTo(cleanupLandingpad) { - val landingpad = gxxLandingpad(numClauses = 0, callFromCleanupBlock = true) + val landingpad = gxxLandingpad(numClauses = 0) LLVMSetCleanup(landingpad, 1) forwardingForeignExceptionsTerminatedWith?.let { terminator -> diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/ObjCExportCodeGenerator.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/ObjCExportCodeGenerator.kt index 0ca7ea8f793..df1882df4eb 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/ObjCExportCodeGenerator.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/objcexport/ObjCExportCodeGenerator.kt @@ -53,6 +53,9 @@ internal class ObjCExportFunctionGenerationContext( ) : FunctionGenerationContext(builder) { private val objCExportCodegen = builder.objCExportCodegen + override val needLeaveFrameInUnwindEpilogue: Boolean + get() = true + // Note: we could generate single "epilogue" and make all [ret]s just branch to it (like [DefaultFunctionGenerationContext]), // but this would be useless for most of the usages, which have only one [ret]. // Remaining usages can be optimized ad hoc.