Test errors
This commit is contained in:
parent
5976674a71
commit
e74a268db5
@ -241,16 +241,16 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
}
|
||||
"simd_insert" => {
|
||||
let index = self.read_scalar(args[1])?.to_u32()? as u64;
|
||||
let scalar = self.read_immediate(args[2])?;
|
||||
let scalar = args[2];
|
||||
let input = args[0];
|
||||
let (len, e_ty) = self.read_vector_ty(input);
|
||||
assert!(
|
||||
index < len,
|
||||
"index `{}` must be in bounds of vector type `{}`: `[0, {})`",
|
||||
"Index `{}` must be in bounds of vector type `{}`: `[0, {})`",
|
||||
index, e_ty, len
|
||||
);
|
||||
assert_eq!(
|
||||
args[0].layout, dest.layout,
|
||||
input.layout, dest.layout,
|
||||
"Return type `{}` must match vector type `{}`",
|
||||
dest.layout.ty, input.layout.ty
|
||||
);
|
||||
@ -261,15 +261,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
);
|
||||
|
||||
for i in 0..len {
|
||||
let place = self.place_field(dest, index)?;
|
||||
if i == index {
|
||||
self.write_immediate(*scalar, place)?;
|
||||
let place = self.place_field(dest, i)?;
|
||||
let value = if i == index {
|
||||
scalar
|
||||
} else {
|
||||
self.write_immediate(
|
||||
*self.read_immediate(self.operand_field(input, index)?)?,
|
||||
place
|
||||
)?;
|
||||
self.operand_field(input, i)?
|
||||
};
|
||||
self.copy_op(value, place)?;
|
||||
}
|
||||
}
|
||||
"simd_extract" => {
|
||||
@ -277,7 +275,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
let (len, e_ty) = self.read_vector_ty(args[0]);
|
||||
assert!(
|
||||
index < len,
|
||||
"index `{}` must be in bounds of vector type `{}`: `[0, {})`",
|
||||
"index `{}` is out-of-bounds of vector type `{}` with length `{}`",
|
||||
index, e_ty, len
|
||||
);
|
||||
assert_eq!(
|
||||
@ -285,10 +283,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
"Return type `{}` must match vector element type `{}`",
|
||||
dest.layout.ty, e_ty
|
||||
);
|
||||
self.write_immediate(
|
||||
*self.read_immediate(self.operand_field(args[0], index)?)?,
|
||||
dest
|
||||
)?;
|
||||
self.copy_op(self.operand_field(args[0], index)?, dest)?;
|
||||
}
|
||||
_ => return Ok(false),
|
||||
}
|
||||
|
22
src/test/ui/consts/const-eval/simd/extract-fail0.rs
Normal file
22
src/test/ui/consts/const-eval/simd/extract-fail0.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// failure-status: 101
|
||||
// rustc-env:RUST_BACKTRACE=0
|
||||
#![feature(const_fn)]
|
||||
#![feature(repr_simd)]
|
||||
#![feature(platform_intrinsics)]
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
#[repr(simd)] struct i8x1(i8);
|
||||
|
||||
extern "platform-intrinsic" {
|
||||
fn simd_extract<T, U>(x: T, idx: u32) -> U;
|
||||
}
|
||||
|
||||
const X: i8x1 = i8x1(42);
|
||||
|
||||
const fn extract_wrong_ret() -> i16 {
|
||||
unsafe { simd_extract(X, 0_u32) }
|
||||
}
|
||||
|
||||
const A: i16 = extract_wrong_ret();
|
||||
|
||||
fn main() {}
|
15
src/test/ui/consts/const-eval/simd/extract-fail0.stderr
Normal file
15
src/test/ui/consts/const-eval/simd/extract-fail0.stderr
Normal file
@ -0,0 +1,15 @@
|
||||
thread 'rustc' panicked at 'assertion failed: `(left == right)`
|
||||
left: `i8`,
|
||||
right: `i16`: Return type `i16` must match vector element type `i8`', src/librustc_mir/interpret/intrinsics.rs:281:17
|
||||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
|
||||
|
||||
error: internal compiler error: unexpected panic
|
||||
|
||||
note: the compiler unexpectedly panicked. this is a bug.
|
||||
|
||||
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
|
||||
|
||||
note: rustc 1.39.0-dev running on x86_64-apple-darwin
|
||||
|
||||
note: compiler flags: -Z threads=1 -Z ui-testing -Z unstable-options -C prefer-dynamic -C rpath -C debuginfo=0
|
||||
|
22
src/test/ui/consts/const-eval/simd/extract-fail1.rs
Normal file
22
src/test/ui/consts/const-eval/simd/extract-fail1.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// failure-status: 101
|
||||
// rustc-env:RUST_BACKTRACE=0
|
||||
#![feature(const_fn)]
|
||||
#![feature(repr_simd)]
|
||||
#![feature(platform_intrinsics)]
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
#[repr(simd)] struct i8x1(i8);
|
||||
|
||||
extern "platform-intrinsic" {
|
||||
fn simd_extract<T, U>(x: T, idx: u32) -> U;
|
||||
}
|
||||
|
||||
const X: i8x1 = i8x1(42);
|
||||
|
||||
const fn extract_wrong_vec() -> i8 {
|
||||
unsafe { simd_extract(42_i8, 0_u32) }
|
||||
}
|
||||
|
||||
const B: i8 = extract_wrong_vec();
|
||||
|
||||
fn main() {}
|
15
src/test/ui/consts/const-eval/simd/extract-fail1.stderr
Normal file
15
src/test/ui/consts/const-eval/simd/extract-fail1.stderr
Normal file
@ -0,0 +1,15 @@
|
||||
error: internal compiler error: src/librustc_mir/interpret/operand.rs:346: Type `i8` is not a SIMD vector type
|
||||
|
||||
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:643:9
|
||||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
|
||||
|
||||
note: the compiler unexpectedly panicked. this is a bug.
|
||||
|
||||
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
|
||||
|
||||
note: rustc 1.39.0-dev running on x86_64-apple-darwin
|
||||
|
||||
note: compiler flags: -Z threads=1 -Z ui-testing -Z unstable-options -C prefer-dynamic -C rpath -C debuginfo=0
|
||||
|
||||
error: aborting due to previous error
|
||||
|
22
src/test/ui/consts/const-eval/simd/extract-fail2.rs
Normal file
22
src/test/ui/consts/const-eval/simd/extract-fail2.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// failure-status: 101
|
||||
// rustc-env:RUST_BACKTRACE=0
|
||||
#![feature(const_fn)]
|
||||
#![feature(repr_simd)]
|
||||
#![feature(platform_intrinsics)]
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
#[repr(simd)] struct i8x1(i8);
|
||||
|
||||
extern "platform-intrinsic" {
|
||||
fn simd_extract<T, U>(x: T, idx: u32) -> U;
|
||||
}
|
||||
|
||||
const X: i8x1 = i8x1(42);
|
||||
|
||||
const fn extract_wrong_idx() -> i8 {
|
||||
unsafe { simd_extract(X, 1_u32) }
|
||||
}
|
||||
|
||||
const C: i8 = extract_wrong_idx();
|
||||
|
||||
fn main() {}
|
13
src/test/ui/consts/const-eval/simd/extract-fail2.stderr
Normal file
13
src/test/ui/consts/const-eval/simd/extract-fail2.stderr
Normal file
@ -0,0 +1,13 @@
|
||||
thread 'rustc' panicked at 'index `1` is out-of-bounds of vector type `i8` with length `1`', src/librustc_mir/interpret/intrinsics.rs:276:17
|
||||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
|
||||
|
||||
error: internal compiler error: unexpected panic
|
||||
|
||||
note: the compiler unexpectedly panicked. this is a bug.
|
||||
|
||||
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
|
||||
|
||||
note: rustc 1.39.0-dev running on x86_64-apple-darwin
|
||||
|
||||
note: compiler flags: -Z threads=1 -Z ui-testing -Z unstable-options -C prefer-dynamic -C rpath -C debuginfo=0
|
||||
|
22
src/test/ui/consts/const-eval/simd/insert-fail0.rs
Normal file
22
src/test/ui/consts/const-eval/simd/insert-fail0.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// failure-status: 101
|
||||
// rustc-env:RUST_BACKTRACE=0
|
||||
#![feature(const_fn)]
|
||||
#![feature(repr_simd)]
|
||||
#![feature(platform_intrinsics)]
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
#[repr(simd)] struct i8x1(i8);
|
||||
|
||||
extern "platform-intrinsic" {
|
||||
fn simd_insert<T, U>(x: T, idx: u32, val: U) -> T;
|
||||
}
|
||||
|
||||
const X: i8x1 = i8x1(42);
|
||||
|
||||
const fn insert_wrong_scalar() -> i8x1 {
|
||||
unsafe { simd_insert(X, 0_u32, 42_i16) }
|
||||
}
|
||||
|
||||
const D: i8x1 = insert_wrong_scalar();
|
||||
|
||||
fn main() {}
|
15
src/test/ui/consts/const-eval/simd/insert-fail0.stderr
Normal file
15
src/test/ui/consts/const-eval/simd/insert-fail0.stderr
Normal file
@ -0,0 +1,15 @@
|
||||
thread 'rustc' panicked at 'assertion failed: `(left == right)`
|
||||
left: `i16`,
|
||||
right: `i8`: Scalar type `i16` must match vector element type `i8`', src/librustc_mir/interpret/intrinsics.rs:257:17
|
||||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
|
||||
|
||||
error: internal compiler error: unexpected panic
|
||||
|
||||
note: the compiler unexpectedly panicked. this is a bug.
|
||||
|
||||
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
|
||||
|
||||
note: rustc 1.39.0-dev running on x86_64-apple-darwin
|
||||
|
||||
note: compiler flags: -Z threads=1 -Z ui-testing -Z unstable-options -C prefer-dynamic -C rpath -C debuginfo=0
|
||||
|
22
src/test/ui/consts/const-eval/simd/insert-fail1.rs
Normal file
22
src/test/ui/consts/const-eval/simd/insert-fail1.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// failure-status: 101
|
||||
// rustc-env:RUST_BACKTRACE=0
|
||||
#![feature(const_fn)]
|
||||
#![feature(repr_simd)]
|
||||
#![feature(platform_intrinsics)]
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
#[repr(simd)] struct i8x1(i8);
|
||||
|
||||
extern "platform-intrinsic" {
|
||||
fn simd_insert<T, U>(x: T, idx: u32, val: U) -> T;
|
||||
}
|
||||
|
||||
const X: i8x1 = i8x1(42);
|
||||
|
||||
const fn insert_wrong_idx() -> i8x1 {
|
||||
unsafe { simd_insert(X, 1_u32, 42_i8) }
|
||||
}
|
||||
|
||||
const E: i8x1 = insert_wrong_idx();
|
||||
|
||||
fn main() {}
|
13
src/test/ui/consts/const-eval/simd/insert-fail1.stderr
Normal file
13
src/test/ui/consts/const-eval/simd/insert-fail1.stderr
Normal file
@ -0,0 +1,13 @@
|
||||
thread 'rustc' panicked at 'Index `1` must be in bounds of vector type `i8`: `[0, 1)`', src/librustc_mir/interpret/intrinsics.rs:247:17
|
||||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
|
||||
|
||||
error: internal compiler error: unexpected panic
|
||||
|
||||
note: the compiler unexpectedly panicked. this is a bug.
|
||||
|
||||
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
|
||||
|
||||
note: rustc 1.39.0-dev running on x86_64-apple-darwin
|
||||
|
||||
note: compiler flags: -Z threads=1 -Z ui-testing -Z unstable-options -C prefer-dynamic -C rpath -C debuginfo=0
|
||||
|
@ -1,27 +0,0 @@
|
||||
#![feature(const_fn)]
|
||||
#![feature(repr_simd)]
|
||||
#![feature(platform_intrinsics)]
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
#[repr(simd)] struct i8x1(i8);
|
||||
|
||||
extern "platform-intrinsic" {
|
||||
fn simd_insert<T, U>(x: T, idx: u32, val: U) -> T;
|
||||
fn simd_extract<T, U>(x: T, idx: u32) -> U;
|
||||
}
|
||||
|
||||
const fn foo(x: i8x1) -> i8 {
|
||||
// 42 is a i16 that does not fit in a i8
|
||||
unsafe { simd_insert(x, 0_u32, 42_i16) }.0 //~ ERROR
|
||||
}
|
||||
|
||||
const fn bar(x: i8x1) -> i16 {
|
||||
// the i8 is not a i16:
|
||||
unsafe { simd_extract(x, 0_u32) } //~ ERROR
|
||||
}
|
||||
|
||||
fn main() {
|
||||
const V: i8x1 = i8x1(13);
|
||||
const X: i8 = foo(V);
|
||||
const Y: i16 = bar(V);
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
error: any use of this value will cause an error
|
||||
--> $DIR/insert_extract-fail.rs:14:14
|
||||
|
|
||||
LL | unsafe { simd_insert(x, 0_u32, 42_i16) }.0
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| Inserting `i16` with size `2` to a vector element place of size `1`
|
||||
| inside call to `foo` at $DIR/insert_extract-fail.rs:19:19
|
||||
...
|
||||
LL | const X: i8 = foo(V);
|
||||
| ---------------------
|
||||
|
|
||||
= note: `#[deny(const_err)]` on by default
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -1,17 +0,0 @@
|
||||
#![feature(const_fn)]
|
||||
#![feature(platform_intrinsics)]
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
extern "platform-intrinsic" {
|
||||
fn simd_extract<T, U>(x: T, idx: u32) -> U;
|
||||
}
|
||||
|
||||
const fn foo(x: i8) -> i8 {
|
||||
// i8 is not a vector type:
|
||||
unsafe { simd_extract(x, 0_u32) } //~ ERROR
|
||||
}
|
||||
|
||||
fn main() {
|
||||
const V: i8 = 13;
|
||||
const X: i8 = foo(V);
|
||||
}
|
Loading…
Reference in New Issue
Block a user