-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #66874 - RalfJung:miri-assert-panic, r=oli-obk
Miri engine: proper support for `Assert` MIR terminators This puts down the basis for rust-lang/miri#1070, and I also did some clean-up. The Miri side of this is at rust-lang/miri#1084. r? @oli-obk
- Loading branch information
Showing
13 changed files
with
195 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,48 @@ | ||
use rustc::middle::lang_items::PanicLocationLangItem; | ||
use rustc::mir::interpret::{Pointer, PointerArithmetic, Scalar}; | ||
use rustc::ty::subst::Subst; | ||
use rustc_target::abi::{LayoutOf, Size}; | ||
use syntax_pos::Symbol; | ||
use rustc_target::abi::LayoutOf; | ||
use syntax_pos::{Symbol, Span}; | ||
|
||
use crate::interpret::{MemoryKind, MPlaceTy, intrinsics::{InterpCx, InterpResult, Machine}}; | ||
use crate::interpret::{Scalar, MemoryKind, MPlaceTy, intrinsics::{InterpCx, Machine}}; | ||
|
||
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | ||
pub fn alloc_caller_location( | ||
crate fn alloc_caller_location( | ||
&mut self, | ||
filename: Symbol, | ||
line: u32, | ||
col: u32, | ||
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { | ||
) -> MPlaceTy<'tcx, M::PointerTag> { | ||
let file = self.allocate_str(&filename.as_str(), MemoryKind::CallerLocation); | ||
let line = Scalar::from_u32(line); | ||
let col = Scalar::from_u32(col); | ||
|
||
let ptr_size = self.pointer_size(); | ||
let u32_size = Size::from_bits(32); | ||
|
||
// Allocate memory for `CallerLocation` struct. | ||
let loc_ty = self.tcx.type_of(self.tcx.require_lang_item(PanicLocationLangItem, None)) | ||
.subst(*self.tcx, self.tcx.mk_substs([self.tcx.lifetimes.re_static.into()].iter())); | ||
let loc_layout = self.layout_of(loc_ty)?; | ||
|
||
let file_alloc = self.tcx.allocate_bytes(filename.as_str().as_bytes()); | ||
let file_ptr = Pointer::new(file_alloc, Size::ZERO); | ||
let file = Scalar::Ptr(self.tag_static_base_pointer(file_ptr)); | ||
let file_len = Scalar::from_uint(filename.as_str().len() as u128, ptr_size); | ||
|
||
let loc_layout = self.layout_of(loc_ty).unwrap(); | ||
let location = self.allocate(loc_layout, MemoryKind::CallerLocation); | ||
|
||
let file_out = self.mplace_field(location, 0)?; | ||
let file_ptr_out = self.force_ptr(self.mplace_field(file_out, 0)?.ptr)?; | ||
let file_len_out = self.force_ptr(self.mplace_field(file_out, 1)?.ptr)?; | ||
let line_out = self.force_ptr(self.mplace_field(location, 1)?.ptr)?; | ||
let col_out = self.force_ptr(self.mplace_field(location, 2)?.ptr)?; | ||
// Initialize fields. | ||
self.write_immediate(file.to_ref(), self.mplace_field(location, 0).unwrap().into()) | ||
.expect("writing to memory we just allocated cannot fail"); | ||
self.write_scalar(line, self.mplace_field(location, 1).unwrap().into()) | ||
.expect("writing to memory we just allocated cannot fail"); | ||
self.write_scalar(col, self.mplace_field(location, 2).unwrap().into()) | ||
.expect("writing to memory we just allocated cannot fail"); | ||
|
||
let layout = &self.tcx.data_layout; | ||
// We just allocated this, so we can skip the bounds checks. | ||
let alloc = self.memory.get_raw_mut(file_ptr_out.alloc_id)?; | ||
|
||
alloc.write_scalar(layout, file_ptr_out, file.into(), ptr_size)?; | ||
alloc.write_scalar(layout, file_len_out, file_len.into(), ptr_size)?; | ||
alloc.write_scalar(layout, line_out, line.into(), u32_size)?; | ||
alloc.write_scalar(layout, col_out, col.into(), u32_size)?; | ||
location | ||
} | ||
|
||
Ok(location) | ||
pub fn alloc_caller_location_for_span( | ||
&mut self, | ||
span: Span, | ||
) -> MPlaceTy<'tcx, M::PointerTag> { | ||
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span); | ||
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo()); | ||
self.alloc_caller_location( | ||
Symbol::intern(&caller.file.name.to_string()), | ||
caller.line as u32, | ||
caller.col_display as u32 + 1, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.