-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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).
- Loading branch information
Showing
7 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/tools/miri/tests/fail/function_calls/target_feature.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//@only-target-x86_64: uses x86 target features | ||
|
||
fn main() { | ||
assert!(!is_x86_feature_detected!("ssse3")); | ||
unsafe { | ||
ssse3_fn(); //~ ERROR: calling a function that requires unavailable target features: ssse3 | ||
} | ||
} | ||
|
||
#[target_feature(enable = "ssse3")] | ||
unsafe fn ssse3_fn() {} |
15 changes: 15 additions & 0 deletions
15
src/tools/miri/tests/fail/function_calls/target_feature.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: Undefined Behavior: calling a function that requires unavailable target features: ssse3 | ||
--> $DIR/target_feature.rs:LL:CC | ||
| | ||
LL | ssse3_fn(); | ||
| ^^^^^^^^^^ calling a function that requires unavailable target features: ssse3 | ||
| | ||
= 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 `main` at $DIR/target_feature.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to previous error | ||
|
12 changes: 12 additions & 0 deletions
12
src/tools/miri/tests/pass/function_calls/target_feature.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//@only-target-x86_64: uses x86 target features | ||
//@compile-flags: -C target-feature=+ssse3 | ||
|
||
fn main() { | ||
assert!(is_x86_feature_detected!("ssse3")); | ||
unsafe { | ||
ssse3_fn(); | ||
} | ||
} | ||
|
||
#[target_feature(enable = "ssse3")] | ||
unsafe fn ssse3_fn() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// only-x86_64 | ||
// compile-flags:-C target-feature=+ssse3 | ||
|
||
#![crate_type = "lib"] | ||
|
||
// ok (ssse3 enabled at compile time) | ||
const A: () = unsafe { ssse3_fn() }; | ||
|
||
// error (avx2 not enabled at compile time) | ||
const B: () = unsafe { avx2_fn() }; | ||
//~^ ERROR evaluation of constant value failed | ||
|
||
#[target_feature(enable = "ssse3")] | ||
const unsafe fn ssse3_fn() {} | ||
|
||
#[target_feature(enable = "avx2")] | ||
const unsafe fn avx2_fn() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error[E0080]: evaluation of constant value failed | ||
--> $DIR/const_fn_target_feature.rs:10:24 | ||
| | ||
LL | const B: () = unsafe { avx2_fn() }; | ||
| ^^^^^^^^^ calling a function that requires unavailable target features: avx2 | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |