forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect (non-raw) borrows of null ZST pointers in CheckNull
- Loading branch information
1 parent
73bf794
commit b4641b2
Showing
6 changed files
with
76 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//@ run-fail | ||
//@ compile-flags: -C debug-assertions | ||
//@ error-pattern: null pointer dereference occured | ||
|
||
fn main() { | ||
let ptr: *const () = std::ptr::null(); | ||
let _ptr: &() = unsafe { &*ptr }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ fn main() { | |
let ptr: *const u16 = std::ptr::null(); | ||
unsafe { | ||
let _ = *ptr; | ||
let _ = &raw const *ptr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Make sure that we don't insert a check for places that do not read. | ||
//@ run-pass | ||
//@ compile-flags: -C debug-assertions | ||
|
||
fn main() { | ||
let ptr: *const () = std::ptr::null(); | ||
unsafe { | ||
let _ = *ptr; | ||
let _ = &raw const *ptr; | ||
} | ||
} |