2020-01-16 00:00:00 +00:00
|
|
|
// needs-sanitizer-support
|
2020-06-05 00:00:00 +00:00
|
|
|
// needs-sanitizer-memory
|
2020-01-16 00:00:00 +00:00
|
|
|
//
|
2022-07-16 11:08:48 +00:00
|
|
|
// revisions: unoptimized optimized
|
|
|
|
//
|
|
|
|
// [optimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
|
|
|
|
// [unoptimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins
|
2020-01-16 00:00:00 +00:00
|
|
|
//
|
|
|
|
// run-fail
|
|
|
|
// error-pattern: MemorySanitizer: use-of-uninitialized-value
|
|
|
|
// error-pattern: Uninitialized value was created by an allocation
|
2022-08-12 08:57:18 +00:00
|
|
|
// error-pattern: in the stack frame
|
2020-01-16 00:00:00 +00:00
|
|
|
//
|
|
|
|
// 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)]
|
2022-08-29 20:28:35 +00:00
|
|
|
#![allow(invalid_value)]
|
2020-01-16 00:00:00 +00:00
|
|
|
|
|
|
|
use std::hint::black_box;
|
|
|
|
use std::mem::MaybeUninit;
|
|
|
|
|
|
|
|
#[inline(never)]
|
|
|
|
#[no_mangle]
|
|
|
|
fn random() -> [isize; 32] {
|
2022-08-14 09:37:03 +00:00
|
|
|
let r = MaybeUninit::uninit();
|
2020-01-16 00:00:00 +00:00
|
|
|
// Avoid optimizing everything out.
|
2022-08-14 09:37:03 +00:00
|
|
|
unsafe { std::intrinsics::volatile_load(r.as_ptr()) }
|
2020-01-16 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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 {
|
2022-08-14 09:37:03 +00:00
|
|
|
let r = black_box(random as fn() -> [isize; 32])();
|
2020-01-16 00:00:00 +00:00
|
|
|
xor(&r)
|
|
|
|
}
|