@@ -388,44 +388,31 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
388
388
}
389
389
}
390
390
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 ) ?;
407
397
}
408
398
}
409
399
_ if ty. is_box ( ) || ty. is_region_ptr ( ) => {
410
400
// Handle wide pointers.
411
401
// 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 ) ?;
419
406
}
420
407
// 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 ) ?
422
409
// for the purpose of validity, consider foreign types to have
423
410
// alignment and size determined by the layout (size will be 0,
424
411
// 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 ) ) ;
426
413
let ptr: Option < _ > = match
427
414
self . ecx . memory . check_ptr_access_align (
428
- ptr,
415
+ place . ptr ,
429
416
size,
430
417
Some ( align) ,
431
418
CheckInAllocMsg :: InboundsTest ,
@@ -435,7 +422,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
435
422
Err ( err) => {
436
423
info ! (
437
424
"{:?} did not pass access check for size {:?}, align {:?}" ,
438
- ptr, size, align
425
+ place . ptr, size, align
439
426
) ;
440
427
match err. kind {
441
428
err_unsup ! ( InvalidNullPointerUsage ) =>
@@ -459,7 +446,6 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
459
446
} ;
460
447
// Recursive checking
461
448
if let Some ( ref mut ref_tracking) = self . ref_tracking_for_consts {
462
- let place = self . ecx . ref_to_mplace ( value) ?;
463
449
if let Some ( ptr) = ptr { // not a ZST
464
450
// Skip validation entirely for some external statics
465
451
let alloc_kind = self . ecx . tcx . alloc_map . lock ( ) . get ( ptr. alloc_id ) ;
0 commit comments