rust/src/test
bors b520af6fd5 Auto merge of #65646 - Amanieu:foreign-exceptions, r=nikomatsakis
Allow foreign exceptions to unwind through Rust code and Rust panics to unwind through FFI

This PR fixes interactions between Rust panics and foreign (mainly C++) exceptions.

C++ exceptions (and other FFI exceptions) can now safely unwind through Rust code:
- The FFI function causing the unwind must be marked with `#[unwind(allowed)]`. If this is not the case then LLVM may optimize landing pads away with the assumption that they are unreachable.
- Drop code will be executed as the exception unwinds through the stack, as with a Rust panic.
- `catch_unwind` will *not* catch the exception, instead the exception will silently continue unwinding past it.

Rust panics can now safely unwind through C++ code:
- C++ destructors will be called as the stack unwinds.
- The Rust panic can only be caught with `catch (...)`, after which it can be either rethrown or discarded.
- C++ cannot name the type of the Rust exception object used for unwinding, which means that it can't be caught explicitly or have its contents inspected.

Tests have been added to ensure all of the above works correctly.

Some notes about non-C++ exceptions:
- `pthread_cancel` and `pthread_exit` use unwinding on glibc. This has the same behavior as a C++ exception: destructors are run but it cannot be caught by `catch_unwind`.
- `longjmp` on Windows is implemented using unwinding. Destructors are run on MSVC, but not on MinGW. In both cases the unwind cannot be caught by `catch_unwind`.
- As with C++ exceptions, you need to mark the relevant FFI functions with `#[unwind(allowed)]`, otherwise LLVM will optimize out the destructors since they seem unreachable.

I haven't updated any of the documentation, so officially unwinding through FFI is still UB. However this is a step towards making it well-defined.

Fixes #65441

cc @gnzlbg
r? @alexcrichton
2019-11-03 18:36:59 +00:00
..
assembly
auxiliary
codegen rustc_codegen_ssa: move all set_var_name calls to mir::debuginfo. 2019-10-31 20:25:42 +02:00
codegen-units Update test output. 2019-10-25 14:52:39 +02:00
compile-fail fix compile-fail test 2019-10-22 12:42:15 -07:00
debuginfo
incremental Re-enable Emscripten's exception handling support 2019-10-25 15:16:36 -07:00
mir-opt Auto merge of #65459 - ecstatic-morse:graphviz-subgraph, r=estebank 2019-11-01 03:15:31 +00:00
pretty Fix a previously forgotten pretty-printing test after a change to the pretty-printing mechanism. 2019-10-28 18:43:59 +01:00
run-fail [const-prop] Handle MIR Rvalue::Aggregates 2019-10-18 06:29:57 -04:00
run-make Upgrade Emscripten targets to use upstream LLVM backend 2019-10-16 17:06:48 -07:00
run-make-fulldeps Fix macOS tests 2019-11-03 14:04:15 +00:00
run-pass-valgrind
rustdoc Rollup merge of #65857 - kinnison:kinnison/issue-55364, r=Manisheart,GuillaumeGomez 2019-11-01 11:20:12 -07:00
rustdoc-js
rustdoc-js-std
rustdoc-ui stabilize cfg(doctest) 2019-10-29 13:42:55 +01:00
rustfix
ui Auto merge of #65759 - tmiasko:ui, r=petrochenkov 2019-11-03 15:14:09 +00:00
ui-fulldeps Update error annotations in ui-fulldeps tests that successfully compile 2019-11-03 10:20:11 +01:00
COMPILER_TESTS.md