@@ -184,23 +184,25 @@ impl<'tcx> OpTy<'tcx> {
184
184
impl < ' a , ' mir , ' tcx , M : Machine < ' mir , ' tcx > > EvalContext < ' a , ' mir , ' tcx , M > {
185
185
/// Try reading a value in memory; this is interesting particularily for ScalarPair.
186
186
/// Return None if the layout does not permit loading this as a value.
187
- fn try_read_value_from_ptr (
187
+ fn try_read_value_from_mplace (
188
188
& self ,
189
- ptr : Scalar ,
190
- ptr_align : Align ,
191
- layout : TyLayout < ' tcx > ,
189
+ mplace : MPlaceTy < ' tcx > ,
192
190
) -> EvalResult < ' tcx , Option < Value > > {
191
+ if mplace. extra != PlaceExtra :: None {
192
+ return Ok ( None ) ;
193
+ }
194
+ let ( ptr, ptr_align) = mplace. to_scalar_ptr_align ( ) ;
193
195
self . memory . check_align ( ptr, ptr_align) ?;
194
196
195
- if layout. size . bytes ( ) == 0 {
197
+ if mplace . layout . size . bytes ( ) == 0 {
196
198
return Ok ( Some ( Value :: Scalar ( ScalarMaybeUndef :: Scalar ( Scalar :: Bits { bits : 0 , size : 0 } ) ) ) ) ;
197
199
}
198
200
199
201
let ptr = ptr. to_ptr ( ) ?;
200
202
201
- match layout. abi {
203
+ match mplace . layout . abi {
202
204
layout:: Abi :: Scalar ( ..) => {
203
- let scalar = self . memory . read_scalar ( ptr, ptr_align, layout. size ) ?;
205
+ let scalar = self . memory . read_scalar ( ptr, ptr_align, mplace . layout . size ) ?;
204
206
Ok ( Some ( Value :: Scalar ( scalar) ) )
205
207
}
206
208
layout:: Abi :: ScalarPair ( ref a, ref b) => {
@@ -226,21 +228,18 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
226
228
/// in a `Value`, not on which data is stored there currently.
227
229
pub ( super ) fn try_read_value (
228
230
& self ,
229
- OpTy { op : src, layout } : OpTy < ' tcx > ,
231
+ src : OpTy < ' tcx > ,
230
232
) -> EvalResult < ' tcx , Result < Value , MemPlace > > {
231
- match src {
232
- Operand :: Indirect ( mplace) => {
233
- if mplace. extra == PlaceExtra :: None {
234
- if let Some ( val) =
235
- self . try_read_value_from_ptr ( mplace. ptr , mplace. align , layout) ?
236
- {
237
- return Ok ( Ok ( val) ) ;
238
- }
233
+ Ok ( match src. try_as_mplace ( ) {
234
+ Ok ( mplace) => {
235
+ if let Some ( val) = self . try_read_value_from_mplace ( mplace) ? {
236
+ Ok ( val)
237
+ } else {
238
+ Err ( * mplace)
239
239
}
240
- Ok ( Err ( mplace) )
241
240
} ,
242
- Operand :: Immediate ( val) => Ok ( Ok ( val) ) ,
243
- }
241
+ Err ( val) => Ok ( val) ,
242
+ } )
244
243
}
245
244
246
245
/// Read a value from a place, asserting that that is possible with the given layout.
0 commit comments