rust/compiler
bors 2690468727 Auto merge of #92911 - nbdd0121:unwind, r=Amanieu
Guard against unwinding in cleanup code

Currently the only safe guard we have against double unwind is the panic count (which is local to Rust). When double unwinds indeed happen (e.g. C++ exception + Rust panic, or two C++ exceptions), then the second unwind actually goes through and the first unwind is leaked. This can cause UB. cc rust-lang/project-ffi-unwind#6

E.g. given the following C++ code:
```c++
extern "C" void foo() {
    throw "A";
}

extern "C" void execute(void (*fn)()) {
    try {
        fn();
    } catch(...) {
    }
}
```

This program is well-defined to terminate:
```c++
struct dtor {
    ~dtor() noexcept(false) {
        foo();
    }
};

void a() {
    dtor a;
    dtor b;
}

int main() {
    execute(a);
    return 0;
}
```

But this Rust code doesn't catch the double unwind:
```rust
extern "C-unwind" {
    fn foo();
    fn execute(f: unsafe extern "C-unwind" fn());
}

struct Dtor;

impl Drop for Dtor {
    fn drop(&mut self) {
        unsafe { foo(); }
    }
}

extern "C-unwind" fn a() {
    let _a = Dtor;
    let _b = Dtor;
}

fn main() {
    unsafe { execute(a) };
}
```

To address this issue, this PR adds an unwind edge to an abort block, so that the Rust example aborts. This is similar to how clang guards against double unwind (except clang calls terminate per C++ spec and we abort).

The cost should be very small; it's an additional trap instruction (well, two for now, since we use TrapUnreachable, but that's a different issue) for each function with landing pads; if LLVM gains support to encode "abort/terminate" info directly in LSDA like GCC does, then it'll be free. It's an additional basic block though so compile time may be worse, so I'd like a perf run.

r? `@ghost`
`@rustbot` label: F-c_unwind
2022-02-19 23:25:06 +00:00
..
rustc
rustc_apfloat
rustc_arena
rustc_ast Rollup merge of #93634 - matthiaskrgr:clippy_complexity_jan_2022, r=oli-obk 2022-02-18 16:23:33 +01:00
rustc_ast_lowering Rollup merge of #93877 - Amanieu:asm_fixes, r=nagisa 2022-02-18 23:23:08 +01:00
rustc_ast_passes Rollup merge of #93634 - matthiaskrgr:clippy_complexity_jan_2022, r=oli-obk 2022-02-18 16:23:33 +01:00
rustc_ast_pretty
rustc_attr Implement --check-cfg option (RFC 3013) 2022-02-16 13:03:12 +01:00
rustc_borrowck Rollup merge of #94006 - pierwill:upvar-field, r=nikomatsakis 2022-02-19 06:45:32 +01:00
rustc_builtin_macros Rollup merge of #92959 - asquared31415:test-non-fn-help, r=estebank 2022-02-18 16:23:29 +01:00
rustc_codegen_cranelift Overhaul Const. 2022-02-15 16:19:59 +11:00
rustc_codegen_gcc
rustc_codegen_llvm Auto merge of #94134 - matthiaskrgr:rollup-b132kjz, r=matthiaskrgr 2022-02-19 02:07:43 +00:00
rustc_codegen_ssa Auto merge of #92911 - nbdd0121:unwind, r=Amanieu 2022-02-19 23:25:06 +00:00
rustc_const_eval Support pretty printing of invalid constants 2022-02-16 00:38:59 +01:00
rustc_data_structures Address review comments. 2022-02-15 16:20:01 +11:00
rustc_driver Rollup merge of #93915 - Urgau:rfc-3013, r=petrochenkov 2022-02-18 23:23:10 +01:00
rustc_error_codes Revert "Auto merge of #91403 - cjgillot:inherit-async, r=oli-obk" 2022-02-17 16:00:04 +00:00
rustc_errors
rustc_expand
rustc_feature Rollup merge of #93658 - cchiw:issue-77443-fix, r=joshtriplett 2022-02-19 06:45:29 +01:00
rustc_fs_util
rustc_graphviz
rustc_hir Auto merge of #93938 - BoxyUwU:fix_res_self_ty, r=lcnr 2022-02-14 12:26:43 +00:00
rustc_hir_pretty
rustc_incremental
rustc_index Adopt let_else in even more places 2022-02-16 22:43:39 +01:00
rustc_infer Rollup merge of #93990 - lcnr:pre-89862-cleanup, r=estebank 2022-02-19 06:45:31 +01:00
rustc_interface Rollup merge of #93915 - Urgau:rfc-3013, r=petrochenkov 2022-02-18 23:23:10 +01:00
rustc_lexer
rustc_lint Overhaul Const. 2022-02-15 16:19:59 +11:00
rustc_lint_defs Implement --check-cfg option (RFC 3013) 2022-02-16 13:03:12 +01:00
rustc_llvm Rollup merge of #91675 - ivanloz:memtagsan, r=nagisa 2022-02-18 23:23:03 +01:00
rustc_log
rustc_macros
rustc_metadata rustdoc: Collect traits in scope for lang items 2022-02-18 16:11:23 +08:00
rustc_middle Rollup merge of #94086 - tmiasko:char-try-from-scalar-int, r=davidtwco 2022-02-19 06:45:33 +01:00
rustc_mir_build use AllocId and Ty in ExprKind::StaticRef and delay ConstValue construction 2022-02-15 21:18:33 +01:00
rustc_mir_dataflow Overhaul TyS and Ty. 2022-02-15 16:03:24 +11:00
rustc_mir_transform Rollup merge of #93634 - matthiaskrgr:clippy_complexity_jan_2022, r=oli-obk 2022-02-18 16:23:33 +01:00
rustc_monomorphize Rollup merge of #93634 - matthiaskrgr:clippy_complexity_jan_2022, r=oli-obk 2022-02-18 16:23:33 +01:00
rustc_parse Rollup merge of #93634 - matthiaskrgr:clippy_complexity_jan_2022, r=oli-obk 2022-02-18 16:23:33 +01:00
rustc_parse_format Correctly mark the span of captured arguments in format_args!() 2022-02-16 07:34:06 +00:00
rustc_passes change to a struct variant 2022-02-12 11:23:53 +00:00
rustc_plugin_impl
rustc_privacy Overhaul Const. 2022-02-15 16:19:59 +11:00
rustc_query_impl Overhaul Const. 2022-02-15 16:19:59 +11:00
rustc_query_system
rustc_resolve Rollup merge of #93634 - matthiaskrgr:clippy_complexity_jan_2022, r=oli-obk 2022-02-18 16:23:33 +01:00
rustc_save_analysis change to a struct variant 2022-02-12 11:23:53 +00:00
rustc_serialize
rustc_session Rollup merge of #93915 - Urgau:rfc-3013, r=petrochenkov 2022-02-18 23:23:10 +01:00
rustc_span Rollup merge of #93915 - Urgau:rfc-3013, r=petrochenkov 2022-02-18 23:23:10 +01:00
rustc_symbol_mangling Overhaul Const. 2022-02-15 16:19:59 +11:00
rustc_target Rollup merge of #93877 - Amanieu:asm_fixes, r=nagisa 2022-02-18 23:23:08 +01:00
rustc_trait_selection Rollup merge of #93892 - compiler-errors:issue-92917, r=jackh726,nikomatsakis 2022-02-18 23:23:09 +01:00
rustc_traits Overhaul Const. 2022-02-15 16:19:59 +11:00
rustc_ty_utils Overhaul RegionKind and Region. 2022-02-15 16:08:52 +11:00
rustc_type_ir Inline UnifyKey::index and UnifyKey::from_index 2022-02-15 19:07:06 +01:00
rustc_typeck Rollup merge of #93990 - lcnr:pre-89862-cleanup, r=estebank 2022-02-19 06:45:31 +01:00