@@ -244,7 +244,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
244244 }
245245
246246 /// Returns the value, if any, of evaluating `c`.
247- fn eval_constant ( & mut self , c : & ConstOperand < ' tcx > , location : Location ) -> Option < OpTy < ' tcx > > {
247+ fn eval_constant (
248+ & mut self ,
249+ c : & ConstOperand < ' tcx > ,
250+ location : Location ,
251+ layout : Option < TyAndLayout < ' tcx > > ,
252+ ) -> Option < OpTy < ' tcx > > {
248253 // FIXME we need to revisit this for #67176
249254 if c. has_param ( ) {
250255 return None ;
@@ -258,21 +263,31 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
258263 // manually normalized.
259264 let val = self . tcx . try_normalize_erasing_regions ( self . param_env , c. const_ ) . ok ( ) ?;
260265
261- self . use_ecx ( location, |this| this. ecx . eval_mir_constant ( & val, Some ( c. span ) , None ) )
266+ self . use_ecx ( location, |this| this. ecx . eval_mir_constant ( & val, Some ( c. span ) , layout ) )
262267 }
263268
264269 /// Returns the value, if any, of evaluating `place`.
265- fn eval_place ( & mut self , place : Place < ' tcx > , location : Location ) -> Option < OpTy < ' tcx > > {
270+ fn eval_place (
271+ & mut self ,
272+ place : Place < ' tcx > ,
273+ location : Location ,
274+ layout : Option < TyAndLayout < ' tcx > > ,
275+ ) -> Option < OpTy < ' tcx > > {
266276 trace ! ( "eval_place(place={:?})" , place) ;
267- self . use_ecx ( location, |this| this. ecx . eval_place_to_op ( place, None ) )
277+ self . use_ecx ( location, |this| this. ecx . eval_place_to_op ( place, layout ) )
268278 }
269279
270280 /// Returns the value, if any, of evaluating `op`. Calls upon `eval_constant`
271281 /// or `eval_place`, depending on the variant of `Operand` used.
272- fn eval_operand ( & mut self , op : & Operand < ' tcx > , location : Location ) -> Option < OpTy < ' tcx > > {
282+ fn eval_operand (
283+ & mut self ,
284+ op : & Operand < ' tcx > ,
285+ location : Location ,
286+ layout : Option < TyAndLayout < ' tcx > > ,
287+ ) -> Option < OpTy < ' tcx > > {
273288 match * op {
274- Operand :: Constant ( ref c) => self . eval_constant ( c, location) ,
275- Operand :: Move ( place) | Operand :: Copy ( place) => self . eval_place ( place, location) ,
289+ Operand :: Constant ( ref c) => self . eval_constant ( c, location, layout ) ,
290+ Operand :: Move ( place) | Operand :: Copy ( place) => self . eval_place ( place, location, layout ) ,
276291 }
277292 }
278293
@@ -453,7 +468,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
453468 cond : & Operand < ' tcx > ,
454469 location : Location ,
455470 ) -> Option < !> {
456- let value = & self . eval_operand ( cond, location) ?;
471+ let value = & self . eval_operand ( cond, location, None ) ?;
457472 trace ! ( "assertion on {:?} should be {:?}" , value, expected) ;
458473
459474 let expected = Scalar :: from_bool ( expected) ;
@@ -481,7 +496,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
481496 let mut eval_to_int = |op| {
482497 // This can be `None` if the lhs wasn't const propagated and we just
483498 // triggered the assert on the value of the rhs.
484- self . eval_operand ( op, location)
499+ self . eval_operand ( op, location, None )
485500 . and_then ( |op| self . ecx . read_immediate ( & op) . ok ( ) )
486501 . map_or ( DbgVal :: Underscore , |op| DbgVal :: Val ( op. to_const_int ( ) ) )
487502 } ;
@@ -546,7 +561,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
546561 fn visit_constant ( & mut self , constant : & ConstOperand < ' tcx > , location : Location ) {
547562 trace ! ( "visit_constant: {:?}" , constant) ;
548563 self . super_constant ( constant, location) ;
549- self . eval_constant ( constant, location) ;
564+ self . eval_constant ( constant, location, None ) ;
550565 }
551566
552567 fn visit_assign ( & mut self , place : & Place < ' tcx > , rvalue : & Rvalue < ' tcx > , location : Location ) {
@@ -626,7 +641,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
626641 self . check_assertion ( * expected, msg, cond, location) ;
627642 }
628643 TerminatorKind :: SwitchInt { ref discr, ref targets } => {
629- if let Some ( ref value) = self . eval_operand ( discr, location)
644+ if let Some ( ref value) = self . eval_operand ( discr, location, None )
630645 && let Some ( value_const) =
631646 self . use_ecx ( location, |this| this. ecx . read_scalar ( value) )
632647 && let Ok ( constant) = value_const. try_to_int ( )
0 commit comments