use get_size_and_align to test if an allocation is live
This commit is contained in:
parent
842bbd2764
commit
317c6ac129
@ -372,7 +372,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn call_extra_fn(
|
fn call_extra_fn(
|
||||||
_ecx: &mut InterpretCx<'mir, 'tcx, Self>,
|
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
|
||||||
fn_val: !,
|
fn_val: !,
|
||||||
_args: &[OpTy<'tcx>],
|
_args: &[OpTy<'tcx>],
|
||||||
_dest: Option<PlaceTy<'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
|
/// Execute `fn_val`. it is the hook's responsibility to advance the instruction
|
||||||
/// pointer as appropriate.
|
/// pointer as appropriate.
|
||||||
fn call_extra_fn(
|
fn call_extra_fn(
|
||||||
ecx: &mut InterpretCx<'mir, 'tcx, Self>,
|
ecx: &mut InterpCx<'mir, 'tcx, Self>,
|
||||||
fn_val: Self::ExtraFnVal,
|
fn_val: Self::ExtraFnVal,
|
||||||
args: &[OpTy<'tcx, Self::PointerTag>],
|
args: &[OpTy<'tcx, Self::PointerTag>],
|
||||||
dest: Option<PlaceTy<'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::layout::{self, TyLayout, LayoutOf, VariantIdx};
|
||||||
use rustc::ty;
|
use rustc::ty;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc::mir::interpret::{
|
|
||||||
GlobalAlloc, InterpResult, InterpError,
|
|
||||||
};
|
|
||||||
|
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
OpTy, Machine, InterpCx, ValueVisitor, MPlaceTy,
|
GlobalAlloc, InterpResult, InterpError,
|
||||||
|
OpTy, Machine, InterpCx, ValueVisitor, MPlaceTy, AllocCheck,
|
||||||
};
|
};
|
||||||
|
|
||||||
macro_rules! validation_failure {
|
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.
|
// Only NULL is the niche. So make sure the ptr is NOT NULL.
|
||||||
if self.ecx.memory.ptr_may_be_null(ptr) {
|
if self.ecx.memory.ptr_may_be_null(ptr) {
|
||||||
// These conditions are just here to improve the diagnostics so we can
|
// 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() &&
|
if self.ref_tracking_for_consts.is_some() &&
|
||||||
self.ecx.memory.get(ptr.alloc_id).is_err() &&
|
self.ecx.memory.get_size_and_align(ptr.alloc_id, AllocCheck::Live)
|
||||||
self.ecx.memory.get_fn(ptr.into()).is_err() {
|
.is_err()
|
||||||
|
{
|
||||||
return validation_failure!(
|
return validation_failure!(
|
||||||
"encountered dangling pointer", self.path
|
"a dangling pointer", self.path
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return validation_failure!("a potentially NULL pointer", self.path);
|
return validation_failure!("a potentially NULL pointer", self.path);
|
||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
} else {
|
} else {
|
||||||
// Conservatively, we reject, because the pointer *could* have this
|
// Conservatively, we reject, because the pointer *could* have a bad
|
||||||
// value.
|
// value.
|
||||||
return validation_failure!(
|
return validation_failure!(
|
||||||
"a pointer",
|
"a pointer",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user