Skip to content

Commit 67f7fb1

Browse files
committed
Auto merge of rust-lang#3099 - RalfJung:abi-target-feature, r=RalfJung
add test for a function ABI mismatch due to target features Cc rust-lang/miri#3095
2 parents ea4a983 + 3a42e5c commit 67f7fb1

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//@only-target-x86_64
2+
#![allow(improper_ctypes_definitions)]
3+
use std::arch::x86_64::*;
4+
use std::mem::transmute;
5+
6+
#[no_mangle]
7+
#[target_feature(enable = "avx")]
8+
pub unsafe extern "C" fn foo(_y: f32, x: __m256) -> __m256 {
9+
x
10+
}
11+
12+
pub fn bar(x: __m256) -> __m256 {
13+
// The first and second argument get mixed up here since caller
14+
// and callee do not have the same feature flags.
15+
// In Miri, we don't have a concept of "dynamically available feature flags",
16+
// so this will always lead to an error due to calling a function that requires
17+
// an unavailable feature. If we ever support dynamically available features,
18+
// this will need some dedicated checks.
19+
unsafe { foo(0.0, x) } //~ERROR: unavailable target features
20+
}
21+
22+
fn assert_eq_m256(a: __m256, b: __m256) {
23+
unsafe { assert_eq!(transmute::<_, [f32; 8]>(a), transmute::<_, [f32; 8]>(b)) }
24+
}
25+
26+
fn main() {
27+
let input = unsafe { transmute::<_, __m256>([1.0f32; 8]) };
28+
let copy = bar(input);
29+
assert_eq_m256(input, copy);
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: Undefined Behavior: calling a function that requires unavailable target features: avx
2+
--> $DIR/simd_feature_flag_difference.rs:LL:CC
3+
|
4+
LL | unsafe { foo(0.0, x) }
5+
| ^^^^^^^^^^^ calling a function that requires unavailable target features: avx
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `bar` at $DIR/simd_feature_flag_difference.rs:LL:CC
11+
note: inside `main`
12+
--> $DIR/simd_feature_flag_difference.rs:LL:CC
13+
|
14+
LL | let copy = bar(input);
15+
| ^^^^^^^^^^
16+
17+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
18+
19+
error: aborting due to previous error
20+

0 commit comments

Comments
 (0)