Update match branches
This updates all places where match branches check on StatementKind or UseContext. This doesn't properly implement them, but adds TODOs where they are, and also adds some best guesses to what they should be in some cases.
This commit is contained in:
parent
72c734d001
commit
89f45ed9f3
19 changed files with 1346 additions and 24 deletions
|
@ -293,8 +293,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
|
||||||
| MutatingUseContext::AsmOutput
|
| MutatingUseContext::AsmOutput
|
||||||
| MutatingUseContext::Borrow
|
| MutatingUseContext::Borrow
|
||||||
| MutatingUseContext::AddressOf
|
| MutatingUseContext::AddressOf
|
||||||
| MutatingUseContext::Projection
|
| MutatingUseContext::Projection,
|
||||||
| MutatingUseContext::CopyNonOverlapping,
|
|
||||||
)
|
)
|
||||||
| PlaceContext::NonMutatingUse(
|
| PlaceContext::NonMutatingUse(
|
||||||
NonMutatingUseContext::Inspect
|
NonMutatingUseContext::Inspect
|
||||||
|
@ -302,8 +301,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
|
||||||
| NonMutatingUseContext::UniqueBorrow
|
| NonMutatingUseContext::UniqueBorrow
|
||||||
| NonMutatingUseContext::ShallowBorrow
|
| NonMutatingUseContext::ShallowBorrow
|
||||||
| NonMutatingUseContext::AddressOf
|
| NonMutatingUseContext::AddressOf
|
||||||
| NonMutatingUseContext::Projection
|
| NonMutatingUseContext::Projection,
|
||||||
| NonMutatingUseContext::CopyNonOverlapping,
|
|
||||||
) => {
|
) => {
|
||||||
self.not_ssa(local);
|
self.not_ssa(local);
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,18 +120,22 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
ref dst,
|
ref dst,
|
||||||
ref size,
|
ref size,
|
||||||
}) => {
|
}) => {
|
||||||
let dst_val = self.codegen_place(&mut bx, dst.as_ref());
|
let dst_val = self.codegen_operand(&mut bx, dst);
|
||||||
let src_val = self.codegen_place(&mut bx, src.as_ref());
|
let src_val = self.codegen_operand(&mut bx, src);
|
||||||
let size_val = self.codegen_operand(&mut bx, size);
|
let size_val = self.codegen_operand(&mut bx, size);
|
||||||
let size = size_val.immediate_or_packed_pair(&mut bx);
|
let size = size_val.immediate_or_packed_pair(&mut bx);
|
||||||
|
let dst = dst_val.immediate_or_packed_pair(&mut bx);
|
||||||
|
let src = src_val.immediate_or_packed_pair(&mut bx);
|
||||||
|
use crate::MemFlags;
|
||||||
|
let flags =
|
||||||
|
(!MemFlags::UNALIGNED) & (!MemFlags::VOLATILE) & (!MemFlags::NONTEMPORAL);
|
||||||
bx.memcpy(
|
bx.memcpy(
|
||||||
dst_val.llval,
|
dst,
|
||||||
dst_val.align,
|
dst_val.layout.layout.align.pref,
|
||||||
src_val.llval,
|
src,
|
||||||
src_val.align,
|
src_val.layout.layout.align.pref,
|
||||||
size,
|
size,
|
||||||
// TODO probably want to have this change based on alignment above?
|
flags,
|
||||||
crate::MemFlags::empty(),
|
|
||||||
);
|
);
|
||||||
bx
|
bx
|
||||||
}
|
}
|
||||||
|
|
|
@ -1668,7 +1668,7 @@ impl Debug for Statement<'_> {
|
||||||
ref src,
|
ref src,
|
||||||
ref dst,
|
ref dst,
|
||||||
ref size,
|
ref size,
|
||||||
}) => write!(fmt, "copy_nonoverlapping(src={:?}, dst={:?},bytes={:?})", src, dst, size),
|
}) => write!(fmt, "copy_nonoverlapping(src={:?}, dst={:?}, size={:?})", src, dst, size),
|
||||||
Nop => write!(fmt, "nop"),
|
Nop => write!(fmt, "nop"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1682,8 +1682,8 @@ pub struct Coverage {
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
|
#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
|
||||||
pub struct CopyNonOverlapping<'tcx> {
|
pub struct CopyNonOverlapping<'tcx> {
|
||||||
pub src: Place<'tcx>,
|
pub src: Operand<'tcx>,
|
||||||
pub dst: Place<'tcx>,
|
pub dst: Operand<'tcx>,
|
||||||
pub size: Operand<'tcx>,
|
pub size: Operand<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -441,14 +441,12 @@ macro_rules! make_mir_visitor {
|
||||||
ref $($mutability)? dst,
|
ref $($mutability)? dst,
|
||||||
ref $($mutability)? size,
|
ref $($mutability)? size,
|
||||||
}) => {
|
}) => {
|
||||||
self.visit_place(
|
self.visit_operand(
|
||||||
src,
|
src,
|
||||||
PlaceContext::NonMutatingUse(NonMutatingUseContext::CopyNonOverlapping),
|
|
||||||
location
|
location
|
||||||
);
|
);
|
||||||
self.visit_place(
|
self.visit_operand(
|
||||||
dst,
|
dst,
|
||||||
PlaceContext::MutatingUse(MutatingUseContext::CopyNonOverlapping),
|
|
||||||
location
|
location
|
||||||
);
|
);
|
||||||
self.visit_operand(size, location)
|
self.visit_operand(size, location)
|
||||||
|
@ -1168,8 +1166,6 @@ pub enum NonMutatingUseContext {
|
||||||
/// f(&x.y);
|
/// f(&x.y);
|
||||||
///
|
///
|
||||||
Projection,
|
Projection,
|
||||||
/// Source from copy_nonoverlapping.
|
|
||||||
CopyNonOverlapping,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
|
@ -1199,8 +1195,6 @@ pub enum MutatingUseContext {
|
||||||
Projection,
|
Projection,
|
||||||
/// Retagging, a "Stacked Borrows" shadow state operation
|
/// Retagging, a "Stacked Borrows" shadow state operation
|
||||||
Retag,
|
Retag,
|
||||||
/// Memory written to in copy_nonoverlapping.
|
|
||||||
CopyNonOverlapping,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
|
|
|
@ -92,6 +92,21 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
|
||||||
self.consume_operand(location, input);
|
self.consume_operand(location, input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping {
|
||||||
|
ref src,
|
||||||
|
ref dst,
|
||||||
|
ref size,
|
||||||
|
}) => {
|
||||||
|
self.consume_operand(location, src);
|
||||||
|
self.consume_operand(location, dst);
|
||||||
|
self.consume_operand(location, size);
|
||||||
|
match dst {
|
||||||
|
Operand::Move(ref place) | Operand::Copy(ref place) => {
|
||||||
|
self.mutate_place(location, *place, Deep, JustWrite);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
StatementKind::Nop
|
StatementKind::Nop
|
||||||
| StatementKind::Coverage(..)
|
| StatementKind::Coverage(..)
|
||||||
| StatementKind::AscribeUserType(..)
|
| StatementKind::AscribeUserType(..)
|
||||||
|
|
|
@ -626,6 +626,8 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
|
||||||
self.consume_operand(location, (input, span), flow_state);
|
self.consume_operand(location, (input, span), flow_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StatementKind::CopyNonOverlapping(..) => todo!(),
|
||||||
StatementKind::Nop
|
StatementKind::Nop
|
||||||
| StatementKind::Coverage(..)
|
| StatementKind::Coverage(..)
|
||||||
| StatementKind::AscribeUserType(..)
|
| StatementKind::AscribeUserType(..)
|
||||||
|
|
|
@ -1520,6 +1520,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
StatementKind::CopyNonOverlapping(..) => todo!(),
|
||||||
StatementKind::FakeRead(..)
|
StatementKind::FakeRead(..)
|
||||||
| StatementKind::StorageLive(..)
|
| StatementKind::StorageLive(..)
|
||||||
| StatementKind::StorageDead(..)
|
| StatementKind::StorageDead(..)
|
||||||
|
|
|
@ -306,6 +306,8 @@ impl<'tcx> dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
|
||||||
| mir::StatementKind::AscribeUserType(..)
|
| mir::StatementKind::AscribeUserType(..)
|
||||||
| mir::StatementKind::Coverage(..)
|
| mir::StatementKind::Coverage(..)
|
||||||
| mir::StatementKind::Nop => {}
|
| mir::StatementKind::Nop => {}
|
||||||
|
|
||||||
|
mir::StatementKind::CopyNonOverlapping(..) => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -150,6 +150,8 @@ impl<'mir, 'tcx> dataflow::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'mir,
|
||||||
| StatementKind::Nop
|
| StatementKind::Nop
|
||||||
| StatementKind::Retag(..)
|
| StatementKind::Retag(..)
|
||||||
| StatementKind::StorageLive(..) => {}
|
| StatementKind::StorageLive(..) => {}
|
||||||
|
|
||||||
|
StatementKind::CopyNonOverlapping(..) => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -319,6 +319,8 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
|
||||||
| StatementKind::AscribeUserType(..)
|
| StatementKind::AscribeUserType(..)
|
||||||
| StatementKind::Coverage(..)
|
| StatementKind::Coverage(..)
|
||||||
| StatementKind::Nop => {}
|
| StatementKind::Nop => {}
|
||||||
|
|
||||||
|
StatementKind::CopyNonOverlapping(..) => todo!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,6 +113,23 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
M::retag(self, *kind, &dest)?;
|
M::retag(self, *kind, &dest)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Call CopyNonOverlapping
|
||||||
|
CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping { dst, src, size }) => {
|
||||||
|
let size = self.eval_operand(size, None)?;
|
||||||
|
|
||||||
|
let dst = {
|
||||||
|
let dst = self.eval_operand(dst, None)?;
|
||||||
|
dst.assert_mem_place(self)
|
||||||
|
};
|
||||||
|
let src = {
|
||||||
|
let src = self.eval_operand(src, None)?;
|
||||||
|
src.assert_mem_place(self)
|
||||||
|
};
|
||||||
|
// Not sure how to convert an MPlaceTy<'_, <M as Machine<'_, '_>>::PointerTag>
|
||||||
|
// to a pointer, or OpTy to a size
|
||||||
|
self.memory.copy(src, dst, size, /*nonoverlapping*/ true)?;
|
||||||
|
}
|
||||||
|
|
||||||
// Statements we do not track.
|
// Statements we do not track.
|
||||||
AscribeUserType(..) => {}
|
AscribeUserType(..) => {}
|
||||||
|
|
||||||
|
|
|
@ -808,6 +808,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
|
||||||
| StatementKind::Retag { .. }
|
| StatementKind::Retag { .. }
|
||||||
| StatementKind::AscribeUserType(..)
|
| StatementKind::AscribeUserType(..)
|
||||||
| StatementKind::Coverage(..)
|
| StatementKind::Coverage(..)
|
||||||
|
| StatementKind::CopyNonOverlapping(..)
|
||||||
| StatementKind::Nop => {}
|
| StatementKind::Nop => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
|
||||||
| StatementKind::Retag { .. }
|
| StatementKind::Retag { .. }
|
||||||
| StatementKind::AscribeUserType(..)
|
| StatementKind::AscribeUserType(..)
|
||||||
| StatementKind::Coverage(..)
|
| StatementKind::Coverage(..)
|
||||||
|
| StatementKind::CopyNonOverlapping(..)
|
||||||
| StatementKind::Nop => {
|
| StatementKind::Nop => {
|
||||||
// safe (at least as emitted during MIR construction)
|
// safe (at least as emitted during MIR construction)
|
||||||
}
|
}
|
||||||
|
|
|
@ -587,6 +587,7 @@ impl Conflicts<'a> {
|
||||||
| StatementKind::FakeRead(..)
|
| StatementKind::FakeRead(..)
|
||||||
| StatementKind::AscribeUserType(..)
|
| StatementKind::AscribeUserType(..)
|
||||||
| StatementKind::Coverage(..)
|
| StatementKind::Coverage(..)
|
||||||
|
| StatementKind::CopyNonOverlapping(..)
|
||||||
| StatementKind::Nop => {}
|
| StatementKind::Nop => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1454,6 +1454,7 @@ impl Visitor<'tcx> for EnsureGeneratorFieldAssignmentsNeverAlias<'_> {
|
||||||
| StatementKind::Retag(..)
|
| StatementKind::Retag(..)
|
||||||
| StatementKind::AscribeUserType(..)
|
| StatementKind::AscribeUserType(..)
|
||||||
| StatementKind::Coverage(..)
|
| StatementKind::Coverage(..)
|
||||||
|
| StatementKind::CopyNonOverlapping(..)
|
||||||
| StatementKind::Nop => {}
|
| StatementKind::Nop => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1272
compiler/rustc_mir/src/transform/instrument_coverage.rs
Normal file
1272
compiler/rustc_mir/src/transform/instrument_coverage.rs
Normal file
File diff suppressed because it is too large
Load diff
|
@ -39,6 +39,7 @@ impl RemoveNoopLandingPads {
|
||||||
| StatementKind::StorageDead(_)
|
| StatementKind::StorageDead(_)
|
||||||
| StatementKind::AscribeUserType(..)
|
| StatementKind::AscribeUserType(..)
|
||||||
| StatementKind::Coverage(..)
|
| StatementKind::Coverage(..)
|
||||||
|
| StatementKind::CopyNonOverlapping(..)
|
||||||
| StatementKind::Nop => {
|
| StatementKind::Nop => {
|
||||||
// These are all nops in a landing pad
|
// These are all nops in a landing pad
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,6 +245,7 @@ pub fn statement_kind_name(statement: &Statement<'_>) -> &'static str {
|
||||||
Retag(..) => "Retag",
|
Retag(..) => "Retag",
|
||||||
AscribeUserType(..) => "AscribeUserType",
|
AscribeUserType(..) => "AscribeUserType",
|
||||||
Coverage(..) => "Coverage",
|
Coverage(..) => "Coverage",
|
||||||
|
CopyNonOverlapping(..) => "CopyNonOverlapping",
|
||||||
Nop => "Nop",
|
Nop => "Nop",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,7 +210,7 @@ fn check_statement(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, statemen
|
||||||
StatementKind::Assign(box (place, rval)) => {
|
StatementKind::Assign(box (place, rval)) => {
|
||||||
check_place(tcx, *place, span, body)?;
|
check_place(tcx, *place, span, body)?;
|
||||||
check_rvalue(tcx, body, def_id, rval, span)
|
check_rvalue(tcx, body, def_id, rval, span)
|
||||||
},
|
}
|
||||||
|
|
||||||
StatementKind::FakeRead(_, place) |
|
StatementKind::FakeRead(_, place) |
|
||||||
// just an assignment
|
// just an assignment
|
||||||
|
@ -218,6 +218,13 @@ fn check_statement(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, statemen
|
||||||
|
|
||||||
StatementKind::LlvmInlineAsm { .. } => Err((span, "cannot use inline assembly in const fn".into())),
|
StatementKind::LlvmInlineAsm { .. } => Err((span, "cannot use inline assembly in const fn".into())),
|
||||||
|
|
||||||
|
StatementKind::CopyNonOverlapping(box rustc_middle::mir::CopyNonOverlapping{
|
||||||
|
dst, src, size,
|
||||||
|
}) => {
|
||||||
|
check_operand(tcx, dst, span, body)?;
|
||||||
|
check_operand(tcx, src, span, body)?;
|
||||||
|
check_operand(tcx, size, span, body)
|
||||||
|
},
|
||||||
// These are all NOPs
|
// These are all NOPs
|
||||||
StatementKind::StorageLive(_)
|
StatementKind::StorageLive(_)
|
||||||
| StatementKind::StorageDead(_)
|
| StatementKind::StorageDead(_)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue