
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.
14 lines
274 B
Rust
14 lines
274 B
Rust
// Make sure that we don't insert a check for `addr_of!`.
|
|
//@ run-pass
|
|
//@ compile-flags: -C debug-assertions
|
|
|
|
struct Field {
|
|
a: u32,
|
|
}
|
|
|
|
fn main() {
|
|
unsafe {
|
|
let ptr: *const Field = std::ptr::null();
|
|
let _ptr = core::ptr::addr_of!((*ptr).a);
|
|
}
|
|
}
|