about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-10-02 18:29:49 +0200
committerRalf Jung <post@ralfj.de>2023-10-02 18:30:03 +0200
commitcfbcc0e6f565a6848e519570cdb4dcd4c3c34fc5 (patch)
tree01c212b3ddadae3eb6369101b7ae4e471a6750fe /src/tools
parent6687c075dfb861f0c51439a34d9bd674b7ef54a9 (diff)
downloadrust-cfbcc0e6f565a6848e519570cdb4dcd4c3c34fc5.tar.gz
rust-cfbcc0e6f565a6848e519570cdb4dcd4c3c34fc5.zip
add test for a function ABI mismatch due to target features
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/miri/tests/fail/function_calls/simd_feature_flag_difference.rs30
-rw-r--r--src/tools/miri/tests/fail/function_calls/simd_feature_flag_difference.stderr20
2 files changed, 50 insertions, 0 deletions
diff --git a/src/tools/miri/tests/fail/function_calls/simd_feature_flag_difference.rs b/src/tools/miri/tests/fail/function_calls/simd_feature_flag_difference.rs
new file mode 100644
index 00000000000..e98a3abadf5
--- /dev/null
+++ b/src/tools/miri/tests/fail/function_calls/simd_feature_flag_difference.rs
@@ -0,0 +1,30 @@
+//@only-target-x86_64
+#![allow(improper_ctypes_definitions)]
+use std::arch::x86_64::*;
+use std::mem::transmute;
+
+#[no_mangle]
+#[target_feature(enable = "avx")]
+pub unsafe extern "C" fn foo(_y: f32, x: __m256) -> __m256 {
+    x
+}
+
+pub fn bar(x: __m256) -> __m256 {
+    // The first and second argument get mixed up here since caller
+    // and callee do not have the same feature flags.
+    // In Miri, we don't have a concept of "dynamically available feature flags",
+    // so this will always lead to an error due to calling a function that requires
+    // an unavailable feature. If we ever support dynamically available features,
+    // this will need some dedicated checks.
+    unsafe { foo(0.0, x) } //~ERROR: unavailable target features
+}
+
+fn assert_eq_m256(a: __m256, b: __m256) {
+    unsafe { assert_eq!(transmute::<_, [f32; 8]>(a), transmute::<_, [f32; 8]>(b)) }
+}
+
+fn main() {
+    let input = unsafe { transmute::<_, __m256>([1.0f32; 8]) };
+    let copy = bar(input);
+    assert_eq_m256(input, copy);
+}
diff --git a/src/tools/miri/tests/fail/function_calls/simd_feature_flag_difference.stderr b/src/tools/miri/tests/fail/function_calls/simd_feature_flag_difference.stderr
new file mode 100644
index 00000000000..ab3ff5fcdc1
--- /dev/null
+++ b/src/tools/miri/tests/fail/function_calls/simd_feature_flag_difference.stderr
@@ -0,0 +1,20 @@
+error: Undefined Behavior: calling a function that requires unavailable target features: avx
+  --> $DIR/simd_feature_flag_difference.rs:LL:CC
+   |
+LL |     unsafe { foo(0.0, x) }
+   |              ^^^^^^^^^^^ calling a function that requires unavailable target features: avx
+   |
+   = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
+   = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
+   = note: BACKTRACE:
+   = note: inside `bar` at $DIR/simd_feature_flag_difference.rs:LL:CC
+note: inside `main`
+  --> $DIR/simd_feature_flag_difference.rs:LL:CC
+   |
+LL |     let copy = bar(input);
+   |                ^^^^^^^^^^
+
+note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
+
+error: aborting due to previous error
+