[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.
This commit is contained in:
Ilya Matveev
2021-06-25 20:01:53 +07:00
committed by Space
parent c132e1a39f
commit dc8186cb83
7 changed files with 46 additions and 4 deletions
@@ -0,0 +1,5 @@
#include <stdexcept>
extern "C" __attribute__((always_inline)) void throwCppException() {
throw std::runtime_error("Error");
}