@@ -12,17 +12,22 @@ pub(crate) struct PointerCheck<'tcx> {
1212 pub ( crate ) assert_kind : Box < AssertKind < Operand < ' tcx > > > ,
1313}
1414
15- /// Utility for adding a check for read/write on every sized, unsafe pointer.
15+ /// Utility for adding a check for read/write on every sized, raw pointer.
1616///
17- /// Visits every read/write access to a [Sized], unsafe pointer and inserts a
18- /// new basic block directly before the pointer access. Then calls `on_finding`
19- /// to insert the actual logic for a pointer check (e.g. check for alignment).
17+ /// Visits every read/write access to a [Sized], raw pointer and inserts a
18+ /// new basic block directly before the pointer access. (Read/write accesses
19+ /// are determined by the `PlaceContext` of the MIR visitor. In particular,
20+ /// uses of pointers in borrow expressions are *not* visited). Then calls
21+ /// `on_finding` to insert the actual logic for a pointer check (e.g. check for
22+ /// alignment).
2023/// This utility takes care of the right order of blocks, the only thing a
2124/// caller must do in `on_finding` is:
2225/// - Append [Statement]s to `stmts`.
2326/// - Append [LocalDecl]s to `local_decls`.
2427/// - Return a [PointerCheck] that contains the condition and an [AssertKind].
25- /// The AssertKind must be a panic with `#[rustc_nounwind]`.
28+ /// The AssertKind must be a panic with `#[rustc_nounwind]`. The condition
29+ /// should always return the boolean `is_ok`, so evaluate to true in case of
30+ /// success and fail the check otherwise.
2631/// This utility will insert a terminator block that asserts on the condition
2732/// and panics on failure.
2833pub ( crate ) fn check_pointers < ' a , ' tcx , F > (
@@ -151,17 +156,17 @@ impl<'a, 'tcx> Visitor<'tcx> for PointerFinder<'a, 'tcx> {
151156 let pointer = Place :: from ( place. local ) ;
152157 let pointer_ty = self . local_decls [ place. local ] . ty ;
153158
154- // We only want to check places based on unsafe pointers
159+ // We only want to check places based on raw pointers
155160 if !pointer_ty. is_unsafe_ptr ( ) {
156- trace ! ( "Indirect, but not based on an unsafe ptr, not checking {:?}" , place) ;
161+ trace ! ( "Indirect, but not based on an raw ptr, not checking {:?}" , place) ;
157162 return ;
158163 }
159164
160165 let pointee_ty =
161- pointer_ty. builtin_deref ( true ) . expect ( "no builtin_deref for an unsafe pointer" ) ;
166+ pointer_ty. builtin_deref ( true ) . expect ( "no builtin_deref for an raw pointer" ) ;
162167 // Ideally we'd support this in the future, but for now we are limited to sized types.
163168 if !pointee_ty. is_sized ( self . tcx , self . typing_env ) {
164- debug ! ( "Unsafe pointer, but pointee is not known to be sized: {:?}" , pointer_ty) ;
169+ trace ! ( "Raw pointer, but pointee is not known to be sized: {:?}" , pointer_ty) ;
165170 return ;
166171 }
167172
@@ -171,7 +176,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PointerFinder<'a, 'tcx> {
171176 _ => pointee_ty,
172177 } ;
173178 if self . excluded_pointees . contains ( & element_ty) {
174- debug ! ( "Skipping pointer for type: {:?}" , pointee_ty) ;
179+ trace ! ( "Skipping pointer for type: {:?}" , pointee_ty) ;
175180 return ;
176181 }
177182
0 commit comments