Skip to content

Commit

Permalink
Auto merge of rust-lang#9241 - Jarcho:ice_9238, r=xFrednet
Browse files Browse the repository at this point in the history
Fix ICE in `miri_to_const`

fixes rust-lang#9238
changelog: Fix ICE when using `#![feature(generic_const_exprs)]` in various lints
  • Loading branch information
bors committed Jul 25, 2022
2 parents 8882578 + ab6463e commit d72e5f2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
20 changes: 6 additions & 14 deletions clippy_utils/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,32 +619,24 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) -
},
mir::ConstantKind::Val(ConstValue::ByRef { alloc, offset: _ }, _) => match result.ty().kind() {
ty::Array(sub_type, len) => match sub_type.kind() {
ty::Float(FloatTy::F32) => match len.to_valtree().try_to_machine_usize(tcx) {
ty::Float(FloatTy::F32) => match len.kind().try_to_machine_usize(tcx) {
Some(len) => alloc
.inner()
.inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * usize::try_from(len).unwrap()))
.to_owned()
.chunks(4)
.map(|chunk| {
Some(Constant::F32(f32::from_le_bytes(
chunk.try_into().expect("this shouldn't happen"),
)))
})
.array_chunks::<4>()
.map(|&chunk| Some(Constant::F32(f32::from_le_bytes(chunk))))
.collect::<Option<Vec<Constant>>>()
.map(Constant::Vec),
_ => None,
},
ty::Float(FloatTy::F64) => match len.to_valtree().try_to_machine_usize(tcx) {
ty::Float(FloatTy::F64) => match len.kind().try_to_machine_usize(tcx) {
Some(len) => alloc
.inner()
.inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * usize::try_from(len).unwrap()))
.to_owned()
.chunks(8)
.map(|chunk| {
Some(Constant::F64(f64::from_le_bytes(
chunk.try_into().expect("this shouldn't happen"),
)))
})
.array_chunks::<8>()
.map(|&chunk| Some(Constant::F64(f64::from_le_bytes(chunk))))
.collect::<Option<Vec<Constant>>>()
.map(Constant::Vec),
_ => None,
Expand Down
1 change: 1 addition & 0 deletions clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(array_chunks)]
#![feature(box_patterns)]
#![feature(control_flow_enum)]
#![feature(let_else)]
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/crashes/ice-9238.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
#![warn(clippy::branches_sharing_code)]

const fn f() -> usize {
2
}
const C: [f64; f()] = [0f64; f()];

fn main() {
let _ = if true { C[0] } else { C[1] };
}

0 comments on commit d72e5f2

Please sign in to comment.