mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-28 03:24:11 +00:00
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.
9 lines
212 B
Rust
9 lines
212 B
Rust
//@ run-fail
|
|
//@ compile-flags: -C debug-assertions
|
|
//@ error-pattern: null pointer dereference occured
|
|
|
|
fn main() {
|
|
let ptr: *mut u32 = std::ptr::null_mut();
|
|
let _ptr: &mut u32 = unsafe { &mut *ptr };
|
|
}
|