ObjCExport: introduce terminatingExceptionHandler
This commit is contained in:
committed by
Space
parent
eaa6a75de4
commit
f7a1fa86a9
+9
-4
@@ -432,7 +432,7 @@ internal abstract class FunctionGenerationContext(
|
||||
val function: LLVMValueRef,
|
||||
val codegen: CodeGenerator,
|
||||
private val startLocation: LocationInfo?,
|
||||
private val endLocation: LocationInfo?,
|
||||
protected val endLocation: LocationInfo?,
|
||||
switchToRunnable: Boolean,
|
||||
internal val irFunction: IrFunction? = null
|
||||
) : ContextUtils {
|
||||
@@ -980,9 +980,7 @@ internal abstract class FunctionGenerationContext(
|
||||
}
|
||||
|
||||
appendingTo(fatalForeignExceptionBlock) {
|
||||
val exceptionRecord = extractValue(landingpad, 0)
|
||||
call(context.llvm.cxaBeginCatchFunction, listOf(exceptionRecord))
|
||||
terminate()
|
||||
terminateWithCurrentException(landingpad)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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() {
|
||||
call(context.llvm.cxxStdTerminate, emptyList())
|
||||
|
||||
|
||||
+12
@@ -96,6 +96,18 @@ internal class ObjCExportFunctionGenerationContext(
|
||||
override fun processReturns() {
|
||||
// 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(
|
||||
|
||||
Reference in New Issue
Block a user