pub(crate) fn check_pointers<'tcx, F>(
tcx: TyCtxt<'tcx>,
body: &mut Body<'tcx>,
excluded_pointees: &[Ty<'tcx>],
on_finding: F,
borrow_check_mode: BorrowCheckMode,
)where
F: Fn(TyCtxt<'tcx>, Place<'tcx>, Ty<'tcx>, PlaceContext, &mut IndexVec<Local, LocalDecl<'tcx>>, &mut Vec<Statement<'tcx>>, SourceInfo) -> PointerCheck<'tcx>,
Expand description
Utility for adding a check for read/write on every sized, raw pointer.
Visits every read/write access to a Sized, raw pointer and inserts a
new basic block directly before the pointer access. (Read/write accesses
are determined by the PlaceContext
of the MIR visitor.) Then calls
on_finding
to insert the actual logic for a pointer check (e.g. check for
alignment). A check can choose to be inserted for (mutable) borrows of
raw pointers via the borrow_check_mode
parameter.
This utility takes care of the right order of blocks, the only thing a
caller must do in on_finding
is:
- Append Statements to
stmts
. - Append LocalDecls to
local_decls
. - Return a PointerCheck that contains the condition and an AssertKind.
The AssertKind must be a panic with
#[rustc_nounwind]
. The condition should always return the booleanis_ok
, so evaluate to true in case of success and fail the check otherwise. This utility will insert a terminator block that asserts on the condition and panics on failure.