-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect use-after-scope bugs with AddressSanitizer
Enable use-after-scope checks by default when using AddressSanitizer. They allow to detect incorrect use of stack objects after their scope have already ended. The detection is based on LLVM lifetime intrinsics. To facilitate the use of this functionality, the lifetime intrinsics are now emitted regardless of optimization level if enabled sanitizer makes use of them.
- Loading branch information
Showing
3 changed files
with
31 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// needs-sanitizer-support | ||
// only-x86_64 | ||
// | ||
// compile-flags: -Zsanitizer=address | ||
// run-fail | ||
// error-pattern: ERROR: AddressSanitizer: stack-use-after-scope | ||
|
||
static mut P: *mut usize = std::ptr::null_mut(); | ||
|
||
fn main() { | ||
unsafe { | ||
{ | ||
let mut x = 0; | ||
P = &mut x; | ||
} | ||
std::ptr::write_volatile(P, 123); | ||
} | ||
} |