Skip to content

Commit 317c6ac

Browse files
committed
use get_size_and_align to test if an allocation is live
1 parent 842bbd2 commit 317c6ac

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

src/librustc_mir/const_eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
372372
}
373373

374374
fn call_extra_fn(
375-
_ecx: &mut InterpretCx<'mir, 'tcx, Self>,
375+
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
376376
fn_val: !,
377377
_args: &[OpTy<'tcx>],
378378
_dest: Option<PlaceTy<'tcx>>,

src/librustc_mir/interpret/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
127127
/// Execute `fn_val`. it is the hook's responsibility to advance the instruction
128128
/// pointer as appropriate.
129129
fn call_extra_fn(
130-
ecx: &mut InterpretCx<'mir, 'tcx, Self>,
130+
ecx: &mut InterpCx<'mir, 'tcx, Self>,
131131
fn_val: Self::ExtraFnVal,
132132
args: &[OpTy<'tcx, Self::PointerTag>],
133133
dest: Option<PlaceTy<'tcx, Self::PointerTag>>,

src/librustc_mir/interpret/validity.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ use rustc::hir;
66
use rustc::ty::layout::{self, TyLayout, LayoutOf, VariantIdx};
77
use rustc::ty;
88
use rustc_data_structures::fx::FxHashSet;
9-
use rustc::mir::interpret::{
10-
GlobalAlloc, InterpResult, InterpError,
11-
};
129

1310
use std::hash::Hash;
1411

1512
use super::{
16-
OpTy, Machine, InterpCx, ValueVisitor, MPlaceTy,
13+
GlobalAlloc, InterpResult, InterpError,
14+
OpTy, Machine, InterpCx, ValueVisitor, MPlaceTy, AllocCheck,
1715
};
1816

1917
macro_rules! validation_failure {
@@ -505,19 +503,20 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
505503
// Only NULL is the niche. So make sure the ptr is NOT NULL.
506504
if self.ecx.memory.ptr_may_be_null(ptr) {
507505
// These conditions are just here to improve the diagnostics so we can
508-
// differentiate between null pointers and dangling pointers
506+
// differentiate between null pointers and dangling pointers.
509507
if self.ref_tracking_for_consts.is_some() &&
510-
self.ecx.memory.get(ptr.alloc_id).is_err() &&
511-
self.ecx.memory.get_fn(ptr.into()).is_err() {
508+
self.ecx.memory.get_size_and_align(ptr.alloc_id, AllocCheck::Live)
509+
.is_err()
510+
{
512511
return validation_failure!(
513-
"encountered dangling pointer", self.path
512+
"a dangling pointer", self.path
514513
);
515514
}
516515
return validation_failure!("a potentially NULL pointer", self.path);
517516
}
518517
return Ok(());
519518
} else {
520-
// Conservatively, we reject, because the pointer *could* have this
519+
// Conservatively, we reject, because the pointer *could* have a bad
521520
// value.
522521
return validation_failure!(
523522
"a pointer",

0 commit comments

Comments
 (0)