summary refs log tree commit diff
path: root/src/tools/miri
AgeCommit message (Collapse)AuthorLines
2024-03-04Improve wording of static_mut_refObei Sideg-6/+6
Rename `static_mut_ref` lint to `static_mut_refs`. (cherry picked from commit 408eeae59d35cbcaab2cfb345d24373954e74fc5)
2024-02-08[Beta 1.77] Fix bootstrapping from 1.76Eric Huss-1/+1
2024-01-30Remove the lifetime from `DiagnosticArgValue`.Nicholas Nethercote-1/+1
Because it's almost always static. This makes `impl IntoDiagnosticArg for DiagnosticArgValue` trivial, which is nice. There are a few diagnostics constructed in `compiler/rustc_mir_build/src/check_unsafety.rs` and `compiler/rustc_mir_transform/src/errors.rs` that now need symbols converted to `String` with `to_string` instead of `&str` with `as_str`, but that' no big deal, and worth it for the simplifications elsewhere.
2024-01-29Auto merge of #120451 - RalfJung:miri, r=RalfJungbors-172/+235
Miri subtree update r? `@ghost`
2024-01-28Auto merge of #3181 - devnexen:stat_calls_fbsd, r=RalfJungbors-41/+118
freebsd add *stat calls interception support
2024-01-28tweak commentsRalf Jung-2/+2
2024-01-27fix typo in operator.rsRalf Jung-1/+1
2024-01-26interpret: project_downcast: do not ICE for uninhabited variantsRalf Jung-0/+16
2024-01-26alidate the operand passed to is_val_statically_knownRalf Jung-1/+2
2024-01-26fmtThe Miri Conjob Bot-3/+5
2024-01-26Merge from rustcThe Miri Conjob Bot-2/+115
2024-01-26Preparing for merge from rustcThe Miri Conjob Bot-1/+1
2024-01-25Auto merge of #3233 - RalfJung:trophy, r=RalfJungbors-0/+1
Add portable-atomic-util bug to "bugs found" list At least, reading https://notgull.net/cautionary-unsafe-tale/ it seems fair to say Miri found this bug. `@notgull` please let me know if you are okay with having this listed here.
2024-01-25Auto merge of #119911 - NCGThompson:is-statically-known, r=oli-obkbors-0/+27
Replacement of #114390: Add new intrinsic `is_var_statically_known` and optimize pow for powers of two This adds a new intrinsic `is_val_statically_known` that lowers to [``@llvm.is.constant.*`](https://llvm.org/docs/LangRef.html#llvm-is-constant-intrinsic).` It also applies the intrinsic in the int_pow methods to recognize and optimize the idiom `2isize.pow(x)`. See #114390 for more discussion. While I have extended the scope of the power of two optimization from #114390, I haven't added any new uses for the intrinsic. That can be done in later pull requests. Note: When testing or using the library, be sure to use `--stage 1` or higher. Otherwise, the intrinsic will be a noop and the doctests will be skipped. If you are trying out edits, you may be interested in [`--keep-stage 0`](https://rustc-dev-guide.rust-lang.org/building/suggested.html#faster-builds-with---keep-stage). Fixes #47234 Resolves #114390 `@Centri3`
2024-01-24Auto merge of #118336 - saethlin:const-to-op-cache, r=RalfJungbors-2/+88
Return a finite number of AllocIds per ConstAllocation in Miri Before this, every evaluation of a const slice would produce a new AllocId. So in Miri, this program used to have unbounded memory use: ```rust fn main() { loop { helper(); } } fn helper() { "ouch"; } ``` Every trip around the loop creates a new AllocId which we need to keep track of a base address for. And the provenance GC can never clean up that AllocId -> u64 mapping, because the AllocId is for a const allocation which will never be deallocated. So this PR moves the logic of producing an AllocId for a ConstAllocation to the Machine trait, and the implementation that Miri provides will only produce 16 AllocIds for each allocation. The cache is also keyed on the Instance that the const is evaluated in, so that equal consts evaluated in two functions will have disjoint base addresses. r? RalfJung
2024-01-24a bit of refactoring for find_mir_or_eval_fnRalf Jung-43/+15
2024-01-24add __cxa_thread_atexit_impl on freebsdRalf Jung-0/+1
2024-01-24refactor extern static handlingRalf Jung-73/+82
2024-01-24disable freeBSD tests for nowRalf Jung-2/+3
2024-01-24Merge from rustcThe Miri Conjob Bot-2/+6
2024-01-24Preparing for merge from rustcThe Miri Conjob Bot-1/+1
2024-01-23Auto merge of #119044 - RalfJung:intern-without-types, r=oli-obkbors-2/+6
const-eval interning: get rid of type-driven traversal This entirely replaces our const-eval interner, i.e. the code that takes the final result of a constant evaluation from the local memory of the const-eval machine to the global `tcx` memory. The main goal of this change is to ensure that we can detect mutable references that sneak into this final value -- this is something we want to reject for `static` and `const`, and while const-checking performs some static analysis to ensure this, I would be much more comfortable stabilizing const_mut_refs if we had a dynamic check that sanitizes the final value. (This is generally the approach we have been using on const-eval: do a static check to give nice errors upfront, and then do a dynamic check to be really sure that the properties we need for soundness, actually hold.) We can do this now that https://github.com/rust-lang/rust/pull/118324 landed and each pointer comes with a bit (completely independent of its type) storing whether mutation is permitted through this pointer or not. The new interner is a lot simpler than the old one: previously we did a complete type-driven traversal to determine the mutability of all memory we see, and then a second pass to intern any leftover raw pointers. The new interner simply recursively traverses the allocation holding the final result, and all allocations reachable from it (which can be determined from the raw bytes of the result, without knowing anything about types), and ensures they all get interned. The initial allocation is interned as immutable for `const` and pomoted and non-interior-mutable `static`; all other allocations are interned as immutable for `static`, `const`, and promoted. The main subtlety is justifying that those inner allocations may indeed be interned immutably, i.e., that mutating them later would anyway already be UB: - for promoteds, we rely on the analysis that does promotion to ensure that this is sound. - for `const` and `static`, we check that all pointers in the final result that point to things that are new (i.e., part of this const evaluation) are immutable, i.e., were created via `&<expr>` at a non-interior-mutable type. Mutation through immutable pointers is UB so we are free to intern that memory as immutable. Interning raises an error if it encounters a dangling pointer or a mutable pointer that violates the above rules. I also extended our type-driven const validity checks to ensure that `&mut T` in the final value of a const points to mutable memory, at least if `T` is not zero-sized. This catches cases of people turning `&i32` into `&mut i32` (which would still be considered a read-only pointer). Similarly, when these checks encounter an `UnsafeCell`, they are checking that it lives in mutable memory. (Both of these only traverse the newly created values; if those point to other consts/promoteds, the check stops there. But that's okay, we don't have to catch all the UB.) I co-developed this with the stricter interner changes but I can split it out into a separate PR if you prefer. This PR does have the immediate effect of allowing some new code on stable, for instance: ```rust const CONST_RAW: *const Vec<i32> = &Vec::new() as *const _; ``` Previously that code got rejected since the type-based interner didn't know what to do with that pointer. It's a raw pointer, we cannot trust its type. The new interner does not care about types so it sees no issue with this code; there's an immutable pointer pointing to some read-only memory (storing a `Vec<i32>`), all is good. Accepting this code pretty much commits us to non-type-based interning, but I think that's the better strategy anyway. This PR also leads to slightly worse error messages when the final value of a const contains a dangling reference. Previously we would complete interning and then the type-based validation would detect this dangling reference and show a nice error saying where in the value (i.e., in which field) the dangling reference is located. However, the new interner cannot distinguish dangling references from dangling raw pointers, so it must throw an error when it encounters either of them. It doesn't have an understanding of the value structure so all it can say is "somewhere in this constant there's a dangling pointer". (Later parts of the compiler don't like dangling pointers/references so we have to reject them either during interning or during validation.) This could potentially be improved by doing validation before interning, but that's a larger change that I have not attempted yet. (It's also subtle since we do want validation to use the final mutability bits of all involved allocations, and currently it is interning that marks a bunch of allocations as immutable -- that would have to still happen before validation.) `@rust-lang/wg-const-eval` I hope you are okay with this plan. :) `@rust-lang/lang` paging you in since this accepts new code on stable as explained above. Please let me know if you think FCP is necessary.
2024-01-23Merge from rustcThe Miri Conjob Bot-2/+9
2024-01-23Preparing for merge from rustcThe Miri Conjob Bot-1/+1
2024-01-22Revert "Auto merge of #118133 - Urgau:stabilize_trait_upcasting, r=WaffleLapkin"Oli Scherer-2/+9
This reverts commit 6d2b84b3ed7848fd91b8d6151d4451b3103ed816, reversing changes made to 73bc12199ea8c7651ed98b069c0dd6b0bb5fabcf.
2024-01-22const-eval interner: from-scratch rewrite using mutability information from ↵Ralf Jung-2/+6
provenance rather than types
2024-01-22update comment about CARGO_MAKEFLAGSRalf Jung-5/+4
2024-01-21update lockfileRalf Jung-2/+2
2024-01-21Merge from rustcThe Miri Conjob Bot-18/+10
2024-01-21Preparing for merge from rustcThe Miri Conjob Bot-1/+1
2024-01-20Rollup merge of #120150 - Jules-Bertholet:stabilize-round-ties-even, r=cuviperMatthias Krüger-2/+0
Stabilize `round_ties_even` Closes #96710 `@rustbot` label -T-libs T-libs-api
2024-01-19Stabilize `round_ties_even`Jules Bertholet-2/+0
2024-01-19Add new intrinsic `is_constant` and optimize `pow`Catherine Flores-0/+27
Fix overflow check Make MIRI choose the path randomly and rename the intrinsic Add back test Add miri test and make it operate on `ptr` Define `llvm.is.constant` for primitives Update MIRI comment and fix test in stage2 Add const eval test Clarify that both branches must have the same side effects guaranteed non guarantee use immediate type instead Co-Authored-By: Ralf Jung <post@ralfj.de>
2024-01-19Rollup merge of #119984 - kpreid:waker-noop, r=dtolnayMatthias Krüger-12/+6
Change return type of unstable `Waker::noop()` from `Waker` to `&Waker`. The advantage of this is that it does not need to be assigned to a variable to be used in a `Context` creation, which is the most common thing to want to do with a noop waker. It also avoids unnecessarily executing the dynamically dispatched drop function when the noop waker is dropped. If an owned noop waker is desired, it can be created by cloning, but the reverse is harder to do since it requires declaring a constant. Alternatively, both versions could be provided, like `futures::task::noop_waker()` and `futures::task::noop_waker_ref()`, but that seems to me to be API clutter for a very small benefit, whereas having the `&'static` reference available is a large reduction in boilerplate. [Previous discussion on the tracking issue starting here](https://github.com/rust-lang/rust/issues/98286#issuecomment-1862159766)
2024-01-19Auto merge of #120121 - matthiaskrgr:rollup-razammh, r=matthiaskrgrbors-2/+2
Rollup of 10 pull requests Successful merges: - #118665 (Consolidate all associated items on the NonZero integer types into a single impl block per type) - #118798 (Use AtomicU8 instead of AtomicUsize in backtrace.rs) - #119062 (Deny braced macro invocations in let-else) - #119138 (Docs: Use non-SeqCst in module example of atomics) - #119907 (Update `fn()` trait implementation docs) - #120083 (Warn when not having a profiler runtime means that coverage tests won't be run/blessed) - #120107 (dead_code treats #[repr(transparent)] the same as #[repr(C)]) - #120110 (Update documentation for Vec::into_boxed_slice to be more clear about excess capacity) - #120113 (Remove myself from review rotation) - #120118 (Fix typo in documentation in base.rs) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-18Remove no-longer-needed `allow(dead_code)` from Miri testsJake Goulding-2/+2
`repr(transparent)` now silences the lint.
2024-01-19Fix typo in munmap_partial.rsIkko Eltociear Ashimine-1/+1
addres -> address
2024-01-17Remove unnecessary `let`s and borrowing from `Waker::noop()` usage.Kevin Reid-12/+6
`Waker::noop()` now returns a `&'static Waker` reference, so it can be passed directly to `Context` creation with no temporary lifetime issue.
2024-01-17Auto merge of #119111 - michaelwoerister:measureme-11, r=Mark-Simulacrumbors-1/+1
Update measureme crate to version 11 perf.rlo has been updated to use 11.0.0 already, so it should be able to handle the new file format. r? `@Mark-Simulacrum` Fixes https://github.com/rust-lang/rust/issues/99282 Fixes https://github.com/rust-lang/rust/issues/119103
2024-01-14fmtThe Miri Conjob Bot-2/+2
2024-01-14Merge from rustcThe Miri Conjob Bot-32/+32
2024-01-14Preparing for merge from rustcThe Miri Conjob Bot-1/+1
2024-01-13Update measureme crate to version 11Michael Woerister-1/+1
2024-01-13Auto merge of #117285 - joboet:move_platforms_to_pal, r=ChrisDentonbors-32/+32
Move platform modules into `sys::pal` This is the initial step of #117276. `sys` just re-exports everything from the current `sys` for now, I'll move the implementations for the individual features one-by-one after this PR merges.
2024-01-13Merge from rustcThe Miri Conjob Bot-1/+0
2024-01-13Preparing for merge from rustcThe Miri Conjob Bot-1/+1
2024-01-12Revert "Auto merge of #118568 - DianQK:no-builtins-symbols, r=pnkfelix"DianQK-1/+0
This reverts commit 503e129328080e924c0ddfca6abf4c2812580102, reversing changes made to 0e7f91b75e7484a713e2f644212cfc1aa7478a28.
2024-01-12update paths in commentsjoboet-2/+2
2024-01-11std: update miri testsjoboet-28/+28
2024-01-11miri: update reference to PAL module on Windowsjoboet-2/+2