This commit is contained in:
The Miri Conjob Bot 2023-07-03 06:35:03 +00:00
parent 1505dd86d1
commit 707afc389a
6 changed files with 53 additions and 35 deletions

View file

@ -221,7 +221,10 @@ impl AllocHistory {
impl<'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'history, 'ecx, 'mir, 'tcx> {
pub fn start_grant(&mut self, perm: Permission) {
let Operation::Retag(op) = &mut self.operation else {
unreachable!("start_grant must only be called during a retag, this is: {:?}", self.operation)
unreachable!(
"start_grant must only be called during a retag, this is: {:?}",
self.operation
)
};
op.permission = Some(perm);
@ -286,7 +289,8 @@ impl<'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'history, 'ecx, 'mir, 'tcx> {
tag: BorTag,
protector_tag: Option<BorTag>,
) -> Option<TagHistory> {
let Some(created) = self.history
let Some(created) = self
.history
.creations
.iter()
.rev()
@ -315,22 +319,27 @@ impl<'history, 'ecx, 'mir, 'tcx> DiagnosticCx<'history, 'ecx, 'mir, 'tcx> {
None
}
})
}).or_else(|| {
})
.or_else(|| {
// If we didn't find a retag that created this tag, it might be the base tag of
// this allocation.
if self.history.base.0.tag() == tag {
Some((
format!("{tag:?} was created here, as the base tag for {:?}", self.history.id),
self.history.base.1.data()
format!(
"{tag:?} was created here, as the base tag for {:?}",
self.history.id
),
self.history.base.1.data(),
))
} else {
None
}
}) else {
// But if we don't have a creation event, this is related to a wildcard, and there
// is really nothing we can do to help.
return None;
};
})
else {
// But if we don't have a creation event, this is related to a wildcard, and there
// is really nothing we can do to help.
return None;
};
let invalidated = self.history.invalidations.iter().rev().find_map(|event| {
if event.tag == tag { Some(event.generate_diagnostic()) } else { None }

View file

@ -430,12 +430,15 @@ impl<'tcx> Stack {
.find_granting(AccessKind::Write, derived_from, exposed_tags)
.map_err(|()| dcx.grant_error(self))?;
let (Some(granting_idx), ProvenanceExtra::Concrete(_)) = (granting_idx, derived_from) else {
let (Some(granting_idx), ProvenanceExtra::Concrete(_)) = (granting_idx, derived_from)
else {
// The parent is a wildcard pointer or matched the unknown bottom.
// This is approximate. Nobody knows what happened, so forget everything.
// The new thing is SRW anyway, so we cannot push it "on top of the unknown part"
// (for all we know, it might join an SRW group inside the unknown).
trace!("reborrow: forgetting stack entirely due to SharedReadWrite reborrow from wildcard or unknown");
trace!(
"reborrow: forgetting stack entirely due to SharedReadWrite reborrow from wildcard or unknown"
);
self.set_unknown_bottom(global.next_ptr_tag);
return Ok(());
};

View file

@ -196,19 +196,19 @@ impl<'tcx> Stack {
let ProvenanceExtra::Concrete(tag) = tag else {
// Handle the wildcard case.
// Go search the stack for an exposed tag.
if let Some(idx) =
self.borrows
.iter()
.enumerate() // we also need to know *where* in the stack
.rev() // search top-to-bottom
.find_map(|(idx, item)| {
// If the item fits and *might* be this wildcard, use it.
if item.perm().grants(access) && exposed_tags.contains(&item.tag()) {
Some(idx)
} else {
None
}
})
if let Some(idx) = self
.borrows
.iter()
.enumerate() // we also need to know *where* in the stack
.rev() // search top-to-bottom
.find_map(|(idx, item)| {
// If the item fits and *might* be this wildcard, use it.
if item.perm().grants(access) && exposed_tags.contains(&item.tag()) {
Some(idx)
} else {
None
}
})
{
return Ok(Some(idx));
}

View file

@ -570,9 +570,13 @@ impl DisplayRepr {
extraction_aux(tree, tree.root, show_unnamed, &mut v);
let Some(root) = v.pop() else {
if show_unnamed {
unreachable!("This allocation contains no tags, not even a root. This should not happen.");
unreachable!(
"This allocation contains no tags, not even a root. This should not happen."
);
}
eprintln!("This allocation does not contain named tags. Use `miri_print_borrow_state(_, true)` to also print unnamed tags.");
eprintln!(
"This allocation does not contain named tags. Use `miri_print_borrow_state(_, true)` to also print unnamed tags."
);
return None;
};
assert!(v.is_empty());

View file

@ -256,7 +256,9 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
ptr_size.bytes()
);
let Some(new_perm) = new_perm else { return Ok(Some((alloc_id, orig_tag))); };
let Some(new_perm) = new_perm else {
return Ok(Some((alloc_id, orig_tag)));
};
if let Some(protect) = new_perm.protector {
// We register the protection in two different places.

View file

@ -483,7 +483,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
// `index` is an array, not a SIMD type
let ty::Array(_, index_len) = index.layout.ty.kind() else {
span_bug!(this.cur_span(), "simd_shuffle index argument has non-array type {}", index.layout.ty)
span_bug!(
this.cur_span(),
"simd_shuffle index argument has non-array type {}",
index.layout.ty
)
};
let index_len = index_len.eval_target_usize(*this.tcx, this.param_env());
@ -622,9 +626,7 @@ fn fmax_op<'tcx>(
right: &ImmTy<'tcx, Provenance>,
) -> InterpResult<'tcx, Scalar<Provenance>> {
assert_eq!(left.layout.ty, right.layout.ty);
let ty::Float(float_ty) = left.layout.ty.kind() else {
bug!("fmax operand is not a float")
};
let ty::Float(float_ty) = left.layout.ty.kind() else { bug!("fmax operand is not a float") };
let left = left.to_scalar();
let right = right.to_scalar();
Ok(match float_ty {
@ -638,9 +640,7 @@ fn fmin_op<'tcx>(
right: &ImmTy<'tcx, Provenance>,
) -> InterpResult<'tcx, Scalar<Provenance>> {
assert_eq!(left.layout.ty, right.layout.ty);
let ty::Float(float_ty) = left.layout.ty.kind() else {
bug!("fmin operand is not a float")
};
let ty::Float(float_ty) = left.layout.ty.kind() else { bug!("fmin operand is not a float") };
let left = left.to_scalar();
let right = right.to_scalar();
Ok(match float_ty {