Skip to content

Commit 47c62df

Browse files
committed
Add a test
1 parent 7dd197f commit 47c62df

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//@ compile-flags: -O --target wasm32-unknown-emscripten -Z emscripten-wasm-eh
2+
//@ needs-llvm-components: webassembly
3+
4+
// Emscripten has its own unique implementation of catch_unwind (in `codegen_emcc_try`),
5+
// make sure it generates something reasonable.
6+
7+
#![feature(no_core, lang_items, intrinsics, rustc_attrs)]
8+
#![crate_type = "lib"]
9+
#![no_std]
10+
#![no_core]
11+
12+
#[lang = "sized"]
13+
trait Sized {}
14+
#[lang = "freeze"]
15+
trait Freeze {}
16+
#[lang = "copy"]
17+
trait Copy {}
18+
19+
impl<T> Copy for *mut T {}
20+
21+
#[rustc_intrinsic]
22+
fn size_of<T>() -> usize {
23+
loop {}
24+
}
25+
26+
extern "rust-intrinsic" {
27+
fn catch_unwind(
28+
try_fn: fn(_: *mut u8),
29+
data: *mut u8,
30+
catch_fn: fn(_: *mut u8, _: *mut u8),
31+
) -> i32;
32+
}
33+
34+
// CHECK-LABEL: @ptr_size
35+
#[no_mangle]
36+
pub fn ptr_size() -> usize {
37+
// CHECK: ret [[PTR_SIZE:.*]]
38+
size_of::<*mut u8>()
39+
}
40+
41+
// CHECK-LABEL: @test_catch_unwind
42+
#[no_mangle]
43+
pub unsafe fn test_catch_unwind(
44+
try_fn: fn(_: *mut u8),
45+
data: *mut u8,
46+
catch_fn: fn(_: *mut u8, _: *mut u8),
47+
) -> i32 {
48+
// CHECK: start:
49+
// CHECK: invoke void %try_fn(ptr %data)
50+
// CHECK: to label %__rust_try.exit unwind label %catchswitch.i
51+
// CHECK: catchswitch.i: ; preds = %start
52+
// CHECK: %catchswitch1.i = catchswitch within none [label %catchpad.i] unwind to caller
53+
54+
// CHECK: catchpad.i: ; preds = %catchswitch.i
55+
// CHECK: %catchpad2.i = catchpad within %catchswitch1.i [ptr null]
56+
// CHECK: %0 = tail call ptr @llvm.wasm.get.exception(token %catchpad2.i)
57+
// CHECK: %1 = tail call i32 @llvm.wasm.get.ehselector(token %catchpad2.i)
58+
// CHECK: call void %catch_fn(ptr %data, ptr %0) [ "funclet"(token %catchpad2.i) ]
59+
// CHECK: catchret from %catchpad2.i to label %__rust_try.exit
60+
61+
// CHECK: __rust_try.exit: ; preds = %start, %catchpad.i
62+
// CHECK: %common.ret.op.i = phi i32 [ 0, %start ], [ 1, %catchpad.i ]
63+
// CHECK: ret i32 %common.ret.op.i
64+
65+
catch_unwind(try_fn, data, catch_fn)
66+
}
File renamed without changes.

0 commit comments

Comments
 (0)