Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sanitizer tests #68291

Merged
merged 1 commit into from
Jan 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions src/test/run-make-fulldeps/sanitizer-address/Makefile

This file was deleted.

4 changes: 0 additions & 4 deletions src/test/run-make-fulldeps/sanitizer-address/overflow.rs

This file was deleted.

5 changes: 0 additions & 5 deletions src/test/run-make-fulldeps/sanitizer-invalid-target/Makefile

This file was deleted.

3 changes: 0 additions & 3 deletions src/test/run-make-fulldeps/sanitizer-invalid-target/hello.rs

This file was deleted.

7 changes: 0 additions & 7 deletions src/test/run-make-fulldeps/sanitizer-leak/Makefile

This file was deleted.

11 changes: 0 additions & 11 deletions src/test/run-make-fulldeps/sanitizer-memory/Makefile

This file was deleted.

8 changes: 0 additions & 8 deletions src/test/run-make-fulldeps/sanitizer-memory/maybeuninit.rs

This file was deleted.

7 changes: 0 additions & 7 deletions src/test/run-make-fulldeps/sanitizer-memory/uninit.rs

This file was deleted.

21 changes: 21 additions & 0 deletions src/test/ui/sanitizer-address.rs
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);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// needs-sanitizer-support
// only-x86_64
//
// compile-flags: -Z sanitizer=leak -O
//
// run-fail
// error-pattern: LeakSanitizer: detected memory leaks

#![feature(test)]

use std::hint::black_box;
Expand Down
44 changes: 44 additions & 0 deletions src/test/ui/sanitizer-memory.rs
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)
}
7 changes: 7 additions & 0 deletions src/test/ui/sanitizer-unsupported-target.rs
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]
4 changes: 4 additions & 0 deletions src/test/ui/sanitizer-unsupported-target.stderr
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