@@ -388,44 +388,31 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
388388 }
389389 }
390390 ty:: RawPtr ( ..) => {
391- // Check pointer part.
392- if self . ref_tracking_for_consts . is_some ( ) {
393- // Integers/floats in CTFE: For consistency with integers, we do not
394- // accept undef.
395- let _ptr = try_validation ! ( value. to_scalar_ptr( ) ,
396- "undefined address in raw pointer" , self . path) ;
397- } else {
398- // Remain consistent with `usize`: Accept anything.
399- }
400-
401- // Check metadata.
402- let meta = try_validation ! ( value. to_meta( ) ,
403- "uninitialized data in wide pointer metadata" , self . path) ;
404- let layout = self . ecx . layout_of ( value. layout . ty . builtin_deref ( true ) . unwrap ( ) . ty ) ?;
405- if layout. is_unsized ( ) {
406- self . check_wide_ptr_meta ( meta, layout) ?;
391+ // We are conservative with undef for integers, but try to
392+ // actually enforce our current rules for raw pointers.
393+ let place = try_validation ! ( self . ecx. ref_to_mplace( value) ,
394+ "undefined pointer" , self . path) ;
395+ if place. layout . is_unsized ( ) {
396+ self . check_wide_ptr_meta ( place. meta , place. layout ) ?;
407397 }
408398 }
409399 _ if ty. is_box ( ) || ty. is_region_ptr ( ) => {
410400 // Handle wide pointers.
411401 // Check metadata early, for better diagnostics
412- let ptr = try_validation ! ( value. to_scalar_ptr( ) ,
413- "undefined address in pointer" , self . path) ;
414- let meta = try_validation ! ( value. to_meta( ) ,
415- "uninitialized data in wide pointer metadata" , self . path) ;
416- let layout = self . ecx . layout_of ( value. layout . ty . builtin_deref ( true ) . unwrap ( ) . ty ) ?;
417- if layout. is_unsized ( ) {
418- self . check_wide_ptr_meta ( meta, layout) ?;
402+ let place = try_validation ! ( self . ecx. ref_to_mplace( value) ,
403+ "undefined pointer" , self . path) ;
404+ if place. layout . is_unsized ( ) {
405+ self . check_wide_ptr_meta ( place. meta , place. layout ) ?;
419406 }
420407 // Make sure this is dereferencable and all.
421- let ( size, align) = self . ecx . size_and_align_of ( meta, layout) ?
408+ let ( size, align) = self . ecx . size_and_align_of ( place . meta , place . layout ) ?
422409 // for the purpose of validity, consider foreign types to have
423410 // alignment and size determined by the layout (size will be 0,
424411 // alignment should take attributes into account).
425- . unwrap_or_else ( || ( layout. size , layout. align . abi ) ) ;
412+ . unwrap_or_else ( || ( place . layout . size , place . layout . align . abi ) ) ;
426413 let ptr: Option < _ > = match
427414 self . ecx . memory . check_ptr_access_align (
428- ptr,
415+ place . ptr ,
429416 size,
430417 Some ( align) ,
431418 CheckInAllocMsg :: InboundsTest ,
@@ -435,7 +422,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
435422 Err ( err) => {
436423 info ! (
437424 "{:?} did not pass access check for size {:?}, align {:?}" ,
438- ptr, size, align
425+ place . ptr, size, align
439426 ) ;
440427 match err. kind {
441428 err_unsup ! ( InvalidNullPointerUsage ) =>
@@ -459,7 +446,6 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
459446 } ;
460447 // Recursive checking
461448 if let Some ( ref mut ref_tracking) = self . ref_tracking_for_consts {
462- let place = self . ecx . ref_to_mplace ( value) ?;
463449 if let Some ( ptr) = ptr { // not a ZST
464450 // Skip validation entirely for some external statics
465451 let alloc_kind = self . ecx . tcx . alloc_map . lock ( ) . get ( ptr. alloc_id ) ;
0 commit comments