Skip to content

Commit

Permalink
Test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzlbg committed Sep 25, 2019
1 parent 5976674 commit e74a268
Show file tree
Hide file tree
Showing 14 changed files with 191 additions and 75 deletions.
25 changes: 10 additions & 15 deletions src/librustc_mir/interpret/intrinsics.rs
Expand Up @@ -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
);
Expand All @@ -261,34 +261,29 @@ 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" => {
let index = self.read_scalar(args[1])?.to_u32()? as _;
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!(
e_ty, dest.layout.ty,
"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),
}
Expand Down
22 changes: 22 additions & 0 deletions src/test/ui/consts/const-eval/simd/extract-fail0.rs
@@ -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 changes: 15 additions & 0 deletions src/test/ui/consts/const-eval/simd/extract-fail0.stderr
@@ -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 changes: 22 additions & 0 deletions src/test/ui/consts/const-eval/simd/extract-fail1.rs
@@ -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 changes: 15 additions & 0 deletions src/test/ui/consts/const-eval/simd/extract-fail1.stderr
@@ -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 changes: 22 additions & 0 deletions src/test/ui/consts/const-eval/simd/extract-fail2.rs
@@ -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 changes: 13 additions & 0 deletions src/test/ui/consts/const-eval/simd/extract-fail2.stderr
@@ -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 changes: 22 additions & 0 deletions src/test/ui/consts/const-eval/simd/insert-fail0.rs
@@ -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 changes: 15 additions & 0 deletions src/test/ui/consts/const-eval/simd/insert-fail0.stderr
@@ -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 changes: 22 additions & 0 deletions src/test/ui/consts/const-eval/simd/insert-fail1.rs
@@ -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 changes: 13 additions & 0 deletions src/test/ui/consts/const-eval/simd/insert-fail1.stderr
@@ -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

27 changes: 0 additions & 27 deletions src/test/ui/consts/const-eval/simd/insert_extract-fail.rs

This file was deleted.

16 changes: 0 additions & 16 deletions src/test/ui/consts/const-eval/simd/insert_extract-fail.stderr

This file was deleted.

17 changes: 0 additions & 17 deletions src/test/ui/consts/const-eval/simd/read_fail.rs

This file was deleted.

0 comments on commit e74a268

Please sign in to comment.