]> git.lizzy.rs Git - rust.git/blob - src/test/ui/sanitize/memory.rs
Auto merge of #98051 - davidtwco:split-dwarf-stabilization, r=wesleywiser
[rust.git] / src / test / ui / sanitize / memory.rs
1 // needs-sanitizer-support
2 // needs-sanitizer-memory
3 //
4 // compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
5 //
6 // run-fail
7 // error-pattern: MemorySanitizer: use-of-uninitialized-value
8 // error-pattern: Uninitialized value was created by an allocation
9 // error-pattern: in the stack frame
10 //
11 // This test case intentionally limits the usage of the std,
12 // since it will be linked with an uninstrumented version of it.
13
14 #![feature(core_intrinsics)]
15 #![feature(start)]
16 #![feature(bench_black_box)]
17
18 use std::hint::black_box;
19 use std::mem::MaybeUninit;
20
21 #[inline(never)]
22 #[no_mangle]
23 fn random() -> [isize; 32] {
24     let r = unsafe { MaybeUninit::uninit().assume_init() };
25     // Avoid optimizing everything out.
26     black_box(r)
27 }
28
29 #[inline(never)]
30 #[no_mangle]
31 fn xor(a: &[isize]) -> isize {
32     let mut s = 0;
33     for i in 0..a.len() {
34         s = s ^ a[i];
35     }
36     s
37 }
38
39 #[start]
40 fn main(_: isize, _: *const *const u8) -> isize {
41     let r = random();
42     xor(&r)
43 }