forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#122287 - RalfJung:simd-static-assert, r=pnkfelix add test ensuring simd codegen checks don't run when a static assertion failed stdarch relies on this to ensure that SIMD indices are in bounds. I would love to know why this works, but I can't figure out where codegen decides to not codegen a function if a required-const does not evaluate. `@oli-obk` `@bjorn3` do you have any idea?
- Loading branch information
Showing
7 changed files
with
56 additions
and
8 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//@build-fail | ||
//! Make sure that monomorphization-time const errors from `static_assert` take priority over the | ||
//! error from simd_extract. Basically this checks that if a const fails to evaluate in some | ||
//! function, we don't bother codegen'ing the function. | ||
#![feature(generic_arg_infer)] | ||
#![feature(core_intrinsics)] | ||
#![feature(repr_simd)] | ||
#![feature(inline_const)] | ||
use std::intrinsics::simd::*; | ||
|
||
#[repr(simd)] | ||
#[allow(non_camel_case_types)] | ||
struct int8x4_t(u8,u8,u8,u8); | ||
|
||
fn get_elem<const LANE: u32>(a: int8x4_t) -> u8 { | ||
const { assert!(LANE < 4); } // the error should be here... | ||
//~^ ERROR failed | ||
//~| assertion failed | ||
unsafe { simd_extract(a, LANE) } // ...not here | ||
} | ||
|
||
fn main() { | ||
get_elem::<4>(int8x4_t(0,0,0,0)); | ||
} |
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 @@ | ||
error[E0080]: evaluation of `get_elem::<4>::{constant#0}` failed | ||
--> $DIR/const-err-trumps-simd-err.rs:16:13 | ||
| | ||
LL | const { assert!(LANE < 4); } // the error should be here... | ||
| ^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: LANE < 4', $DIR/const-err-trumps-simd-err.rs:16:13 | ||
| | ||
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
note: the above error was encountered while instantiating `fn get_elem::<4>` | ||
--> $DIR/const-err-trumps-simd-err.rs:23:5 | ||
| | ||
LL | get_elem::<4>(int8x4_t(0,0,0,0)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |