
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.
12 lines
265 B
Rust
12 lines
265 B
Rust
//@ run-fail
|
|
//@ compile-flags: -C debug-assertions
|
|
//@ error-pattern: null pointer dereference occured
|
|
|
|
fn main() {
|
|
let ptr = std::ptr::null();
|
|
let mut dest = 0u32;
|
|
let dest_ptr = &mut dest as *mut u32;
|
|
unsafe {
|
|
*dest_ptr = *(ptr);
|
|
}
|
|
}
|