diff options
| author | bors <bors@rust-lang.org> | 2021-04-14 18:04:22 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-04-14 18:04:22 +0000 |
| commit | 7537b20626100e7e7fc8c4ad3079d38c05338121 (patch) | |
| tree | 6a89a9ed2076f0e1530b422024dc4651ccb6dfa7 /compiler/rustc_codegen_llvm/src | |
| parent | 07ef25984549bc33adbdc402e977655d8c9093a7 (diff) | |
| parent | 7f0f83a26fdec4caa2a8512f9fc611d504b7aad2 (diff) | |
| download | rust-7537b20626100e7e7fc8c4ad3079d38c05338121.tar.gz rust-7537b20626100e7e7fc8c4ad3079d38c05338121.zip | |
Auto merge of #83948 - ABouttefeux:lint-nullprt-deref, r=RalfJung
add lint deref_nullptr detecting when a null ptr is dereferenced
fixes #83856
changelog: add lint that detect code like
```rust
unsafe {
&*core::ptr::null::<i32>()
};
unsafe {
addr_of!(std::ptr::null::<i32>())
};
let x: i32 = unsafe {*core::ptr::null()};
let x: i32 = unsafe {*core::ptr::null_mut()};
unsafe {*(0 as *const i32)};
unsafe {*(core::ptr::null() as *const i32)};
```
```
warning: Dereferencing a null pointer causes undefined behavior
--> src\main.rs:5:26
|
5 | let x: i32 = unsafe {*core::ptr::null()};
| ^^^^^^^^^^^^^^^^^^
| |
| a null pointer is dereferenced
| this code causes undefined behavior when executed
|
= note: `#[warn(deref_nullptr)]` on by default
```
Limitation:
It does not detect code like
```rust
const ZERO: usize = 0;
unsafe {*(ZERO as *const i32)};
```
or code where `0` is not directly a literal
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
0 files changed, 0 insertions, 0 deletions
