rust/src
bors aa589d3dc7 Auto merge of #2145 - saethlin:zero-size-creation, r=RalfJung
Save a created event for zero-size reborrows

Currently, we don't save a created event for zero-sized reborrows. Attempting to use something from a zero-sized reborrow is surprisingly common, for example on `minimal-lexical==0.2.1` we previously just emit this:
```
Undefined Behavior: attempting a write access using <187021> at alloc72933[0x0], but that tag does not exist in the borrow stack for this location
    --> /root/rust/library/core/src/ptr/mod.rs:1287:9
     |
1287 |         copy_nonoverlapping(&src as *const T, dst, 1);
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |         |
     |         attempting a write access using <187021> at alloc72933[0x0], but that tag does not exist in the borrow stack for this location
     |         this error occurs as part of an access at alloc72933[0x0..0x8]
     |
     = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
     = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

     = note: inside `std::ptr::write::<u64>` at /root/rust/library/core/src/ptr/mod.rs:1287:9
note: inside `minimal_lexical::stackvec::StackVec::push_unchecked` at /root/build/src/stackvec.rs:82:13
    --> /root/build/src/stackvec.rs:82:13
     |
82   |             ptr::write(self.as_mut_ptr().add(self.len()), value);
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

... backtrace continues...
```
Which leaves us with the question "where did we make this pointer?" because for every other diagnostic you get a "was created by" note, so I suspect people might be tempted to think there is a Miri bug here. I certainly was.

---
This code duplication is so awful, I'm going to take a look at cleaning it up later. The fact that `ptr_get_alloc_id` can fail in this situation makes things annoying.
2022-05-30 23:43:51 +00:00
..
bin enable number validity checking and ptr::invalid checking by default 2022-05-25 16:17:41 +02:00
helpers Replace as casts in llvm.x86.addcarry.64 implementation 2022-04-30 10:33:55 -07:00
shims Add support for _COARSE clocks, spruce up comments 2022-05-30 11:26:10 -04:00
stacked_borrows rustup 2022-05-29 14:06:35 +02:00
data_race.rs Fix backwards cmpxchg_weak_failure_rate check 2022-05-22 20:24:08 -07:00
diagnostics.rs Adjust Miri to also require return places everywhere 2022-05-24 17:16:36 +02:00
eval.rs enable number validity checking and ptr::invalid checking by default 2022-05-25 16:17:41 +02:00
helpers.rs rustup 2022-05-29 14:06:35 +02:00
intptrcast.rs enable number validity checking and ptr::invalid checking by default 2022-05-25 16:17:41 +02:00
lib.rs Initial work on permissive provenance 2022-05-23 09:07:31 +02:00
machine.rs enable number validity checking and ptr::invalid checking by default 2022-05-25 16:17:41 +02:00
mono_hash_map.rs adjust Miri to Pointer type overhaul 2021-07-16 10:10:12 +02:00
operator.rs rustup 2022-04-09 09:41:29 -04:00
range_map.rs Resolve clippy::needless_return 2022-04-29 15:53:48 -07:00
stacked_borrows.rs Save a created event for zero-size reborrows 2022-05-29 16:45:26 -04:00
sync.rs Inline _create() calls and add assertions 2022-05-12 21:06:17 +01:00
thread.rs Set the current span (somewhat) lazily 2022-04-30 10:25:52 -04:00
vector_clock.rs remove no longer needed imports 2022-04-09 11:32:49 -04:00