@@ -12,17 +12,22 @@ pub(crate) struct PointerCheck<'tcx> {
12
12
pub ( crate ) assert_kind : Box < AssertKind < Operand < ' tcx > > > ,
13
13
}
14
14
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.
16
16
///
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).
20
23
/// This utility takes care of the right order of blocks, the only thing a
21
24
/// caller must do in `on_finding` is:
22
25
/// - Append [Statement]s to `stmts`.
23
26
/// - Append [LocalDecl]s to `local_decls`.
24
27
/// - 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.
26
31
/// This utility will insert a terminator block that asserts on the condition
27
32
/// and panics on failure.
28
33
pub ( crate ) fn check_pointers < ' a , ' tcx , F > (
@@ -151,17 +156,17 @@ impl<'a, 'tcx> Visitor<'tcx> for PointerFinder<'a, 'tcx> {
151
156
let pointer = Place :: from ( place. local ) ;
152
157
let pointer_ty = self . local_decls [ place. local ] . ty ;
153
158
154
- // We only want to check places based on unsafe pointers
159
+ // We only want to check places based on raw pointers
155
160
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) ;
157
162
return ;
158
163
}
159
164
160
165
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" ) ;
162
167
// Ideally we'd support this in the future, but for now we are limited to sized types.
163
168
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) ;
165
170
return ;
166
171
}
167
172
@@ -171,7 +176,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PointerFinder<'a, 'tcx> {
171
176
_ => pointee_ty,
172
177
} ;
173
178
if self . excluded_pointees . contains ( & element_ty) {
174
- debug ! ( "Skipping pointer for type: {:?}" , pointee_ty) ;
179
+ trace ! ( "Skipping pointer for type: {:?}" , pointee_ty) ;
175
180
return ;
176
181
}
177
182
0 commit comments