about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/tools/miri/tests/pass/tree_borrows/protected_uninit.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/tools/miri/tests/pass/tree_borrows/protected_uninit.rs b/src/tools/miri/tests/pass/tree_borrows/protected_uninit.rs
new file mode 100644
index 00000000000..120b2ac46d1
--- /dev/null
+++ b/src/tools/miri/tests/pass/tree_borrows/protected_uninit.rs
@@ -0,0 +1,16 @@
+//@compile-flags: -Zmiri-tree-borrows
+
+// Protectors should not trigger on uninitialized locations,
+// otherwise we can write safe code that triggers UB.
+// To test this we do a write access that disables a protected
+// location, but the location is actually outside of the protected range.
+
+// Both x and y are protected here
+fn write_second(_x: &mut u8, y: &mut u8) {
+    *y = 1;
+}
+
+fn main() {
+    let mut data = (0u8, 1u8);
+    write_second(&mut data.0, &mut data.1);
+}