about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorhyd-dev <yd-huang@outlook.com>2021-03-25 18:49:35 +0800
committerhyd-dev <yd-huang@outlook.com>2021-04-11 22:32:40 +0800
commit2fd4dd20d717b3e8af4bdff2873b348920426425 (patch)
treed20af30295fee75b8cebd4de5d7ffbdd9777bcf2 /src/test
parent58f32da346642ff3f50186f6f4a0de46e61008be (diff)
Allow using `-C force-unwind-tables=no` when `panic=unwind`
Diffstat (limited to 'src/test')
-rw-r--r--src/test/assembly/panic-no-unwind-no-uwtable.rs8
-rw-r--r--src/test/assembly/panic-unwind-no-uwtable.rs12
-rw-r--r--src/test/codegen/force-no-unwind-tables.rs6
-rw-r--r--src/test/codegen/panic-unwind-default-uwtable.rs6
-rw-r--r--src/test/ui/panic-runtime/unwind-tables-panic-required.rs10
-rw-r--r--src/test/ui/unwind-no-uwtable.rs34
6 files changed, 65 insertions, 11 deletions
diff --git a/src/test/assembly/panic-no-unwind-no-uwtable.rs b/src/test/assembly/panic-no-unwind-no-uwtable.rs
new file mode 100644
index 00000000000..499d4e69867
--- /dev/null
+++ b/src/test/assembly/panic-no-unwind-no-uwtable.rs
@@ -0,0 +1,8 @@
+// assembly-output: emit-asm
+// only-x86_64-unknown-linux-gnu
+// compile-flags: -C panic=unwind -C force-unwind-tables=n -O
+
+#![crate_type = "lib"]
+
+// CHECK-NOT: .cfi_startproc
+pub fn foo() {}
diff --git a/src/test/assembly/panic-unwind-no-uwtable.rs b/src/test/assembly/panic-unwind-no-uwtable.rs
new file mode 100644
index 00000000000..8eed72b2fca
--- /dev/null
+++ b/src/test/assembly/panic-unwind-no-uwtable.rs
@@ -0,0 +1,12 @@
+// assembly-output: emit-asm
+// only-x86_64-unknown-linux-gnu
+// compile-flags: -C panic=unwind -C force-unwind-tables=n
+
+#![crate_type = "lib"]
+
+// CHECK-LABEL: foo:
+// CHECK: .cfi_startproc
+#[no_mangle]
+fn foo() {
+    panic!();
+}
diff --git a/src/test/codegen/force-no-unwind-tables.rs b/src/test/codegen/force-no-unwind-tables.rs
index dc77e6cb709..3ee23f05eb2 100644
--- a/src/test/codegen/force-no-unwind-tables.rs
+++ b/src/test/codegen/force-no-unwind-tables.rs
@@ -3,5 +3,9 @@
 
 #![crate_type="lib"]
 
+// CHECK-LABEL: define{{.*}}void @foo
 // CHECK-NOT: attributes #{{.*}} uwtable
-pub fn foo() {}
+#[no_mangle]
+fn foo() {
+    panic!();
+}
diff --git a/src/test/codegen/panic-unwind-default-uwtable.rs b/src/test/codegen/panic-unwind-default-uwtable.rs
new file mode 100644
index 00000000000..4c85008cf35
--- /dev/null
+++ b/src/test/codegen/panic-unwind-default-uwtable.rs
@@ -0,0 +1,6 @@
+// compile-flags: -C panic=unwind -C no-prepopulate-passes
+
+#![crate_type = "lib"]
+
+// CHECK: attributes #{{.*}} uwtable
+pub fn foo() {}
diff --git a/src/test/ui/panic-runtime/unwind-tables-panic-required.rs b/src/test/ui/panic-runtime/unwind-tables-panic-required.rs
deleted file mode 100644
index 79e91879051..00000000000
--- a/src/test/ui/panic-runtime/unwind-tables-panic-required.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-// Tests that the compiler errors if the user tries to turn off unwind tables
-// when they are required.
-//
-// dont-check-compiler-stderr
-// compile-flags: -C panic=unwind -C force-unwind-tables=no
-//
-// error-pattern: panic=unwind requires unwind tables, they cannot be disabled with `-C force-unwind-tables=no`.
-
-pub fn main() {
-}
diff --git a/src/test/ui/unwind-no-uwtable.rs b/src/test/ui/unwind-no-uwtable.rs
new file mode 100644
index 00000000000..f249d3f4574
--- /dev/null
+++ b/src/test/ui/unwind-no-uwtable.rs
@@ -0,0 +1,34 @@
+// run-pass
+// ignore-windows target requires uwtable
+// ignore-wasm32-bare no proper panic=unwind support
+// compile-flags: -C panic=unwind -C force-unwind-tables=n
+
+use std::panic::{self, AssertUnwindSafe};
+
+struct Increase<'a>(&'a mut u8);
+
+impl Drop for Increase<'_> {
+    fn drop(&mut self) {
+        *self.0 += 1;
+    }
+}
+
+#[inline(never)]
+fn unwind() {
+    panic!();
+}
+
+#[inline(never)]
+fn increase(count: &mut u8) {
+    let _increase = Increase(count);
+    unwind();
+}
+
+fn main() {
+    let mut count = 0;
+    assert!(panic::catch_unwind(AssertUnwindSafe(
+        #[inline(never)]
+        || increase(&mut count)
+    )).is_err());
+    assert_eq!(count, 1);
+}