]> git.lizzy.rs Git - rust.git/blob - src/test/ui/sanitize/memory-passing.rs
Rollup merge of #103439 - Nilstrieb:help-me-with-my-macro, r=estebank
[rust.git] / src / test / ui / sanitize / memory-passing.rs
1 // needs-sanitizer-support
2 // needs-sanitizer-memory
3 //
4 // revisions: unoptimized optimized
5 //
6 // [optimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
7 // [unoptimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins
8 //
9 // run-pass
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 #![allow(invalid_value)]
17
18 use std::hint::black_box;
19
20 fn calling_black_box_on_zst_ok() {
21     // It's OK to call black_box on a value of a zero-sized type, even if its
22     // underlying the memory location is uninitialized. For non-zero-sized types,
23     // this would be an MSAN error.
24     let zst = ();
25     black_box(zst);
26 }
27
28 #[start]
29 fn main(_: isize, _: *const *const u8) -> isize {
30     calling_black_box_on_zst_ok();
31     0
32 }