Skip to content
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

update Miri #113151

Merged
merged 64 commits into from
Jun 29, 2023
Merged
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift click to select a range
13c20f2
deref shim arguments with actual ty instead of declared ty
beepster4096 Nov 9, 2022
9d1d651
add deref_pointer_as
beepster4096 Jun 2, 2023
7380a4d
explain windows sync layouts
beepster4096 Jun 3, 2023
580e2b3
Select more TB fail tests
Vanille-N May 10, 2023
9667886
Auto merge of #2887 - Vanille-N:tb-mut-transmute, r=RalfJung
bors Jun 3, 2023
7444a50
use as_os_str_bytes
RalfJung Jun 3, 2023
c1a7783
Auto merge of #2915 - RalfJung:as_os_str_bytes, r=RalfJung
bors Jun 3, 2023
53187d7
Remove rustc-workspace-hack
ehuss Jun 4, 2023
5d01a6b
Auto merge of #2916 - ehuss:remove-workspace-hack, r=RalfJung
bors Jun 4, 2023
7a1cdf7
Differentiate between explicit accesses and accesses inserted by TB
Vanille-N Jun 5, 2023
98c5fce
Auto merge of #2918 - Vanille-N:tb-diags, r=RalfJung
bors Jun 5, 2023
c87f6d9
Revert error in doc comment
Vanille-N Jun 5, 2023
634c21f
Auto merge of #2919 - Vanille-N:tb-diags, r=RalfJung
bors Jun 5, 2023
be5f6b2
box_exclusive_violation
Vanille-N Jun 10, 2023
85533a3
Auto merge of #2922 - Vanille-N:tb-tests, r=RalfJung
bors Jun 11, 2023
6147833
Preparing for merge from rustc
RalfJung Jun 11, 2023
6ab7af4
Merge from rustc
RalfJung Jun 11, 2023
15a6362
Auto merge of #2924 - RalfJung:rustup, r=RalfJung
bors Jun 12, 2023
36e0c42
Preparing for merge from rustc
oli-obk Jun 15, 2023
24595f5
Merge from rustc
oli-obk Jun 15, 2023
52036f5
Auto merge of #2928 - oli-obk:rustup, r=oli-obk
bors Jun 15, 2023
b4b7cd6
Auto merge of #2661 - DrMeepster:deref_operand_as, r=oli-obk
bors Jun 15, 2023
8e930fd
Preparing for merge from rustc
RalfJung Jun 16, 2023
508675b
Merge from rustc
RalfJung Jun 16, 2023
c853744
Auto merge of #2930 - RalfJung:rustup, r=RalfJung
bors Jun 16, 2023
e2d2266
add tests for panicky drop in thread_local destructor
RalfJung Jun 16, 2023
f3b52fd
make test work cross-platform
RalfJung Jun 16, 2023
6f771c8
Auto merge of #2929 - RalfJung:tls-panic, r=RalfJung
bors Jun 16, 2023
5c9ad8b
comment tweaks
RalfJung Jun 16, 2023
20a2a24
Auto merge of #2932 - RalfJung:comment, r=RalfJung
bors Jun 16, 2023
dfd5037
Preparing for merge from rustc
RalfJung Jun 17, 2023
14155e9
Merge from rustc
RalfJung Jun 17, 2023
5f81d83
Auto merge of #2933 - RalfJung:rustup, r=RalfJung
bors Jun 17, 2023
e696299
Preparing for merge from rustc
RalfJung Jun 18, 2023
7cef286
Merge from rustc
RalfJung Jun 18, 2023
6ea5035
bless new tests
RalfJung Jun 19, 2023
f769045
Auto merge of #2935 - RalfJung:rustup, r=RalfJung
bors Jun 19, 2023
a004056
mmap/munmap/mremamp shims
saethlin Aug 13, 2022
69dc735
Make munmap throw unsup errors instead of trying to work
saethlin Jun 16, 2023
8fc8f13
Improve organization
saethlin Jun 17, 2023
b621c4d
Auto merge of #2520 - saethlin:mmap-shim, r=RalfJung
bors Jun 20, 2023
2bd9ade
Preparing for merge from rustc
RalfJung Jun 22, 2023
940cd59
Merge from rustc
RalfJung Jun 22, 2023
878c6ae
Auto merge of #2938 - RalfJung:rustup, r=RalfJung
bors Jun 22, 2023
65d60f9
drop perform_read_access (always read) in favor of zero_size
Vanille-N Jun 19, 2023
732f127
Update ui test crate
oli-obk Jun 26, 2023
3917774
Auto merge of #2941 - oli-obk:ui_test_bump, r=oli-obk
bors Jun 26, 2023
0ba4cdb
Make `--quiet` actually do something
oli-obk Jun 27, 2023
b567773
Auto merge of #2942 - oli-obk:ui_test_bump, r=RalfJung
bors Jun 27, 2023
c91fb78
Add trophy
cbeuw Jun 27, 2023
662388e
Auto merge of #2943 - cbeuw:patch-1, r=oli-obk
bors Jun 27, 2023
48294e4
Preparing for merge from rustc
oli-obk Jun 28, 2023
c10656e
Merge from rustc
oli-obk Jun 28, 2023
de9dc59
fmt
oli-obk Jun 28, 2023
984d29d
Auto merge of #2944 - oli-obk:rustup, r=oli-obk
bors Jun 28, 2023
e1b2951
Try running a sync automatically
oli-obk Jun 28, 2023
1ffe627
Auto merge of #2945 - oli-obk:gha_mk_pr, r=RalfJung
bors Jun 28, 2023
0671f14
Unique gets special treatment when -Zmiri-unique-is-unique
Vanille-N Jun 19, 2023
cec5ec4
Auto merge of #2936 - Vanille-N:unique, r=RalfJung
bors Jun 28, 2023
8d4b2bd
Preparing for merge from rustc
RalfJung Jun 29, 2023
cca0c81
Merge from rustc
RalfJung Jun 29, 2023
feed376
Auto merge of #2946 - RalfJung:rustup, r=RalfJung
bors Jun 29, 2023
a3cea7f
update lockfile
RalfJung Jun 29, 2023
78f58f9
Use a valid `target` directory in miri ui tests
oli-obk Jun 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
drop perform_read_access (always read) in favor of zero_size
  • Loading branch information
Vanille-N committed Jun 22, 2023
commit 65d60f9f11179bf0faa33f948131d454069b2be8
64 changes: 38 additions & 26 deletions src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 99,9 @@ impl<'tcx> Tree {
/// Policy for a new borrow.
#[derive(Debug, Clone, Copy)]
struct NewPermission {
/// Whether this borrow requires a read access on its parent.
/// `perform_read_access` is `true` for all pointers marked `dereferenceable`.
perform_read_access: bool,
/// Optionally ignore the actual size to do a zero-size reborrow.
/// If this is set then `dereferenceable` is not enforced.
zero_size: bool,
/// Which permission should the pointer start with.
initial_state: Permission,
/// Whether this pointer is part of the arguments of a function call.
Expand All @@ -128,28 128,27 @@ impl<'tcx> NewPermission {
// `&`s, which are excluded above.
_ => return None,
};
// This field happens to be redundant since right now we always do a read,
// but it could be useful in the future.
let perform_read_access = true;

let protector = (kind == RetagKind::FnEntry).then_some(ProtectorKind::StrongProtector);
Some(Self { perform_read_access, initial_state, protector })
Some(Self { zero_size: false, initial_state, protector })
}

// Boxes are not handled by `from_ref_ty`, they need special behavior
// implemented here.
fn from_box_ty(
/// Compute permission for `Box`-like type (`Box` always, and also `Unique` if enabled).
/// These pointers allow deallocation so need a different kind of protector not handled
/// by `from_ref_ty`.
fn from_unique_ty(
ty: Ty<'tcx>,
kind: RetagKind,
cx: &crate::MiriInterpCx<'_, 'tcx>,
zero_size: bool,
) -> Option<Self> {
let pointee = ty.builtin_deref(true).unwrap().ty;
pointee.is_unpin(*cx.tcx, cx.param_env()).then_some(()).map(|()| {
// Regular `Unpin` box, give it `noalias` but only a weak protector
// because it is valid to deallocate it within the function.
let ty_is_freeze = ty.is_freeze(*cx.tcx, cx.param_env());
Self {
perform_read_access: true,
zero_size,
initial_state: Permission::new_unique_2phase(ty_is_freeze),
protector: (kind == RetagKind::FnEntry).then_some(ProtectorKind::WeakProtector),
}
Expand Down Expand Up @@ -201,6 200,7 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
Ok(())
};

trace!("Reborrow of size {:?}", ptr_size);
let (alloc_id, base_offset, parent_prov) = if ptr_size > Size::ZERO {
this.ptr_get_alloc_id(place.ptr)?
} else {
Expand Down Expand Up @@ -276,8 276,8 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
let range = alloc_range(base_offset, ptr_size);
let mut tree_borrows = alloc_extra.borrow_tracker_tb().borrow_mut();

if new_perm.perform_read_access {
// Count this reborrow as a read access
// All reborrows incur a (possibly zero-sized) read access to the parent
{
let global = &this.machine.borrow_tracker.as_ref().unwrap();
let span = this.machine.current_span();
tree_borrows.perform_access(
Expand Down Expand Up @@ -308,12 308,19 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
// We want a place for where the ptr *points to*, so we get one.
let place = this.ref_to_mplace(val)?;

// Get a lower bound of the size of this place.
// (When `extern type` are involved, use the size of the known prefix.)
let size = this
.size_and_align_of_mplace(&place)?
.map(|(size, _)| size)
.unwrap_or(place.layout.size);
// Determine the size of the reborrow.
// For most types this is the entire size of the place, however
// - when `extern type` is involved we use the size of the known prefix,
// - if the pointer is not reborrowed (raw pointer) or if `zero_size` is set
// then we override the size to do a zero-length reborrow.
let reborrow_size = match new_perm {
Some(NewPermission { zero_size: false, .. }) =>
this.size_and_align_of_mplace(&place)?
.map(|(size, _)| size)
.unwrap_or(place.layout.size),
_ => Size::from_bytes(0),
};
trace!("Creating new permission: {:?} with size {:?}", new_perm, reborrow_size);

// This new tag is not guaranteed to actually be used.
//
Expand All @@ -324,7 331,7 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
let new_tag = this.machine.borrow_tracker.as_mut().unwrap().get_mut().new_ptr();

// Compute the actual reborrow.
let reborrowed = this.tb_reborrow(&place, size, new_perm, new_tag)?;
let reborrowed = this.tb_reborrow(&place, reborrow_size, new_perm, new_tag)?;

// Adjust pointer.
let new_place = place.map_provenance(|p| {
Expand Down Expand Up @@ -359,10 366,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
val: &ImmTy<'tcx, Provenance>,
) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> {
let this = self.eval_context_mut();
let new_perm = if let &ty::Ref(_, pointee, mutability) = val.layout.ty.kind() {
NewPermission::from_ref_ty(pointee, mutability, kind, this)
} else {
None
let new_perm = match val.layout.ty.kind() {
&ty::Ref(_, pointee, mutability) =>
NewPermission::from_ref_ty(pointee, mutability, kind, this),
_ => None,
};
this.tb_retag_reference(val, new_perm)
}
Expand Down Expand Up @@ -408,7 415,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
}

fn visit_box(&mut self, place: &PlaceTy<'tcx, Provenance>) -> InterpResult<'tcx> {
let new_perm = NewPermission::from_box_ty(place.layout.ty, self.kind, self.ecx);
let new_perm = NewPermission::from_unique_ty(
place.layout.ty,
self.kind,
self.ecx,
/* zero_size */ false,
);
self.retag_ptr_inplace(place, new_perm)
}

Expand Down Expand Up @@ -486,7 498,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
// FIXME: do we truly want a 2phase borrow here?
let new_perm = Some(NewPermission {
initial_state: Permission::new_unique_2phase(/*freeze*/ false),
perform_read_access: true,
zero_size: false,
protector: Some(ProtectorKind::StrongProtector),
});
let val = this.tb_retag_reference(&val, new_perm)?;
Expand Down