Skip to content

Commit

Permalink
use get_size_and_align to test if an allocation is live
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Jul 4, 2019
1 parent 842bbd2 commit 317c6ac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/librustc_mir/const_eval.rs
Expand Up @@ -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>>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/machine.rs
Expand Up @@ -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>>,
Expand Down
17 changes: 8 additions & 9 deletions src/librustc_mir/interpret/validity.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
.is_err()
{
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",
Expand Down

0 comments on commit 317c6ac

Please sign in to comment.