Skip to content

Commit 7cf7aa0

Browse files
committed
Auto merge of #113720 - eduardosm:miri-target-feature, r=RalfJung,oli-obk
miri: fail when calling a function that requires an unavailable target feature miri will report an UB when calling a function that has a `#[target_feature(enable = ...)]` attribute is called and the required feature is not available. "Available features" are the same that `is_x86_feature_detected!` (or equivalent) reports to be available during miri execution (which can be enabled or disabled with the `-C target-feature` flag).
2 parents bc058c7 + 6688a1e commit 7cf7aa0

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@only-target-x86_64: uses x86 target features
2+
3+
fn main() {
4+
assert!(!is_x86_feature_detected!("ssse3"));
5+
unsafe {
6+
ssse3_fn(); //~ ERROR: calling a function that requires unavailable target features: ssse3
7+
}
8+
}
9+
10+
#[target_feature(enable = "ssse3")]
11+
unsafe fn ssse3_fn() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: calling a function that requires unavailable target features: ssse3
2+
--> $DIR/target_feature.rs:LL:CC
3+
|
4+
LL | ssse3_fn();
5+
| ^^^^^^^^^^ calling a function that requires unavailable target features: ssse3
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 `main` at $DIR/target_feature.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to previous error
15+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@only-target-x86_64: uses x86 target features
2+
//@compile-flags: -C target-feature=+ssse3
3+
4+
fn main() {
5+
assert!(is_x86_feature_detected!("ssse3"));
6+
unsafe {
7+
ssse3_fn();
8+
}
9+
}
10+
11+
#[target_feature(enable = "ssse3")]
12+
unsafe fn ssse3_fn() {}

0 commit comments

Comments
 (0)