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.
This commit is contained in:
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user