ObjCExport: introduce terminatingExceptionHandler

This commit is contained in:
Svyatoslav Scherbina
2022-01-13 13:56:01 +03:00
committed by Space
parent eaa6a75de4
commit f7a1fa86a9
2 changed files with 21 additions and 4 deletions
@@ -432,7 +432,7 @@ internal abstract class FunctionGenerationContext(
val function: LLVMValueRef, val function: LLVMValueRef,
val codegen: CodeGenerator, val codegen: CodeGenerator,
private val startLocation: LocationInfo?, private val startLocation: LocationInfo?,
private val endLocation: LocationInfo?, protected val endLocation: LocationInfo?,
switchToRunnable: Boolean, switchToRunnable: Boolean,
internal val irFunction: IrFunction? = null internal val irFunction: IrFunction? = null
) : ContextUtils { ) : ContextUtils {
@@ -980,9 +980,7 @@ internal abstract class FunctionGenerationContext(
} }
appendingTo(fatalForeignExceptionBlock) { appendingTo(fatalForeignExceptionBlock) {
val exceptionRecord = extractValue(landingpad, 0) terminateWithCurrentException(landingpad)
call(context.llvm.cxaBeginCatchFunction, listOf(exceptionRecord))
terminate()
} }
} }
@@ -993,6 +991,13 @@ internal abstract class FunctionGenerationContext(
} }
} }
fun terminateWithCurrentException(landingpad: LLVMValueRef) {
val exceptionRecord = extractValue(landingpad, 0)
// So `std::terminate` is called from C++ catch block:
call(context.llvm.cxaBeginCatchFunction, listOf(exceptionRecord))
terminate()
}
fun terminate() { fun terminate() {
call(context.llvm.cxxStdTerminate, emptyList()) call(context.llvm.cxxStdTerminate, emptyList())
@@ -96,6 +96,18 @@ internal class ObjCExportFunctionGenerationContext(
override fun processReturns() { override fun processReturns() {
// Do nothing. // Do nothing.
} }
val terminatingExceptionHandler = object : ExceptionHandler.Local() {
override val unwind: LLVMBasicBlockRef by lazy {
val result = basicBlockInFunction("fatal_landingpad", endLocation)
appendingTo(result) {
val landingpad = gxxLandingpad(0)
LLVMSetCleanup(landingpad, 1)
terminateWithCurrentException(landingpad)
}
result
}
}
} }
internal class ObjCExportFunctionGenerationContextBuilder( internal class ObjCExportFunctionGenerationContextBuilder(