]> git.lizzy.rs Git - rust.git/blob - src/test/ui/sanitize/memory-eager.rs
Rollup merge of #102634 - andrewpollack:refactor-test-rustcflags, r=Mark-Simulacrum
[rust.git] / src / test / ui / sanitize / memory-eager.rs
1 // needs-sanitizer-support
2 // needs-sanitizer-memory
3 // min-llvm-version: 14.0.0
4 //
5 // revisions: unoptimized optimized
6 //
7 // [optimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
8 // [unoptimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins
9 //
10 // run-fail
11 // error-pattern: MemorySanitizer: use-of-uninitialized-value
12 // error-pattern: Uninitialized value was created by an allocation
13 // error-pattern: in the stack frame
14 //
15 // This test case intentionally limits the usage of the std,
16 // since it will be linked with an uninstrumented version of it.
17
18 #![feature(core_intrinsics)]
19 #![feature(start)]
20
21 use std::hint::black_box;
22 use std::mem::MaybeUninit;
23
24 #[inline(never)]
25 #[no_mangle]
26 #[allow(invalid_value)]
27 fn random() -> char {
28     let r = unsafe { MaybeUninit::uninit().assume_init() };
29     // Avoid optimizing everything out.
30     black_box(r)
31 }
32
33 #[start]
34 fn main(_: isize, _: *const *const u8) -> isize {
35     random();
36     0
37 }