Skip to content

Commit 5a9029c

Browse files
liushuyuCohenArthur
authored andcommitted
gccrs: add two more tests to test try-catch (unwind) code generation
gcc/testsuite/ChangeLog: * rust/compile/try-catch-unwind-old.rs: add a test to test the older try intrinsics from plain old Rust to v1.78.0 * rust/compile/try-catch-unwind-new.rs: add a test to test the newer catch_unwind instrinsics since Rust v1.78.0
1 parent 9e1ffac commit 5a9029c

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// { dg-options "-O2 -w -fdump-tree-optimized" }
2+
#![feature(intrinsics)]
3+
4+
extern "rust-intrinsic" {
5+
// { dg-final { scan-tree-dump-times "__builtin_eh_pointer" 1 "optimized" } }
6+
fn catch_unwind(try_fn: fn(_: *mut u8), data: *mut u8, catch_fn: fn(_: *mut u8, _: *mut u8));
7+
}
8+
9+
extern "C" {
10+
fn try_fn(data: *mut u8);
11+
fn catch_fn(data: *mut u8, ex: *mut u8);
12+
}
13+
14+
pub fn not_main(d: &mut u8) {
15+
unsafe {
16+
// { dg-final { scan-tree-dump-times "try_fn" 1 "optimized" } }
17+
catch_unwind(try_fn, d, catch_fn);
18+
// { dg-final { scan-tree-dump-times "catch_fn" 1 "optimized" } }
19+
}
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// { dg-options "-O2 -w -fdump-tree-optimized" }
2+
#![feature(intrinsics)]
3+
4+
extern "rust-intrinsic" {
5+
// { dg-final { scan-tree-dump-times "__builtin_eh_pointer" 1 "optimized" } }
6+
fn r#try(try_fn: fn(_: *mut u8), data: *mut u8, catch_fn: fn(_: *mut u8, _: *mut u8)) -> i32;
7+
}
8+
9+
extern "C" {
10+
fn try_fn(data: *mut u8);
11+
fn catch_fn(data: *mut u8, ex: *mut u8);
12+
}
13+
14+
pub fn not_main(d: &mut u8) -> i32 {
15+
unsafe {
16+
// { dg-final { scan-tree-dump-times "try_fn" 1 "optimized" } }
17+
let _: i32 = r#try(try_fn, d, catch_fn);
18+
// { dg-final { scan-tree-dump-times "catch_fn" 1 "optimized" } }
19+
}
20+
42
21+
}

0 commit comments

Comments
 (0)