|
11 | 11 | //! gets popped *during unwinding*, we take the panic payload and store it according to the extra
|
12 | 12 | //! metadata we remembered when pushing said frame.
|
13 | 13 |
|
| 14 | +use syntax::source_map::Span; |
14 | 15 | use rustc::mir;
|
15 |
| -use crate::*; |
16 |
| -use super::machine::FrameData; |
| 16 | +use rustc::ty::{self, layout::LayoutOf}; |
17 | 17 | use rustc_target::spec::PanicStrategy;
|
18 |
| -use crate::rustc_target::abi::LayoutOf; |
| 18 | + |
| 19 | +use crate::*; |
19 | 20 |
|
20 | 21 | /// Holds all of the relevant data for a call to
|
21 | 22 | /// `__rust_maybe_catch_panic`.
|
@@ -150,4 +151,37 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
150 | 151 | this.memory.extra.stacked_borrows.borrow_mut().end_call(extra.call_id);
|
151 | 152 | Ok(res)
|
152 | 153 | }
|
| 154 | + |
| 155 | + fn assert_panic( |
| 156 | + &mut self, |
| 157 | + span: Span, |
| 158 | + msg: &AssertMessage<'tcx>, |
| 159 | + unwind: Option<mir::BasicBlock>, |
| 160 | + ) -> InterpResult<'tcx> { |
| 161 | + use rustc::mir::interpret::PanicInfo::*; |
| 162 | + let this = self.eval_context_mut(); |
| 163 | + |
| 164 | + match msg { |
| 165 | + BoundsCheck { ref index, ref len } => { |
| 166 | + // First arg: Caller location. |
| 167 | + let location = this.alloc_caller_location_for_span(span)?; |
| 168 | + // Second arg: index. |
| 169 | + let index = this.read_scalar(this.eval_operand(index, None)?)?; |
| 170 | + // Third arg: len. |
| 171 | + let len = this.read_scalar(this.eval_operand(len, None)?)?; |
| 172 | + |
| 173 | + // Call the lang item. |
| 174 | + let panic_bounds_check = this.tcx.lang_items().panic_bounds_check_fn().unwrap(); |
| 175 | + let panic_bounds_check = ty::Instance::mono(this.tcx.tcx, panic_bounds_check); |
| 176 | + this.call_function( |
| 177 | + panic_bounds_check, |
| 178 | + &[location.ptr, index.not_undef()?, len.not_undef()?], |
| 179 | + None, |
| 180 | + StackPopCleanup::Goto { ret: None, unwind }, |
| 181 | + )?; |
| 182 | + } |
| 183 | + _ => unimplemented!() |
| 184 | + } |
| 185 | + Ok(()) |
| 186 | + } |
153 | 187 | }
|
0 commit comments