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