summaryrefslogtreecommitdiffstats
path: root/src/test/ui/sanitize
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/sanitize')
-rw-r--r--src/test/ui/sanitize/memory-eager.rs38
-rw-r--r--src/test/ui/sanitize/memory.rs14
2 files changed, 47 insertions, 5 deletions
diff --git a/src/test/ui/sanitize/memory-eager.rs b/src/test/ui/sanitize/memory-eager.rs
new file mode 100644
index 000000000..cc0593ec0
--- /dev/null
+++ b/src/test/ui/sanitize/memory-eager.rs
@@ -0,0 +1,38 @@
+// needs-sanitizer-support
+// needs-sanitizer-memory
+// min-llvm-version: 14.0.0
+//
+// revisions: unoptimized optimized
+//
+// [optimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
+// [unoptimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins
+//
+// run-fail
+// error-pattern: MemorySanitizer: use-of-uninitialized-value
+// error-pattern: Uninitialized value was created by an allocation
+// error-pattern: in the stack frame
+//
+// 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)]
+#![feature(bench_black_box)]
+
+use std::hint::black_box;
+use std::mem::MaybeUninit;
+
+#[inline(never)]
+#[no_mangle]
+#[allow(invalid_value)]
+fn random() -> char {
+ let r = unsafe { MaybeUninit::uninit().assume_init() };
+ // Avoid optimizing everything out.
+ black_box(r)
+}
+
+#[start]
+fn main(_: isize, _: *const *const u8) -> isize {
+ random();
+ 0
+}
diff --git a/src/test/ui/sanitize/memory.rs b/src/test/ui/sanitize/memory.rs
index b53f19a5b..14d4de65d 100644
--- a/src/test/ui/sanitize/memory.rs
+++ b/src/test/ui/sanitize/memory.rs
@@ -1,12 +1,15 @@
// needs-sanitizer-support
// needs-sanitizer-memory
//
-// compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
+// revisions: unoptimized optimized
+//
+// [optimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
+// [unoptimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins
//
// run-fail
// error-pattern: MemorySanitizer: use-of-uninitialized-value
// error-pattern: Uninitialized value was created by an allocation
-// error-pattern: in the stack frame of function 'main'
+// error-pattern: in the stack frame
//
// This test case intentionally limits the usage of the std,
// since it will be linked with an uninstrumented version of it.
@@ -14,6 +17,7 @@
#![feature(core_intrinsics)]
#![feature(start)]
#![feature(bench_black_box)]
+#![allow(invalid_value)]
use std::hint::black_box;
use std::mem::MaybeUninit;
@@ -21,9 +25,9 @@ use std::mem::MaybeUninit;
#[inline(never)]
#[no_mangle]
fn random() -> [isize; 32] {
- let r = unsafe { MaybeUninit::uninit().assume_init() };
+ let r = MaybeUninit::uninit();
// Avoid optimizing everything out.
- black_box(r)
+ unsafe { std::intrinsics::volatile_load(r.as_ptr()) }
}
#[inline(never)]
@@ -38,6 +42,6 @@ fn xor(a: &[isize]) -> isize {
#[start]
fn main(_: isize, _: *const *const u8) -> isize {
- let r = random();
+ let r = black_box(random as fn() -> [isize; 32])();
xor(&r)
}