Files
kotlin-fork/kotlin-native/backend.native/tests/interop/exceptions/throwThroughBridge.cpp
T
Ilya Matveev dc8186cb83 [K/N][Interop] Fix throwing exceptions through bridges in opt mode
By default, C functions compiled to bitcode by clang have the
nounwind attribute. If such functions throws an exception, the
behaviour is undefined.

Our interop machinery can process foreign exceptions on call sites
(terminate or wrap them in Kotlin exceptions). But if the interop
bridges have the nounwind attribute, LLVM optimizations (particularly
inlining) may lead to the situation when a foreign exception is ignored by
our foreign exception handler.

This patch fixes the issue by compiling bridges with -fexceptions flag.
This flag makes clang to not set the nounwind attribute, so exceptions
can be thrown through C frames.
2021-07-02 11:51:06 +00:00

11 lines
208 B
C++

#include "testlib_api.h"
#include <stdio.h>
int main(int argc, char** argv) {
try {
testlib_symbols()->kotlin.root.kotlinFun();
} catch (...) {
printf("Should not happen\n");
}
}