about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorcynecx <me@cynecx.net>2021-11-14 03:08:12 +0100
committercynecx <me@cynecx.net>2021-12-03 23:51:49 +0100
commit8e9ccdf28f91d56113117fd512819363602bdf89 (patch)
treea75948b40d1ecd62c5d1b79524a287848b985745 /src/test
parent686ace3b4119333f7d7868b05be2042fe56484a7 (diff)
downloadrust-8e9ccdf28f91d56113117fd512819363602bdf89.tar.gz
rust-8e9ccdf28f91d56113117fd512819363602bdf89.zip
add tests for asm's options(may_unwind)
Diffstat (limited to 'src/test')
-rw-r--r--src/test/codegen/asm-may_unwind.rs24
-rw-r--r--src/test/ui/asm/aarch64/may_unwind.rs31
-rw-r--r--src/test/ui/asm/may_unwind.rs9
-rw-r--r--src/test/ui/asm/x86_64/may_unwind.rs31
4 files changed, 95 insertions, 0 deletions
diff --git a/src/test/codegen/asm-may_unwind.rs b/src/test/codegen/asm-may_unwind.rs
new file mode 100644
index 00000000000..267eab7d105
--- /dev/null
+++ b/src/test/codegen/asm-may_unwind.rs
@@ -0,0 +1,24 @@
+// min-llvm-version: 13.0.0
+// compile-flags: -O
+
+#![crate_type = "rlib"]
+#![feature(asm, asm_unwind)]
+
+#[no_mangle]
+pub extern "C" fn panicky() {}
+
+struct Foo;
+
+impl Drop for Foo {
+    fn drop(&mut self) {
+        println!();
+    }
+}
+
+// CHECK-LABEL: @may_unwind
+// CHECK: invoke void asm sideeffect alignstack unwind
+#[no_mangle]
+pub unsafe fn may_unwind() {
+    let _m = Foo;
+    asm!("", options(may_unwind));
+}
diff --git a/src/test/ui/asm/aarch64/may_unwind.rs b/src/test/ui/asm/aarch64/may_unwind.rs
new file mode 100644
index 00000000000..8e1ece53a47
--- /dev/null
+++ b/src/test/ui/asm/aarch64/may_unwind.rs
@@ -0,0 +1,31 @@
+// min-llvm-version: 13.0.0
+// only-aarch64
+// run-pass
+// needs-asm-support
+
+#![feature(asm, asm_unwind)]
+
+use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};
+
+struct Foo<'a>(&'a mut bool);
+
+impl Drop for Foo<'_> {
+    fn drop(&mut self) {
+        *self.0 = false;
+    }
+}
+
+#[no_mangle]
+extern "C" fn panicky() {
+    resume_unwind(Box::new(()));
+}
+
+fn main() {
+    let flag = &mut true;
+    catch_unwind(AssertUnwindSafe(|| {
+        let _foo = Foo(flag);
+        unsafe { asm!("bl _panicky", options(may_unwind)) };
+    }))
+    .expect_err("expected a panic");
+    assert_eq!(*flag, false);
+}
diff --git a/src/test/ui/asm/may_unwind.rs b/src/test/ui/asm/may_unwind.rs
new file mode 100644
index 00000000000..436e8b9d95a
--- /dev/null
+++ b/src/test/ui/asm/may_unwind.rs
@@ -0,0 +1,9 @@
+// min-llvm-version: 13.0.0
+// run-pass
+// needs-asm-support
+
+#![feature(asm, asm_unwind)]
+
+fn main() {
+    unsafe { asm!("", options(may_unwind)) };
+}
diff --git a/src/test/ui/asm/x86_64/may_unwind.rs b/src/test/ui/asm/x86_64/may_unwind.rs
new file mode 100644
index 00000000000..cec597ea24e
--- /dev/null
+++ b/src/test/ui/asm/x86_64/may_unwind.rs
@@ -0,0 +1,31 @@
+// min-llvm-version: 13.0.0
+// only-x86_64
+// run-pass
+// needs-asm-support
+
+#![feature(asm, asm_unwind)]
+
+use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};
+
+struct Foo<'a>(&'a mut bool);
+
+impl Drop for Foo<'_> {
+    fn drop(&mut self) {
+        *self.0 = false;
+    }
+}
+
+#[no_mangle]
+extern "C" fn panicky() {
+    resume_unwind(Box::new(()));
+}
+
+fn main() {
+    let flag = &mut true;
+    catch_unwind(AssertUnwindSafe(|| {
+        let _foo = Foo(flag);
+        unsafe { asm!("call panicky", options(may_unwind)) };
+    }))
+    .expect_err("expected a panic");
+    assert_eq!(*flag, false);
+}