Skip to content

Commit db76154

Browse files
committed
add codegen-test: wasm-exceptions
1 parent 7905eff commit db76154

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/codegen/wasm_exceptions.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// only-wasm32-bare
2+
// compile-flags: -C panic=unwind
3+
4+
#![crate_type = "lib"]
5+
#![feature(core_intrinsics)]
6+
#![feature(rustc_attrs)]
7+
8+
extern {
9+
fn may_panic();
10+
11+
#[rustc_nounwind]
12+
fn log_number(number: usize);
13+
}
14+
15+
struct LogOnDrop;
16+
17+
impl Drop for LogOnDrop {
18+
fn drop(&mut self) {
19+
unsafe { log_number(0); }
20+
}
21+
}
22+
23+
// CHECK-LABEL: @test_cleanup() {{.*}} @__gxx_wasm_personality_v0
24+
#[no_mangle]
25+
pub fn test_cleanup() {
26+
let _log_on_drop = LogOnDrop;
27+
unsafe { may_panic(); }
28+
29+
// CHECK-NOT: call
30+
// CHECK: invoke void @may_panic()
31+
// CHECK: %cleanuppad = cleanuppad within none []
32+
}
33+
34+
// CHECK-LABEL: @test_rtry() {{.*}} @__gxx_wasm_personality_v0
35+
#[no_mangle]
36+
pub fn test_rtry() {
37+
unsafe {
38+
core::intrinsics::r#try(|_| {
39+
may_panic();
40+
}, core::ptr::null_mut(), |data, exception| {
41+
log_number(data as usize);
42+
log_number(exception as usize);
43+
});
44+
}
45+
46+
// CHECK-NOT: call
47+
// CHECK: invoke void @may_panic()
48+
// CHECK: {{.*}} = catchswitch within none [label {{.*}}] unwind to caller
49+
// CHECK: {{.*}} = catchpad within {{.*}} [ptr null]
50+
// CHECK: catchret
51+
}

0 commit comments

Comments
 (0)