rust/library/unwind/src
Jubilee 1279830068
Rollup merge of #121438 - coolreader18:wasm32-panic-unwind, r=cuviper
std support for wasm32 panic=unwind

Tracking issue: #118168

This adds std support for `-Cpanic=unwind` on wasm, and with it slightly more fleshed out rustc support. Now, the stable default is still panic=abort without exception-handling, but if you `-Zbuild-std` with `RUSTFLAGS=-Cpanic=unwind`, you get wasm exception-handling try/catch blocks in the binary:

```rust
#[no_mangle]
pub fn foo_bar(x: bool) -> *mut u8 {
    let s = Box::<str>::from("hello");
    maybe_panic(x);
    Box::into_raw(s).cast()
}

#[inline(never)]
#[no_mangle]
fn maybe_panic(x: bool) {
    if x {
        panic!("AAAAA");
    }
}
```
```wat
;; snip...
(try $label$5
 (do
  (call $maybe_panic
   (local.get $0)
  )
  (br $label$1)
 )
 (catch_all
  (global.set $__stack_pointer
   (local.get $1)
  )
  (call $__rust_dealloc
   (local.get $2)
   (i32.const 5)
   (i32.const 1)
  )
  (rethrow $label$5)
 )
)
;; snip...
```
2024-03-11 09:29:34 -07:00
..
lib.rs Rollup merge of #121438 - coolreader18:wasm32-panic-unwind, r=cuviper 2024-03-11 09:29:34 -07:00
libunwind.rs Rollup merge of #121438 - coolreader18:wasm32-panic-unwind, r=cuviper 2024-03-11 09:29:34 -07:00
unwinding.rs Use Itanium ABI for thrown exceptions 2024-02-22 17:39:49 -06:00
wasm.rs Don't codegen wasm.throw unless with -Zbuild-std 2024-02-26 11:56:48 -06:00