about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src/check_pointers.rs
diff options
context:
space:
mode:
authorBastian Kersting <bkersting@google.com>2024-12-17 13:00:22 +0000
committerBastian Kersting <bkersting@google.com>2025-01-31 11:13:34 +0000
commitb151b513ba2b65c7506ec1a80f2712bbd09154d1 (patch)
treefc1505e76399304e8da3aca3808ad1b494dfe4e8 /compiler/rustc_mir_transform/src/check_pointers.rs
parent851322b74db9ac91a1b9d206c5f80fc51a97f7c1 (diff)
downloadrust-b151b513ba2b65c7506ec1a80f2712bbd09154d1.tar.gz
rust-b151b513ba2b65c7506ec1a80f2712bbd09154d1.zip
Insert null checks for pointer dereferences when debug assertions are enabled
Similar to how the alignment is already checked, this adds a check
for null pointer dereferences in debug mode. It is implemented similarly
to the alignment check as a MirPass.

This is related to a 2025H1 project goal for better UB checks in debug
mode: https://github.com/rust-lang/rust-project-goals/pull/177.
Diffstat (limited to 'compiler/rustc_mir_transform/src/check_pointers.rs')
-rw-r--r--compiler/rustc_mir_transform/src/check_pointers.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/compiler/rustc_mir_transform/src/check_pointers.rs b/compiler/rustc_mir_transform/src/check_pointers.rs
index 95d3ce05000..72460542f87 100644
--- a/compiler/rustc_mir_transform/src/check_pointers.rs
+++ b/compiler/rustc_mir_transform/src/check_pointers.rs
@@ -17,6 +17,7 @@ pub(crate) struct PointerCheck<'tcx> {
 /// [NonMutatingUseContext::SharedBorrow].
 #[derive(Copy, Clone)]
 pub(crate) enum BorrowCheckMode {
+    IncludeBorrows,
     ExcludeBorrows,
 }
 
@@ -168,7 +169,7 @@ impl<'a, 'tcx> PointerFinder<'a, 'tcx> {
             ) => true,
             PlaceContext::MutatingUse(MutatingUseContext::Borrow)
             | PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) => {
-                !matches!(self.borrow_check_mode, BorrowCheckMode::ExcludeBorrows)
+                matches!(self.borrow_check_mode, BorrowCheckMode::IncludeBorrows)
             }
             _ => false,
         }