[K/N] All bridges should have cleanup landingpad block (BB with return can be called before setting terminated function used as reason to add Enter/Leave frame functions)

This commit is contained in:
Elena Lepilkina
2021-10-18 19:10:16 +03:00
committed by Space
parent 2d72f4d5a9
commit b716872988
2 changed files with 7 additions and 5 deletions
@@ -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 ->
@@ -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.