From b478fcf2705dee1ee0a03461c0dd3856760c42eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannis=20Christopher=20K=C3=B6hl?= Date: Wed, 26 Oct 2022 14:46:27 +0200 Subject: [PATCH] Use new cast methods --- .../src/dataflow_const_prop.rs | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index 1eeebfabba7..acb0f7b95ab 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -128,23 +128,26 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'tcx> { ) -> ValueOrPlaceOrRef { match rvalue { Rvalue::Cast( - CastKind::IntToInt + kind @ (CastKind::IntToInt | CastKind::FloatToInt | CastKind::FloatToFloat - | CastKind::IntToFloat, + | CastKind::IntToFloat), operand, ty, - ) => { - let operand = self.eval_operand(operand, state); - match operand { - FlatSet::Elem(operand) => self - .ecx - .misc_cast(&operand, *ty) - .map(|result| ValueOrPlaceOrRef::Value(self.wrap_immediate(result, *ty))) - .unwrap_or(ValueOrPlaceOrRef::top()), - _ => ValueOrPlaceOrRef::top(), + ) => match self.eval_operand(operand, state) { + FlatSet::Elem(op) => match kind { + CastKind::IntToInt | CastKind::IntToFloat => { + self.ecx.int_to_int_or_float(&op, *ty) + } + CastKind::FloatToInt | CastKind::FloatToFloat => { + self.ecx.float_to_float_or_int(&op, *ty) + } + _ => unreachable!(), } - } + .map(|result| ValueOrPlaceOrRef::Value(self.wrap_immediate(result, *ty))) + .unwrap_or(ValueOrPlaceOrRef::top()), + _ => ValueOrPlaceOrRef::top(), + }, Rvalue::BinaryOp(op, box (left, right)) => { // Overflows must be ignored here. let (val, _overflow) = self.binary_op(state, *op, left, right);