about summary refs log tree commit diff
path: root/src/tools/miri
AgeCommit message (Collapse)AuthorLines
2024-06-03Make WHERE_CLAUSES_OBJECT_SAFETY a regular object safety violationMichael Goulet-34/+0
2024-06-03Reformat `mir!` macro invocations to use braces.Nicholas Nethercote-18/+24
The `mir!` macro has multiple parts: - An optional return type annotation. - A sequence of zero or more local declarations. - A mandatory starting anonymous basic block, which is brace-delimited. - A sequence of zero of more additional named basic blocks. Some `mir!` invocations use braces with a "block" style, like so: ``` mir! { let _unit: (); { let non_copy = S(42); let ptr = std::ptr::addr_of_mut!(non_copy); // Inside `callee`, the first argument and `*ptr` are basically // aliasing places! Call(_unit = callee(Move(*ptr), ptr), ReturnTo(after_call), UnwindContinue()) } after_call = { Return() } } ``` Some invocations use parens with a "block" style, like so: ``` mir!( let x: [i32; 2]; let one: i32; { x = [42, 43]; one = 1; x = [one, 2]; RET = Move(x); Return() } ) ``` And some invocations uses parens with a "tighter" style, like so: ``` mir!({ SetDiscriminant(*b, 0); Return() }) ``` This last style is generally used for cases where just the mandatory starting basic block is present. Its braces are placed next to the parens. This commit changes all `mir!` invocations to use braces with a "block" style. Why? - Consistency is good. - The contents of the invocation is a block of code, so it's odd to use parens. They are more normally used for function-like macros. - Most importantly, the next commit will enable rustfmt for `tests/mir-opt/`. rustfmt is more aggressive about formatting macros that use parens than macros that use braces. Without this commit's changes, rustfmt would break a couple of `mir!` macro invocations that use braces within `tests/mir-opt` by inserting an extraneous comma. E.g.: ``` mir!(type RET = (i32, bool);, { // extraneous comma after ';' RET.0 = 1; RET.1 = true; Return() }) ``` Switching those `mir!` invocations to use braces avoids that problem, resulting in this, which is nicer to read as well as being valid syntax: ``` mir! { type RET = (i32, bool); { RET.0 = 1; RET.1 = true; Return() } } ```
2024-05-31Auto merge of #124662 - zetanumbers:needs_async_drop, r=oli-obkbors-0/+5
Implement `needs_async_drop` in rustc and optimize async drop glue This PR expands on #121801 and implements `Ty::needs_async_drop` which works almost exactly the same as `Ty::needs_drop`, which is needed for #123948. Also made compiler's async drop code to look more like compiler's regular drop code, which enabled me to write an optimization where types which do not use `AsyncDrop` can simply forward async drop glue to `drop_in_place`. This made size of the async block from the [async_drop test](https://github.com/zetanumbers/rust/blob/67980dd6fb11917d23d01a19c2cf4cfc3978aac8/tests/ui/async-await/async-drop.rs) to decrease by 12%.
2024-05-30explain what the open questions are, and add a Miri test for thatRalf Jung-0/+12
2024-05-29Auto merge of #125360 - RalfJung:packed-field-reorder, r=fmeasebors-2/+2
don't inhibit random field reordering on repr(packed(1)) `inhibit_struct_field_reordering_opt` being false means we exclude this type from random field shuffling. However, `packed(1)` types can still be shuffled! The logic was added in https://github.com/rust-lang/rust/pull/48528 since it's pointless to reorder fields in packed(1) types (there's no padding that could be saved) -- but that shouldn't inhibit `-Zrandomize-layout` (which did not exist at the time). We could add an optimization elsewhere to not bother sorting the fields for `repr(packed)` types, but I don't think that's worth the effort. This *does* change the behavior in that we may now reorder fields of `packed(1)` structs (e.g. if there are niches, we'll try to move them to the start/end, according to `NicheBias`). We were always allowed to do that but so far we didn't. Quoting the [reference](https://doc.rust-lang.org/reference/type-layout.html): > On their own, align and packed do not provide guarantees about the order of fields in the layout of a struct or the layout of an enum variant, although they may be combined with representations (such as C) which do provide such guarantees.
2024-05-29Revert miri async drop test but add warnings to each async drop testDaria Sukhonina-50/+34
2024-05-29Bless new async destructor sizes in async drop testsDaria Sukhonina-5/+5
2024-05-29Add size check inside of the async drop testsDaria Sukhonina-29/+50
2024-05-29Rollup merge of #125633 - RalfJung:miri-no-copy, r=saethlin许杰友 Jieyou Xu (Joe)-37/+19
miri: avoid making a full copy of all new allocations Hopefully fixes https://github.com/rust-lang/miri/issues/3637 r? ``@saethlin``
2024-05-28Add Miri smoke pass test for ptr_metadata intrinsicScott McMurray-1/+7
2024-05-28Add Miri tests for `PtrMetadata` UBScott McMurray-0/+142
2024-05-27miri: avoid making a full copy of all new allocationsRalf Jung-37/+19
2024-05-27Rollup merge of #125616 - RalfJung:mir-validate-downcast-projection, ↵Matthias Krüger-1/+1
r=compiler-errors MIR validation: ensure that downcast projection is followed by field projection Cc https://github.com/rust-lang/rust/issues/120369
2024-05-27MIR validation: ensure that downcast projection is followed by field projectionRalf Jung-1/+1
2024-05-27interpret: get rid of 'mir lifetime everywhereRalf Jung-493/+440
2024-05-27interpret: the MIR is actually at lifetime 'tcxRalf Jung-23/+29
2024-05-26Auto merge of #3631 - RalfJung:blocking-refactor, r=RalfJungbors-1043/+951
completely refactor how we manage blocking and unblocking threads This hides a lot of invariants from the implementation of the synchronization primitives, and makes sure we never have to release or acquire a vector clock on another thread but the active one.
2024-05-26add a macro to declare thread unblock callbacksRalf Jung-249/+256
2024-05-26Auto merge of #3632 - RalfJung:readdir, r=RalfJungbors-35/+33
unix/fs: a bit of cleanup in macos_fbsd_readdir_r
2024-05-26unix/fs: a bit of cleanup in macos_fbsd_readdir_rRalf Jung-35/+33
2024-05-26fix './miri run --dep --target _'Ralf Jung-1/+7
2024-05-26data_race: vector indices can be reused immediately when the thread is goneRalf Jung-82/+37
2024-05-26completely refactor how we manage blocking and unblocking threadsRalf Jung-895/+832
2024-05-26make release_clock always work on the current threadRalf Jung-106/+115
2024-05-25Merge from rustcThe Miri Cronjob Bot-1/+1
2024-05-25Preparing for merge from rustcThe Miri Cronjob Bot-1/+1
2024-05-24miri: receive the blessings of validate.rsJubilee Young-1/+1
2024-05-24Auto merge of #3626 - devnexen:pthread_name_illumos, r=oli-obkbors-5/+34
solaris add support for threadname. from std::unix::thread::set_name, pthread_setname_np is a weak symbol (not always had been available). Other than that, similar to linux only having twice of its buffer limit.
2024-05-24Auto merge of #3625 - Strophox:miri-allocation-fix, r=RalfJungbors-23/+24
Bugfix `MiriAllocBytes` to guarantee different addresses Fix in `alloc_bytes.rs` following https://github.com/rust-lang/miri/pull/3526 Currently when an allocation of `size == 0` is requested we return a `std::ptr::without_provenance_mut(align)`, but this means returned `ptr`s may overlap, which breaks things.
2024-05-24extend commentsRalf Jung-2/+3
2024-05-24Auto merge of #3628 - RalfJung:tokio, r=RalfJungbors-1/+13
add back some tokio features Turns out I went a bit too fer when I removed features, so `socketpair` was no longer used.
2024-05-24add back some tokio featuresRalf Jung-1/+13
2024-05-24fmtThe Miri Cronjob Bot-2/+7
2024-05-24Merge from rustcThe Miri Cronjob Bot-92/+90
2024-05-24Preparing for merge from rustcThe Miri Cronjob Bot-1/+1
2024-05-23solaris add suport for threadname.David Carlier-5/+34
from std::unix::thread::set_name, pthread_setname_np is a weak symbol (not always had been available). Other than that, similar to linux only having twice of its buffer limit.
2024-05-23differentiate between layout and alloc_layoutStrophox-10/+18
2024-05-23fix alloc_bytes (always allocate at least 1B)Strophox-23/+15
2024-05-23Rollup merge of #124976 - petrochenkov:usedcrates, r=oli-obkMatthias Krüger-2/+2
rustc: Use `tcx.used_crates(())` more And explain when it should be used. Addresses comments from https://github.com/rust-lang/rust/pull/121167.
2024-05-23fmtThe Miri Cronjob Bot-4/+1
2024-05-23Merge from rustcThe Miri Cronjob Bot-345/+82
2024-05-23Preparing for merge from rustcThe Miri Cronjob Bot-1/+1
2024-05-23Auto merge of #125359 - RalfJung:interpret-overflowing-ops, r=oli-obkbors-90/+88
interpret: make overflowing binops just normal binops Follow-up to https://github.com/rust-lang/rust/pull/125173 (Cc `@scottmcm)`
2024-05-22Rollup merge of #124896 - RalfJung:miri-intrinsic-fallback, r=oli-obkLeón Orell Valerian Liehr-18/+18
miri: rename intrinsic_fallback_checks_ub to intrinsic_fallback_is_spec Checking UB is not the only concern, we also have to make sure we are not losing out on non-determinism. r? ``@oli-obk`` (not urgent, take your time)
2024-05-22solaris/illumos localtime_r / clock_getime support enabled.David Carlier-29/+44
clock_gettime support CLOCK_REALTIME/CLOCK_MONOTONIC clockid_t. localtime_r is supported only tm struct is more limited than other supported platforms.
2024-05-22rustc: Use `tcx.used_crates(())` moreVadim Petrochenkov-2/+2
And explain when it should be used.
2024-05-22Auto merge of #117329 - RalfJung:offset-by-zero, r=oli-obk,scottmcmbors-327/+64
offset: allow zero-byte offset on arbitrary pointers As per prior `@rust-lang/opsem` [discussion](https://github.com/rust-lang/opsem-team/issues/10) and [FCP](https://github.com/rust-lang/unsafe-code-guidelines/issues/472#issuecomment-1793409130): - Zero-sized reads and writes are allowed on all sufficiently aligned pointers, including the null pointer - Inbounds-offset-by-zero is allowed on all pointers, including the null pointer - `offset_from` on two pointers derived from the same allocation is always allowed when they have the same address This removes surprising UB (in particular, even C++ allows "nullptr + 0", which we currently disallow), and it brings us one step closer to an important theoretical property for our semantics ("provenance monotonicity": if operations are valid on bytes without provenance, then adding provenance can't make them invalid). The minimum LLVM we require (v17) includes https://reviews.llvm.org/D154051, so we can finally implement this. The `offset_from` change is needed to maintain the equivalence with `offset`: if `let ptr2 = ptr1.offset(N)` is well-defined, then `ptr2.offset_from(ptr1)` should be well-defined and return N. Now consider the case where N is 0 and `ptr1` dangles: we want to still allow offset_from here. I think we should change offset_from further, but that's a separate discussion. Fixes https://github.com/rust-lang/rust/issues/65108 [Tracking issue](https://github.com/rust-lang/rust/issues/117945) | [T-lang summary](https://github.com/rust-lang/rust/pull/117329#issuecomment-1951981106) Cc `@nikic`
2024-05-22clippyRalf Jung-8/+10
2024-05-22Merge from rustcRalf Jung-20/+37
2024-05-22Preparing for merge from rustcRalf Jung-1/+1