-
Notifications
You must be signed in to change notification settings - Fork 13.4k
refactor goto_block and also add unwind_to_block #66646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7bfed2e
refactor goto_block and also add unwind_to_block
RalfJung 5900b32
unify call_intrinsic handling of intruction pointer with other machin…
RalfJung 419d3fc
move ABI check out to cover all calls
RalfJung b91bf7a
miri: couple ret place and ret block together (they both exist or bot…
RalfJung 6797d52
make sure we handle all transmute invocations, including diverging ones
RalfJung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -9,8 +9,10 @@ use rustc::ty::layout::{LayoutOf, Primitive, Size}; | |
use rustc::ty::subst::SubstsRef; | ||
use rustc::hir::def_id::DefId; | ||
use rustc::ty::TyCtxt; | ||
use rustc::mir::BinOp; | ||
use rustc::mir::interpret::{InterpResult, Scalar, GlobalId, ConstValue}; | ||
use rustc::mir::{ | ||
self, BinOp, | ||
interpret::{InterpResult, Scalar, GlobalId, ConstValue} | ||
}; | ||
|
||
use super::{ | ||
Machine, PlaceTy, OpTy, InterpCx, ImmTy, | ||
|
@@ -91,16 +93,20 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |
span: Span, | ||
instance: ty::Instance<'tcx>, | ||
args: &[OpTy<'tcx, M::PointerTag>], | ||
dest: Option<PlaceTy<'tcx, M::PointerTag>>, | ||
ret: Option<(PlaceTy<'tcx, M::PointerTag>, mir::BasicBlock)>, | ||
) -> InterpResult<'tcx, bool> { | ||
let substs = instance.substs; | ||
let intrinsic_name = &*self.tcx.item_name(instance.def_id()).as_str(); | ||
|
||
// We currently do not handle any diverging intrinsics. | ||
let dest = match dest { | ||
Some(dest) => dest, | ||
None => return Ok(false) | ||
// We currently do not handle any intrinsics that are *allowed* to diverge, | ||
// but `transmute` could lack a return place in case of UB. | ||
let (dest, ret) = match ret { | ||
Some(p) => p, | ||
None => match intrinsic_name { | ||
"transmute" => throw_ub!(Unreachable), | ||
_ => return Ok(false), | ||
} | ||
}; | ||
let intrinsic_name = &*self.tcx.item_name(instance.def_id()).as_str(); | ||
|
||
match intrinsic_name { | ||
"caller_location" => { | ||
|
@@ -268,34 +274,39 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |
// exception from the exception.) | ||
// This is the dual to the special exception for offset-by-0 | ||
// in the inbounds pointer offset operation (see the Miri code, `src/operator.rs`). | ||
if a.is_bits() && b.is_bits() { | ||
// | ||
// Control flow is weird because we cannot early-return (to reach the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have a bunch of situations like that in miri... Maybe we should consider using |
||
// `go_to_block` at the end). | ||
let done = if a.is_bits() && b.is_bits() { | ||
let a = a.to_machine_usize(self)?; | ||
let b = b.to_machine_usize(self)?; | ||
if a == b && a != 0 { | ||
self.write_scalar(Scalar::from_int(0, isize_layout.size), dest)?; | ||
return Ok(true); | ||
} | ||
} | ||
true | ||
} else { false } | ||
} else { false }; | ||
|
||
// General case: we need two pointers. | ||
let a = self.force_ptr(a)?; | ||
let b = self.force_ptr(b)?; | ||
if a.alloc_id != b.alloc_id { | ||
throw_ub_format!( | ||
"ptr_offset_from cannot compute offset of pointers into different \ | ||
allocations.", | ||
); | ||
if !done { | ||
// General case: we need two pointers. | ||
let a = self.force_ptr(a)?; | ||
let b = self.force_ptr(b)?; | ||
if a.alloc_id != b.alloc_id { | ||
throw_ub_format!( | ||
"ptr_offset_from cannot compute offset of pointers into different \ | ||
allocations.", | ||
); | ||
} | ||
let usize_layout = self.layout_of(self.tcx.types.usize)?; | ||
let a_offset = ImmTy::from_uint(a.offset.bytes(), usize_layout); | ||
let b_offset = ImmTy::from_uint(b.offset.bytes(), usize_layout); | ||
let (val, _overflowed, _ty) = self.overflowing_binary_op( | ||
BinOp::Sub, a_offset, b_offset, | ||
)?; | ||
let pointee_layout = self.layout_of(substs.type_at(0))?; | ||
let val = ImmTy::from_scalar(val, isize_layout); | ||
let size = ImmTy::from_int(pointee_layout.size.bytes(), isize_layout); | ||
self.exact_div(val, size, dest)?; | ||
} | ||
let usize_layout = self.layout_of(self.tcx.types.usize)?; | ||
let a_offset = ImmTy::from_uint(a.offset.bytes(), usize_layout); | ||
let b_offset = ImmTy::from_uint(b.offset.bytes(), usize_layout); | ||
let (val, _overflowed, _ty) = self.overflowing_binary_op( | ||
BinOp::Sub, a_offset, b_offset, | ||
)?; | ||
let pointee_layout = self.layout_of(substs.type_at(0))?; | ||
let val = ImmTy::from_scalar(val, isize_layout); | ||
let size = ImmTy::from_int(pointee_layout.size.bytes(), isize_layout); | ||
self.exact_div(val, size, dest)?; | ||
} | ||
|
||
"transmute" => { | ||
|
@@ -350,6 +361,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |
_ => return Ok(false), | ||
} | ||
|
||
self.dump_place(*dest); | ||
self.go_to_block(ret); | ||
Ok(true) | ||
} | ||
|
||
|
@@ -360,7 +373,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |
&mut self, | ||
instance: ty::Instance<'tcx>, | ||
args: &[OpTy<'tcx, M::PointerTag>], | ||
_dest: Option<PlaceTy<'tcx, M::PointerTag>>, | ||
_ret: Option<(PlaceTy<'tcx, M::PointerTag>, mir::BasicBlock)>, | ||
) -> InterpResult<'tcx, bool> { | ||
let def_id = instance.def_id(); | ||
if Some(def_id) == self.tcx.lang_items().panic_fn() { | ||
|
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.