@@ -203,30 +203,14 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
203203 let alloc_align = alloc. inner ( ) . align ;
204204 assert ! ( alloc_align >= layout. align. abi) ;
205205
206- // Returns `None` when the value is partially undefined or any byte of it has provenance.
207- // Otherwise returns the value or (if the entire value is undef) returns an undef.
208206 let read_scalar = |start, size, s : abi:: Scalar , ty| {
209- let range = alloc_range ( start, size) ;
210207 match alloc. 0 . read_scalar (
211208 bx,
212- range ,
209+ alloc_range ( start , size ) ,
213210 /*read_provenance*/ matches ! ( s. primitive( ) , abi:: Primitive :: Pointer ( _) ) ,
214211 ) {
215- Ok ( val) => Some ( bx. scalar_to_backend ( val, s, ty) ) ,
216- Err ( _) => {
217- // We may have failed due to partial provenance or unexpected provenance,
218- // continue down the normal code path if so.
219- if alloc. 0 . provenance ( ) . range_empty ( range, & bx. tcx ( ) )
220- // Since `read_scalar` failed, but there were no relocations involved, the
221- // bytes must be partially or fully uninitialized. Thus we can now unwrap the
222- // information about the range of uninit bytes and check if it's the full range.
223- && alloc. 0 . init_mask ( ) . is_range_initialized ( range) . unwrap_err ( ) == range
224- {
225- Some ( bx. const_undef ( ty) )
226- } else {
227- None
228- }
229- }
212+ Ok ( val) => bx. scalar_to_backend ( val, s, ty) ,
213+ Err ( _) => bx. const_poison ( ty) ,
230214 }
231215 } ;
232216
@@ -237,14 +221,16 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
237221 // check that walks over the type of `mplace` to make sure it is truly correct to treat this
238222 // like a `Scalar` (or `ScalarPair`).
239223 match layout. backend_repr {
240- BackendRepr :: Scalar ( s) => {
224+ BackendRepr :: Scalar ( s @ abi :: Scalar :: Initialized { .. } ) => {
241225 let size = s. size ( bx) ;
242226 assert_eq ! ( size, layout. size, "abi::Scalar size does not match layout size" ) ;
243- if let Some ( val) = read_scalar ( offset, size, s, bx. immediate_backend_type ( layout) ) {
244- return OperandRef { val : OperandValue :: Immediate ( val) , layout } ;
245- }
227+ let val = read_scalar ( offset, size, s, bx. immediate_backend_type ( layout) ) ;
228+ OperandRef { val : OperandValue :: Immediate ( val) , layout }
246229 }
247- BackendRepr :: ScalarPair ( a, b) => {
230+ BackendRepr :: ScalarPair (
231+ a @ abi:: Scalar :: Initialized { .. } ,
232+ b @ abi:: Scalar :: Initialized { .. } ,
233+ ) => {
248234 let ( a_size, b_size) = ( a. size ( bx) , b. size ( bx) ) ;
249235 let b_offset = ( offset + a_size) . align_to ( b. align ( bx) . abi ) ;
250236 assert ! ( b_offset. bytes( ) > 0 ) ;
@@ -260,21 +246,20 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
260246 b,
261247 bx. scalar_pair_element_backend_type ( layout, 1 , true ) ,
262248 ) ;
263- if let ( Some ( a_val) , Some ( b_val) ) = ( a_val, b_val) {
264- return OperandRef { val : OperandValue :: Pair ( a_val, b_val) , layout } ;
265- }
249+ OperandRef { val : OperandValue :: Pair ( a_val, b_val) , layout }
250+ }
251+ _ if layout. is_zst ( ) => OperandRef :: zero_sized ( layout) ,
252+ _ => {
253+ // Neither a scalar nor scalar pair. Load from a place
254+ // FIXME: should we cache `const_data_from_alloc` to avoid repeating this for the
255+ // same `ConstAllocation`?
256+ let init = bx. const_data_from_alloc ( alloc) ;
257+ let base_addr = bx. static_addr_of ( init, alloc_align, None ) ;
258+
259+ let llval = bx. const_ptr_byte_offset ( base_addr, offset) ;
260+ bx. load_operand ( PlaceRef :: new_sized ( llval, layout) )
266261 }
267- _ if layout. is_zst ( ) => return OperandRef :: zero_sized ( layout) ,
268- _ => { }
269262 }
270- // Neither a scalar nor scalar pair. Load from a place
271- // FIXME: should we cache `const_data_from_alloc` to avoid repeating this for the
272- // same `ConstAllocation`?
273- let init = bx. const_data_from_alloc ( alloc) ;
274- let base_addr = bx. static_addr_of ( init, alloc_align, None ) ;
275-
276- let llval = bx. const_ptr_byte_offset ( base_addr, offset) ;
277- bx. load_operand ( PlaceRef :: new_sized ( llval, layout) )
278263 }
279264
280265 /// Asserts that this operand refers to a scalar and returns
0 commit comments