about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGary Guo <gary@garyguo.net>2022-05-20 21:52:00 +0100
committerGary Guo <gary@garyguo.net>2022-06-08 21:32:41 +0100
commit1750a2f723a796b9c98b223df6013f3b1b0254df (patch)
tree4c0d645087b73ab95b2382ab080608c4839e6da0
parentbc5afd9e347c79d7e0c910eb4f452410579ca4b6 (diff)
downloadrust-1750a2f723a796b9c98b223df6013f3b1b0254df.tar.gz
rust-1750a2f723a796b9c98b223df6013f3b1b0254df.zip
Add tests for mixed panic mode restriction and lints
-rw-r--r--src/test/ui/panic-runtime/auxiliary/needs-abort.rs5
-rw-r--r--src/test/ui/panic-runtime/auxiliary/needs-unwind.rs13
-rw-r--r--src/test/ui/panic-runtime/need-abort-got-unwind.rs9
-rw-r--r--src/test/ui/panic-runtime/need-abort-got-unwind.stderr4
-rw-r--r--src/test/ui/panic-runtime/need-unwind-got-abort.rs8
-rw-r--r--src/test/ui/panic-runtime/need-unwind-got-abort.stderr6
-rw-r--r--src/test/ui/unwind-abis/ffi-unwind-calls-lint.rs25
-rw-r--r--src/test/ui/unwind-abis/ffi-unwind-calls-lint.stderr20
8 files changed, 90 insertions, 0 deletions
diff --git a/src/test/ui/panic-runtime/auxiliary/needs-abort.rs b/src/test/ui/panic-runtime/auxiliary/needs-abort.rs
new file mode 100644
index 00000000000..8fad49b5e9d
--- /dev/null
+++ b/src/test/ui/panic-runtime/auxiliary/needs-abort.rs
@@ -0,0 +1,5 @@
+// compile-flags:-C panic=abort
+// no-prefer-dynamic
+
+#![crate_type = "rlib"]
+#![no_std]
diff --git a/src/test/ui/panic-runtime/auxiliary/needs-unwind.rs b/src/test/ui/panic-runtime/auxiliary/needs-unwind.rs
new file mode 100644
index 00000000000..d555b531986
--- /dev/null
+++ b/src/test/ui/panic-runtime/auxiliary/needs-unwind.rs
@@ -0,0 +1,13 @@
+// compile-flags:-C panic=unwind
+// no-prefer-dynamic
+
+#![crate_type = "rlib"]
+#![no_std]
+#![feature(c_unwind)]
+
+extern "C-unwind" fn foo() {}
+
+fn bar() {
+    let ptr: extern "C-unwind" fn() = foo;
+    ptr();
+}
diff --git a/src/test/ui/panic-runtime/need-abort-got-unwind.rs b/src/test/ui/panic-runtime/need-abort-got-unwind.rs
new file mode 100644
index 00000000000..c72fb96e357
--- /dev/null
+++ b/src/test/ui/panic-runtime/need-abort-got-unwind.rs
@@ -0,0 +1,9 @@
+// build-fail
+// needs-unwind
+// error-pattern:is incompatible with this crate's strategy of `unwind`
+// aux-build:needs-abort.rs
+// ignore-wasm32-bare compiled with panic=abort by default
+
+extern crate needs_abort;
+
+fn main() {}
diff --git a/src/test/ui/panic-runtime/need-abort-got-unwind.stderr b/src/test/ui/panic-runtime/need-abort-got-unwind.stderr
new file mode 100644
index 00000000000..d29c7875fd0
--- /dev/null
+++ b/src/test/ui/panic-runtime/need-abort-got-unwind.stderr
@@ -0,0 +1,4 @@
+error: the crate `needs_abort` requires panic strategy `abort` which is incompatible with this crate's strategy of `unwind`
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/panic-runtime/need-unwind-got-abort.rs b/src/test/ui/panic-runtime/need-unwind-got-abort.rs
new file mode 100644
index 00000000000..3bcc0aa39ac
--- /dev/null
+++ b/src/test/ui/panic-runtime/need-unwind-got-abort.rs
@@ -0,0 +1,8 @@
+// build-fail
+// error-pattern:is incompatible with this crate's strategy of `abort`
+// aux-build:needs-unwind.rs
+// compile-flags:-C panic=abort
+
+extern crate needs_unwind;
+
+fn main() {}
diff --git a/src/test/ui/panic-runtime/need-unwind-got-abort.stderr b/src/test/ui/panic-runtime/need-unwind-got-abort.stderr
new file mode 100644
index 00000000000..a53b7ffe574
--- /dev/null
+++ b/src/test/ui/panic-runtime/need-unwind-got-abort.stderr
@@ -0,0 +1,6 @@
+error: the linked panic runtime `panic_unwind` is not compiled with this crate's panic strategy `abort`
+
+error: the crate `needs_unwind` requires panic strategy `unwind` which is incompatible with this crate's strategy of `abort`
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/unwind-abis/ffi-unwind-calls-lint.rs b/src/test/ui/unwind-abis/ffi-unwind-calls-lint.rs
new file mode 100644
index 00000000000..67c20e9eac5
--- /dev/null
+++ b/src/test/ui/unwind-abis/ffi-unwind-calls-lint.rs
@@ -0,0 +1,25 @@
+// build-pass
+
+#![feature(c_unwind)]
+#![warn(ffi_unwind_calls)]
+
+mod foo {
+    #[no_mangle]
+    pub extern "C-unwind" fn foo() {}
+}
+
+extern "C-unwind" {
+    fn foo();
+}
+
+fn main() {
+    // Call to Rust function is fine.
+    foo::foo();
+    // Call to foreign function should warn.
+    unsafe { foo(); }
+    //~^ WARNING call to foreign function with FFI-unwind ABI
+    let ptr: extern "C-unwind" fn() = foo::foo;
+    // Call to function pointer should also warn.
+    ptr();
+    //~^ WARNING call to function pointer with FFI-unwind ABI
+}
diff --git a/src/test/ui/unwind-abis/ffi-unwind-calls-lint.stderr b/src/test/ui/unwind-abis/ffi-unwind-calls-lint.stderr
new file mode 100644
index 00000000000..cf8a7782e35
--- /dev/null
+++ b/src/test/ui/unwind-abis/ffi-unwind-calls-lint.stderr
@@ -0,0 +1,20 @@
+warning: call to foreign function with FFI-unwind ABI
+  --> $DIR/ffi-unwind-calls-lint.rs:19:14
+   |
+LL |     unsafe { foo(); }
+   |              ^^^^^ call to foreign function with FFI-unwind ABI
+   |
+note: the lint level is defined here
+  --> $DIR/ffi-unwind-calls-lint.rs:4:9
+   |
+LL | #![warn(ffi_unwind_calls)]
+   |         ^^^^^^^^^^^^^^^^
+
+warning: call to function pointer with FFI-unwind ABI
+  --> $DIR/ffi-unwind-calls-lint.rs:23:5
+   |
+LL |     ptr();
+   |     ^^^^^ call to function pointer with FFI-unwind ABI
+
+warning: 2 warnings emitted
+