From 96d6efdf32f346c45f58897b2f7fff38a476cfbe Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 24 Dec 2019 02:04:07 +0100 Subject: [PATCH] Emit errors without halting interpretation --- src/diagnostics.rs | 16 ++++++++++------ src/lib.rs | 4 +++- src/stacked_borrows.rs | 15 ++++++++++----- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/diagnostics.rs b/src/diagnostics.rs index 2431d9230f36..504863b13427 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -70,10 +70,14 @@ pub fn register_err(e: InterpErrorInfo<'static>) { ECX.with(|ecx| ecx.borrow_mut().push(e)); } -pub fn process_errors(mut f: impl FnMut(InterpErrorInfo<'static>)) { - ECX.with(|ecx| { - for e in ecx.borrow_mut().drain(..) { - f(e); - } - }); +impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {} +pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> { + fn process_errors(&self) { + let this = self.eval_context_ref(); + ECX.with(|ecx| { + for e in ecx.borrow_mut().drain(..) { + report_err(this, e); + } + }); + } } diff --git a/src/lib.rs b/src/lib.rs index bf6b111754de..ae92a777d88e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,9 @@ pub use crate::shims::time::EvalContextExt as TimeEvalContextExt; pub use crate::shims::tls::{EvalContextExt as TlsEvalContextExt, TlsData}; pub use crate::shims::EvalContextExt as ShimsEvalContextExt; -pub use crate::diagnostics::{process_errors, register_err, report_err}; +pub use crate::diagnostics::{ + register_err, report_err, EvalContextExt as DiagnosticsEvalContextExt, +}; pub use crate::eval::{create_ecx, eval_main, MiriConfig, TerminationInfo}; pub use crate::helpers::EvalContextExt as HelpersEvalContextExt; pub use crate::machine::{ diff --git a/src/stacked_borrows.rs b/src/stacked_borrows.rs index 53a94e74cbf0..3d446c6b468e 100644 --- a/src/stacked_borrows.rs +++ b/src/stacked_borrows.rs @@ -10,11 +10,9 @@ use std::rc::Rc; use rustc_hir::Mutability; use rustc::mir::RetagKind; use rustc::ty::{self, layout::Size}; +use rustc_mir::interpret::InterpError; -use crate::{ - AllocId, HelpersEvalContextExt, ImmTy, Immediate, InterpResult, MPlaceTy, MemoryKind, - MiriMemoryKind, PlaceTy, Pointer, RangeMap, TerminationInfo, -}; +use crate::*; pub type PtrId = NonZeroU64; pub type CallId = NonZeroU64; @@ -269,7 +267,12 @@ impl<'tcx> Stack { fn check_protector(item: &Item, tag: Option, global: &GlobalState) -> InterpResult<'tcx> { if let Tag::Tagged(id) = item.tag { if Some(id) == global.tracked_pointer_tag { - throw_machine_stop!(TerminationInfo::PoppedTrackedPointerTag(item.clone())); + register_err( + InterpError::MachineStop(Box::new(TerminationInfo::PoppedTrackedPointerTag( + item.clone(), + ))) + .into(), + ); } } if let Some(call) = item.protector { @@ -630,6 +633,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx this.write_immediate(val, place)?; } + this.process_errors(); + Ok(()) } }