@@ -244,7 +244,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
244
244
}
245
245
246
246
/// 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 > > {
248
253
// FIXME we need to revisit this for #67176
249
254
if c. has_param ( ) {
250
255
return None ;
@@ -258,21 +263,31 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
258
263
// manually normalized.
259
264
let val = self . tcx . try_normalize_erasing_regions ( self . param_env , c. const_ ) . ok ( ) ?;
260
265
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 ) )
262
267
}
263
268
264
269
/// 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 > > {
266
276
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 ) )
268
278
}
269
279
270
280
/// Returns the value, if any, of evaluating `op`. Calls upon `eval_constant`
271
281
/// 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 > > {
273
288
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 ) ,
276
291
}
277
292
}
278
293
@@ -453,7 +468,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
453
468
cond : & Operand < ' tcx > ,
454
469
location : Location ,
455
470
) -> Option < !> {
456
- let value = & self . eval_operand ( cond, location) ?;
471
+ let value = & self . eval_operand ( cond, location, None ) ?;
457
472
trace ! ( "assertion on {:?} should be {:?}" , value, expected) ;
458
473
459
474
let expected = Scalar :: from_bool ( expected) ;
@@ -481,7 +496,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
481
496
let mut eval_to_int = |op| {
482
497
// This can be `None` if the lhs wasn't const propagated and we just
483
498
// triggered the assert on the value of the rhs.
484
- self . eval_operand ( op, location)
499
+ self . eval_operand ( op, location, None )
485
500
. and_then ( |op| self . ecx . read_immediate ( & op) . ok ( ) )
486
501
. map_or ( DbgVal :: Underscore , |op| DbgVal :: Val ( op. to_const_int ( ) ) )
487
502
} ;
@@ -546,7 +561,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
546
561
fn visit_constant ( & mut self , constant : & ConstOperand < ' tcx > , location : Location ) {
547
562
trace ! ( "visit_constant: {:?}" , constant) ;
548
563
self . super_constant ( constant, location) ;
549
- self . eval_constant ( constant, location) ;
564
+ self . eval_constant ( constant, location, None ) ;
550
565
}
551
566
552
567
fn visit_assign ( & mut self , place : & Place < ' tcx > , rvalue : & Rvalue < ' tcx > , location : Location ) {
@@ -626,7 +641,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
626
641
self . check_assertion ( * expected, msg, cond, location) ;
627
642
}
628
643
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 )
630
645
&& let Some ( value_const) =
631
646
self . use_ecx ( location, |this| this. ecx . read_scalar ( value) )
632
647
&& let Ok ( constant) = value_const. try_to_int ( )
0 commit comments