
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.
16 lines
296 B
Rust
16 lines
296 B
Rust
//@ compile-flags: -C debug-assertions
|
|
|
|
struct Null {
|
|
a: u32,
|
|
}
|
|
|
|
fn main() {
|
|
// CHECK-LABEL: fn main(
|
|
// CHECK-NOT: {{assert.*}}
|
|
let val: u32 = 42;
|
|
let val_ref: &u32 = &val;
|
|
let _access1: &u32 = &*val_ref;
|
|
|
|
let val = Null { a: 42 };
|
|
let _access2: &u32 = &val.a;
|
|
}
|