Skip to content

Commit dd6efe1

Browse files
committed
Auto merge of #134424 - 1c3t3a:null-checks, r=saethlin
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 inserts checks in the same places as the `CheckAlignment` pass and additionally also inserts checks for `Borrows`, so code like ```rust let ptr: *const u32 = std::ptr::null(); let val: &u32 = unsafe { &*ptr }; ``` will have a check inserted on dereference. This is done because null references are UB. The alignment check doesn't cover these places, because in `&(*ptr).field`, the exact requirement is that the final reference must be aligned. This is something to consider further enhancements of the alignment check. For now this is implemented as a separate `MirPass`, to make it easy to disable this check if necessary. This is related to a 2025H1 project goal for better UB checks in debug mode: rust-lang/rust-project-goals#177. r? `@saethlin`
2 parents 1a8cc75 + 5c034a5 commit dd6efe1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub const MIRI_DEFAULT_ARGS: &[&str] = &[
168168
"-Zmir-emit-retag",
169169
"-Zmir-keep-place-mention",
170170
"-Zmir-opt-level=0",
171-
"-Zmir-enable-passes=-CheckAlignment",
171+
"-Zmir-enable-passes=-CheckAlignment,-CheckNull",
172172
// Deduplicating diagnostics means we miss events when tracking what happens during an
173173
// execution. Let's not do that.
174174
"-Zdeduplicate-diagnostics=no",

0 commit comments

Comments
 (0)