diff options
| author | The Miri Cronjob Bot <miri@cron.bot> | 2024-03-14 05:01:33 +0000 |
|---|---|---|
| committer | The Miri Cronjob Bot <miri@cron.bot> | 2024-03-14 05:01:33 +0000 |
| commit | 06ca3abc5ab06894fd2e15f78140eacccca3a5e9 (patch) | |
| tree | ca240256a0323f4bbf16f86e7de5c1c78e47c98a /src/tools/miri/tests | |
| parent | f5bb34f4605bc83c02c2c0a7a128d706d6031f11 (diff) | |
| parent | ac1b8575c017b6cc99cf389ceffe853d7b53a694 (diff) | |
| download | rust-06ca3abc5ab06894fd2e15f78140eacccca3a5e9.tar.gz rust-06ca3abc5ab06894fd2e15f78140eacccca3a5e9.zip | |
Merge from rustc
Diffstat (limited to 'src/tools/miri/tests')
| -rw-r--r-- | src/tools/miri/tests/pass/address-reuse.rs | 16 | ||||
| -rw-r--r-- | src/tools/miri/tests/pass/intptrcast.rs | 4 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/tools/miri/tests/pass/address-reuse.rs b/src/tools/miri/tests/pass/address-reuse.rs new file mode 100644 index 00000000000..9b5c8c38b8f --- /dev/null +++ b/src/tools/miri/tests/pass/address-reuse.rs @@ -0,0 +1,16 @@ +//! Check that we do sometimes reuse addresses. +use std::collections::HashSet; + +fn main() { + let count = 100; + let mut addrs = HashSet::<usize>::new(); + for _ in 0..count { + // We make a `Box` with a layout that's hopefully not used by tons of things inside the + // allocator itself, so that we are more likely to get reuse. (With `i32` or `usize`, on + // Windows the reuse chances are very low.) + let b = Box::new([42usize; 4]); + addrs.insert(&*b as *const [usize; 4] as usize); + } + // dbg!(addrs.len()); + assert!(addrs.len() > 1 && addrs.len() < count); +} diff --git a/src/tools/miri/tests/pass/intptrcast.rs b/src/tools/miri/tests/pass/intptrcast.rs index 42b6f433420..370b09f512c 100644 --- a/src/tools/miri/tests/pass/intptrcast.rs +++ b/src/tools/miri/tests/pass/intptrcast.rs @@ -67,8 +67,8 @@ fn ptr_eq_dangling() { drop(b); let b = Box::new(0); let y = &*b as *const i32; // different allocation - // They *could* be equal if memory was reused, but probably are not. - assert!(x != y); + // They *could* be equal if memory is reused... + assert!(x != y || x == y); } fn ptr_eq_out_of_bounds() { |
