Skip to content

Commit 2153abb

Browse files
committed
Add handling of float arrays to miri_to_const
1 parent b4ff774 commit 2153abb

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

clippy_lints/src/consts.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,41 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
492492
},
493493
_ => None,
494494
},
495+
ty::ConstKind::Value(ConstValue::ByRef { alloc, offset: _ }) => match result.ty.kind {
496+
ty::Array(sub_type, len) => match sub_type.kind {
497+
ty::Float(FloatTy::F32) => match miri_to_const(len) {
498+
Some(Constant::Int(len)) => alloc
499+
.inspect_with_undef_and_ptr_outside_interpreter(0..(4 * len as usize))
500+
.to_owned()
501+
.chunks(4)
502+
.map(|chunk| {
503+
Some(Constant::F32(f32::from_le_bytes(
504+
chunk.try_into().expect("this shouldn't happen"),
505+
)))
506+
})
507+
.collect::<Option<Vec<Constant>>>()
508+
.map(Constant::Vec),
509+
_ => None,
510+
},
511+
ty::Float(FloatTy::F64) => match miri_to_const(len) {
512+
Some(Constant::Int(len)) => alloc
513+
.inspect_with_undef_and_ptr_outside_interpreter(0..(8 * len as usize))
514+
.to_owned()
515+
.chunks(8)
516+
.map(|chunk| {
517+
Some(Constant::F64(f64::from_le_bytes(
518+
chunk.try_into().expect("this shouldn't happen"),
519+
)))
520+
})
521+
.collect::<Option<Vec<Constant>>>()
522+
.map(Constant::Vec),
523+
_ => None,
524+
},
525+
// FIXME: implement other array type conversions.
526+
_ => None,
527+
},
528+
_ => None,
529+
},
495530
// FIXME: implement other conversions.
496531
_ => None,
497532
}

0 commit comments

Comments
 (0)