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.
Rollup merge of rust-lang#68291 - tmiasko:sanitizer-tests, r=nikomats…
…akis Update sanitizer tests * Move tests from src/test/run-make-fulldeps to src/test/ui. * Fix memory sanitizer test to detect the intended issue rather than an unrelated one caused by the use of an uninstrumented std.
- Loading branch information
Showing
13 changed files
with
84 additions
and
75 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
// needs-sanitizer-support | ||
// only-x86_64 | ||
// | ||
// compile-flags: -Z sanitizer=address -O | ||
// | ||
// run-fail | ||
// error-pattern: AddressSanitizer: stack-buffer-overflow | ||
// error-pattern: 'xs' <== Memory access at offset | ||
|
||
#![feature(test)] | ||
|
||
use std::hint::black_box; | ||
use std::mem; | ||
|
||
fn main() { | ||
let xs = [0, 1, 2, 3]; | ||
// Avoid optimizing everything out. | ||
let xs = black_box(xs.as_ptr()); | ||
let code = unsafe { *xs.offset(4) }; | ||
std::process::exit(code); | ||
} |
8 changes: 8 additions & 0 deletions
8
.../run-make-fulldeps/sanitizer-leak/leak.rs → src/test/ui/sanitizer-leak.rs
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,44 @@ | ||
// needs-sanitizer-support | ||
// only-linux | ||
// only-x86_64 | ||
// | ||
// compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O | ||
// | ||
// run-fail | ||
// error-pattern: MemorySanitizer: use-of-uninitialized-value | ||
// error-pattern: Uninitialized value was created by an allocation | ||
// error-pattern: in the stack frame of function 'random' | ||
// | ||
// This test case intentionally limits the usage of the std, | ||
// since it will be linked with an uninstrumented version of it. | ||
|
||
#![feature(core_intrinsics)] | ||
#![feature(start)] | ||
#![feature(test)] | ||
|
||
use std::hint::black_box; | ||
use std::mem::MaybeUninit; | ||
|
||
#[inline(never)] | ||
#[no_mangle] | ||
fn random() -> [isize; 32] { | ||
let r = unsafe { MaybeUninit::uninit().assume_init() }; | ||
// Avoid optimizing everything out. | ||
black_box(r) | ||
} | ||
|
||
#[inline(never)] | ||
#[no_mangle] | ||
fn xor(a: &[isize]) -> isize { | ||
let mut s = 0; | ||
for i in 0..a.len() { | ||
s = s ^ a[i]; | ||
} | ||
s | ||
} | ||
|
||
#[start] | ||
fn main(_: isize, _: *const *const u8) -> isize { | ||
let r = random(); | ||
xor(&r) | ||
} |
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,7 @@ | ||
// ignore-tidy-linelength | ||
// compile-flags: -Z sanitizer=leak --target i686-unknown-linux-gnu | ||
// error-pattern: error: LeakSanitizer only works with the `x86_64-unknown-linux-gnu` or `x86_64-apple-darwin` target | ||
|
||
#![feature(no_core)] | ||
#![no_core] | ||
#![no_main] |
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,4 @@ | ||
error: LeakSanitizer only works with the `x86_64-unknown-linux-gnu` or `x86_64-apple-darwin` target | ||
|
||
error: aborting due to previous error | ||
|