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 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())
|
||||||
|
|
||||||
|
|||||||
+12
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user