diff options
| author | Bastian Kersting <bkersting@google.com> | 2025-03-03 13:28:41 +0000 |
|---|---|---|
| committer | Bastian Kersting <bkersting@google.com> | 2025-04-25 12:16:40 +0000 |
| commit | a3e7c699bc430e29e3035d36e4b3f9682c86c56e (patch) | |
| tree | 2dd704fca4e490f802134c00fcdcae8022c5bc7a /compiler/rustc_mir_transform/src/check_null.rs | |
| parent | 862156d6f25ccb0d915d2a0c8ebab520d05e4f72 (diff) | |
| download | rust-a3e7c699bc430e29e3035d36e4b3f9682c86c56e.tar.gz rust-a3e7c699bc430e29e3035d36e4b3f9682c86c56e.zip | |
Extend the alignment check to borrows
The current alignment check does not include checks for creating misaligned references from raw pointers, which is now added in this patch. When inserting the check we need to be careful with references to field projections (e.g. `&(*ptr).a`), in which case the resulting reference must be aligned according to the field type and not the type of the pointer.
Diffstat (limited to 'compiler/rustc_mir_transform/src/check_null.rs')
| -rw-r--r-- | compiler/rustc_mir_transform/src/check_null.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/rustc_mir_transform/src/check_null.rs b/compiler/rustc_mir_transform/src/check_null.rs index 543e1845e65..ad74e335bd9 100644 --- a/compiler/rustc_mir_transform/src/check_null.rs +++ b/compiler/rustc_mir_transform/src/check_null.rs @@ -4,7 +4,7 @@ use rustc_middle::mir::*; use rustc_middle::ty::{Ty, TyCtxt}; use rustc_session::Session; -use crate::check_pointers::{BorrowCheckMode, PointerCheck, check_pointers}; +use crate::check_pointers::{BorrowedFieldProjectionMode, PointerCheck, check_pointers}; pub(super) struct CheckNull; @@ -14,7 +14,13 @@ impl<'tcx> crate::MirPass<'tcx> for CheckNull { } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - check_pointers(tcx, body, &[], insert_null_check, BorrowCheckMode::IncludeBorrows); + check_pointers( + tcx, + body, + &[], + insert_null_check, + BorrowedFieldProjectionMode::NoFollowProjections, + ); } fn is_required(&self) -> bool { |
