Skip to content
Browse files

use get_size_and_align to test if an allocation is live

  • Loading branch information...
RalfJung committed Jul 1, 2019
1 parent 842bbd2 commit 317c6ac12935046b04c349f6151148600d4c1512
Showing with 10 additions and 11 deletions.
  1. +1 −1 src/librustc_mir/
  2. +1 −1 src/librustc_mir/interpret/
  3. +8 −9 src/librustc_mir/interpret/
@@ -372,7 +372,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,

fn call_extra_fn(
_ecx: &mut InterpretCx<'mir, 'tcx, Self>,
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
fn_val: !,
_args: &[OpTy<'tcx>],
_dest: Option<PlaceTy<'tcx>>,
@@ -127,7 +127,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
/// Execute `fn_val`. it is the hook's responsibility to advance the instruction
/// pointer as appropriate.
fn call_extra_fn(
ecx: &mut InterpretCx<'mir, 'tcx, Self>,
ecx: &mut InterpCx<'mir, 'tcx, Self>,
fn_val: Self::ExtraFnVal,
args: &[OpTy<'tcx, Self::PointerTag>],
dest: Option<PlaceTy<'tcx, Self::PointerTag>>,
@@ -6,14 +6,12 @@ use rustc::hir;
use rustc::ty::layout::{self, TyLayout, LayoutOf, VariantIdx};
use rustc::ty;
use rustc_data_structures::fx::FxHashSet;
use rustc::mir::interpret::{
GlobalAlloc, InterpResult, InterpError,

use std::hash::Hash;

use super::{
OpTy, Machine, InterpCx, ValueVisitor, MPlaceTy,
GlobalAlloc, InterpResult, InterpError,
OpTy, Machine, InterpCx, ValueVisitor, MPlaceTy, AllocCheck,

macro_rules! validation_failure {
@@ -505,19 +503,20 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
// Only NULL is the niche. So make sure the ptr is NOT NULL.
if self.ecx.memory.ptr_may_be_null(ptr) {
// These conditions are just here to improve the diagnostics so we can
// differentiate between null pointers and dangling pointers
// differentiate between null pointers and dangling pointers.
if self.ref_tracking_for_consts.is_some() &&
self.ecx.memory.get(ptr.alloc_id).is_err() &&
self.ecx.memory.get_fn(ptr.into()).is_err() {
self.ecx.memory.get_size_and_align(ptr.alloc_id, AllocCheck::Live)
return validation_failure!(
"encountered dangling pointer", self.path
"a dangling pointer", self.path
return validation_failure!("a potentially NULL pointer", self.path);
return Ok(());
} else {
// Conservatively, we reject, because the pointer *could* have this
// Conservatively, we reject, because the pointer *could* have a bad
// value.
return validation_failure!(
"a pointer",

0 comments on commit 317c6ac

Please sign in to comment.
You can’t perform that action at this time.