diff options
| author | bors <bors@rust-lang.org> | 2025-01-31 15:56:53 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-01-31 15:56:53 +0000 |
| commit | b8172d762b1f393f4a4458182402c21e709fb459 (patch) | |
| tree | a2d4c4af863104e5eb67421df08ea95f4f96f723 /compiler/rustc_codegen_llvm/src/errors.rs | |
| parent | a7b16ac380614878c590dd690f9c20642f2a6118 (diff) | |
| parent | 77f3081f84f60b4ce4081dfc517b3d1fe061fef6 (diff) | |
| download | rust-b8172d762b1f393f4a4458182402c21e709fb459.tar.gz rust-b8172d762b1f393f4a4458182402c21e709fb459.zip | |
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: https://github.com/rust-lang/rust-project-goals/pull/177.
r? `@saethlin`
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/errors.rs')
0 files changed, 0 insertions, 0 deletions
