aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorliushuyu <liushuyu011@gmail.com>2024-12-02 14:52:35 -0700
committerPhilip Herron <philip.herron@embecosm.com>2025-01-10 10:10:01 +0000
commitc82a879f21b5a390e2760ea15dd974154dc102fd (patch)
tree3197d2a233bc4bb790520414754340cce1b032db /gcc
parent66669cd6687526d42ddd1d6936b46563830a15b3 (diff)
downloadgcc-c82a879f21b5a390e2760ea15dd974154dc102fd.zip
gcc-c82a879f21b5a390e2760ea15dd974154dc102fd.tar.gz
gcc-c82a879f21b5a390e2760ea15dd974154dc102fd.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/rust/compile/try-catch-unwind-new.rs20
-rw-r--r--gcc/testsuite/rust/compile/try-catch-unwind-old.rs21
2 files changed, 41 insertions, 0 deletions
diff --git a/gcc/testsuite/rust/compile/try-catch-unwind-new.rs b/gcc/testsuite/rust/compile/try-catch-unwind-new.rs
new file mode 100644
index 0000000..b176f7a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/try-catch-unwind-new.rs
@@ -0,0 +1,20 @@
+// { dg-options "-O2 -w -fdump-tree-optimized" }
+#![feature(intrinsics)]
+
+extern "rust-intrinsic" {
+ // { dg-final { scan-tree-dump-times "__builtin_eh_pointer" 1 "optimized" } }
+ fn catch_unwind(try_fn: fn(_: *mut u8), data: *mut u8, catch_fn: fn(_: *mut u8, _: *mut u8));
+}
+
+extern "C" {
+ fn try_fn(data: *mut u8);
+ fn catch_fn(data: *mut u8, ex: *mut u8);
+}
+
+pub fn not_main(d: &mut u8) {
+ unsafe {
+ // { dg-final { scan-tree-dump-times "try_fn" 1 "optimized" } }
+ catch_unwind(try_fn, d, catch_fn);
+ // { dg-final { scan-tree-dump-times "catch_fn" 1 "optimized" } }
+ }
+}
diff --git a/gcc/testsuite/rust/compile/try-catch-unwind-old.rs b/gcc/testsuite/rust/compile/try-catch-unwind-old.rs
new file mode 100644
index 0000000..e97d52c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/try-catch-unwind-old.rs
@@ -0,0 +1,21 @@
+// { dg-options "-O2 -w -fdump-tree-optimized" }
+#![feature(intrinsics)]
+
+extern "rust-intrinsic" {
+ // { dg-final { scan-tree-dump-times "__builtin_eh_pointer" 1 "optimized" } }
+ fn r#try(try_fn: fn(_: *mut u8), data: *mut u8, catch_fn: fn(_: *mut u8, _: *mut u8)) -> i32;
+}
+
+extern "C" {
+ fn try_fn(data: *mut u8);
+ fn catch_fn(data: *mut u8, ex: *mut u8);
+}
+
+pub fn not_main(d: &mut u8) -> i32 {
+ unsafe {
+ // { dg-final { scan-tree-dump-times "try_fn" 1 "optimized" } }
+ let _: i32 = r#try(try_fn, d, catch_fn);
+ // { dg-final { scan-tree-dump-times "catch_fn" 1 "optimized" } }
+ }
+ 42
+}