Skip to content

Commit 65aeac6

Browse files
committed
add assembly-test: wasm-exceptions
1 parent db76154 commit 65aeac6

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tests/assembly/wasm_exceptions.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// only-wasm32-bare
2+
// assembly-output: emit-asm
3+
// compile-flags: -C target-feature=+exception-handling
4+
// compile-flags: -C panic=unwind
5+
// compile-flags: -C llvm-args=-wasm-enable-eh
6+
7+
#![crate_type = "lib"]
8+
#![feature(core_intrinsics)]
9+
#![feature(rustc_attrs)]
10+
11+
extern {
12+
fn may_panic();
13+
14+
#[rustc_nounwind]
15+
fn log_number(number: usize);
16+
}
17+
18+
struct LogOnDrop;
19+
20+
impl Drop for LogOnDrop {
21+
fn drop(&mut self) {
22+
unsafe { log_number(0); }
23+
}
24+
}
25+
26+
// CHECK-LABEL: test_cleanup:
27+
#[no_mangle]
28+
pub fn test_cleanup() {
29+
let _log_on_drop = LogOnDrop;
30+
unsafe { may_panic(); }
31+
32+
// CHECK-NOT: call
33+
// CHECK: try
34+
// CHECK: call may_panic
35+
// CHECK: catch_all
36+
// CHECK: rethrow
37+
// CHECK: end_try
38+
}
39+
40+
// CHECK-LABEL: test_rtry:
41+
#[no_mangle]
42+
pub fn test_rtry() {
43+
unsafe {
44+
core::intrinsics::r#try(|_| {
45+
may_panic();
46+
}, core::ptr::null_mut(), |data, exception| {
47+
log_number(data as usize);
48+
log_number(exception as usize);
49+
});
50+
}
51+
52+
// CHECK-NOT: call
53+
// CHECK: try
54+
// CHECK: call may_panic
55+
// CHECK: catch
56+
// CHECK: call log_number
57+
// CHECK: call log_number
58+
// CHECK-NOT: rethrow
59+
// CHECK: end_try
60+
}

0 commit comments

Comments
 (0)