about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret/place.rs
AgeCommit message (Collapse)AuthorLines
2025-09-10interpret: fix overlapping aggregate initializationRalf Jung-1/+1
2025-08-19Rollup merge of #145585 - RalfJung:miri-inplace-arg-checks, r=compiler-errors许杰友 Jieyou Xu (Joe)-0/+6
Miri: fix handling of in-place argument and return place handling This fixes two separate bugs (in two separate commits): - If the return place is `_local` and not `*ptr`, we didn't always properly protect it if there were other pointers pointing to that return place. - If two in-place arguments are *the same* local variable, we didn't always detect that aliasing.
2025-08-18interpret: fix in-place return place semantics when the return place ↵Ralf Jung-0/+6
expression is a local variable
2025-08-18interpret: avoid forcing all integer newtypes into memory during ↵Ralf Jung-0/+7
clear_provenance
2025-08-17Auto merge of #144081 - RalfJung:const-ptr-fragments, r=oli-obkbors-4/+4
const-eval: full support for pointer fragments This fixes https://github.com/rust-lang/const-eval/issues/72 and makes `swap_nonoverlapping` fully work in const-eval by enhancing per-byte provenance tracking with tracking of *which* of the bytes of the pointer this one is. Later, if we see all the same bytes in the exact same order, we can treat it like a whole pointer again without ever risking a leak of the data bytes (that encode the offset into the allocation). This lifts the limitation that was discussed quite a bit in https://github.com/rust-lang/rust/pull/137280. For a concrete piece of code that used to fail and now works properly consider this example doing a byte-for-byte memcpy in const without using intrinsics: ```rust use std::{mem::{self, MaybeUninit}, ptr}; type Byte = MaybeUninit<u8>; const unsafe fn memcpy(dst: *mut Byte, src: *const Byte, n: usize) { let mut i = 0; while i < n { *dst.add(i) = *src.add(i); i += 1; } } const _MEMCPY: () = unsafe { let ptr = &42; let mut ptr2 = ptr::null::<i32>(); // Copy from ptr to ptr2. memcpy(&mut ptr2 as *mut _ as *mut _, &ptr as *const _ as *const _, mem::size_of::<&i32>()); assert!(*ptr2 == 42); }; ``` What makes this code tricky is that pointers are "opaque blobs" in const-eval, we cannot just let people look at the individual bytes since *we don't know what those bytes look like* -- that depends on the absolute address the pointed-to object will be placed at. The code above "breaks apart" a pointer into individual bytes, and then puts them back together in the same order elsewhere. This PR implements the logic to properly track how those individual bytes relate to the original pointer, and to recognize when they are in the right order again. We still reject constants where the final value contains a not-fully-put-together pointer: I have no idea how one could construct an LLVM global where one byte is defined as "the 3rd byte of a pointer to that other global over there" -- and even if LLVM supports this somehow, we can leave implementing that to a future PR. It seems unlikely to me anyone would even want this, but who knows.^^ This also changes the behavior of Miri, by tracking the order of bytes with provenance and only considering a pointer to have valid provenance if all bytes are in the original order again. This is related to https://github.com/rust-lang/unsafe-code-guidelines/issues/558. It means one cannot implement XOR linked lists with strict provenance any more, which is however only of theoretical interest. Practically I am curious if anyone will show up with any code that Miri now complains about - that would be interesting data. Cc `@rust-lang/opsem`
2025-08-11Turn _span into _trace as trace span nameStypox-1/+1
_span could possibly be confused with the Span type in rustc
2025-07-31Add tracing to more functions related to step.rsStypox-0/+5
2025-07-30const-eval: full support for pointer fragmentsRalf Jung-4/+4
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-1/+1
2025-06-29rename Pointer::from_addr_invalid to match strict provenance APIRalf Jung-1/+1
2025-06-27Rollup merge of #143046 - RalfJung:zst-unsafe-cell, r=lcnr,oli-obkMatthias Krüger-5/+5
const validation: properly ignore zero-sized UnsafeCell Fixes https://github.com/rust-lang/rust/issues/142948 r? `@oli-obk`
2025-06-27Add InterpCx::layout_of with tracing, shadowing LayoutOfStypox-1/+1
2025-06-26make size_and_align_of_mplace work on all projectableRalf Jung-5/+5
2025-06-25make `tidy-alphabetical` use a natural sortFolkert de Vries-1/+1
2025-01-28miri: optimize zeroed allocSpecificProtagonist-4/+4
Co-authored-by: Ralf Jung <post@ralfj.de>
2025-01-07Avoid naming variables `str`Josh Triplett-2/+2
This renames variables named `str` to other names, to make sure `str` always refers to a type. It's confusing to read code where `str` (or another standard type name) is used as an identifier. It also produces misleading syntax highlighting.
2024-12-25swap_typed_nonoverlapping: properly detect overlap even when swapping scalar ↵Ralf Jung-26/+5
values
2024-12-09interpret: clean up deduplicating allocation functionsRalf Jung-27/+17
2024-12-07Add allocate_bytes and refactor allocate_str in InterpCx for raw byte allocationshamb0-13/+32
Signed-off-by: shamb0 <r.raajey@gmail.com>
2024-11-19`InterpCx` store `TypingEnv` instead of a `ParamEnv`lcnr-2/+2
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-9/+3
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-10-31stop using `ParamEnv::reveal` while handling MIRlcnr-2/+8
2024-10-29compiler: `rustc_abi::Abi` => `BackendRepr`Jubilee Young-4/+8
The initial naming of "Abi" was an awful mistake, conveying wrong ideas about how psABIs worked and even more about what the enum meant. It was only meant to represent the way the value would be described to a codegen backend as it was lowered to that intermediate representation. It was never meant to mean anything about the actual psABI handling! The conflation is because LLVM typically will associate a certain form with a certain ABI, but even that does not hold when the special cases that actually exist arise, plus the IR annotations that modify the ABI. Reframe `rustc_abi::Abi` as the `BackendRepr` of the type, and rename `BackendRepr::Aggregate` as `BackendRepr::Memory`. Unfortunately, due to the persistent misunderstandings, this too is now incorrect: - Scattered ABI-relevant code is entangled with BackendRepr - We do not always pre-compute a correct BackendRepr that reflects how we "actually" want this value to be handled, so we leave the backend interface to also inject various special-cases here - In some cases `BackendRepr::Memory` is a "real" aggregate, but in others it is in fact using memory, and in some cases it is a scalar! Our rustc-to-backend lowering code handles this sort of thing right now. That will eventually be addressed by lifting duplicated lowering code to either rustc_codegen_ssa or rustc_target as appropriate.
2024-10-03interpret: Immediate::offset: use shared sanity-check function to ensure ↵Ralf Jung-2/+6
invariant
2024-10-02Auto merge of #131006 - RalfJung:immediate-sanity, r=saethlinbors-3/+5
interpret: always enable write_immediate sanity checks Writing a wrongly-sized scalar somewhere can have quite confusing effects. Let's see how expensive it is to catch this early.
2024-10-01make InterpResult a dedicated type to avoid accidentally discarding the errorRalf Jung-40/+36
2024-09-30panic when an interpreter error gets unintentionally discardedRalf Jung-6/+13
2024-09-29interpret: always enable write_immediate sanity checksRalf Jung-3/+5
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-4/+4
2024-09-15Rollup merge of #129828 - RalfJung:miri-data-race, r=saethlinMatthias Krüger-9/+22
miri: treat non-memory local variables properly for data race detection Fixes https://github.com/rust-lang/miri/issues/3242 Miri has an optimization where some local variables are not represented in memory until something forces them to be stored in memory (most notably, creating a pointer/reference to the local will do that). However, for a subsystem triggering on memory accesses -- such as the data race detector -- this means that the memory access seems to happen only when the local is moved to memory, instead of at the time that it actually happens. This can lead to UB reports in programs that do not actually have UB. This PR fixes that by adding machine hooks for reads and writes to such efficiently represented local variables. The data race system tracks those very similar to how it would track reads and writes to addressable memory, and when a local is moved to memory, the clocks get overwritten with the information stored for the local.
2024-09-13interpret: simplify SIMD type handlingRalf Jung-23/+22
2024-09-10interpret: mark some hot functions inline(always)Ralf Jung-0/+3
recovers some of the perf regressions from #129778
2024-09-10miri: treat non-memory local variables properly for data race detectionRalf Jung-9/+22
2024-09-08interpret: reset padding during validationRalf Jung-7/+10
2024-09-08interpret: reset provenance on typed copiesRalf Jung-25/+44
2024-09-08interpret: factor out common code for place mutationRalf Jung-81/+62
2024-09-08interpret: make Writeable trait about a to_place operationRalf Jung-17/+12
2024-09-08interpret: remove Readable trait, we can use Projectable insteadRalf Jung-7/+7
2024-09-03Auto merge of #129777 - nnethercote:unreachable_pub-4, r=Urgaubors-2/+2
Add `unreachable_pub`, round 4 A follow-up to #129732. r? `@Urgau`
2024-09-03Add `warn(unreachable_pub)` to `rustc_const_eval`.Nicholas Nethercote-2/+2
2024-09-02chore: Fix typos in 'compiler' (batch 1)Alexander Cyon-1/+1
2024-08-31interpret, codegen: tweak some comments and checks regarding Box with custom ↵Ralf Jung-5/+7
allocator
2024-08-06miri: make vtable addresses not globally uniqueRalf Jung-1/+2
2024-08-03Miri: add a flag to do recursive validity checkingRalf Jung-3/+12
2024-08-01interpret: simplify pointer arithmetic logicRalf Jung-4/+2
2024-08-01on a signed deref check, mention the right pointer in the errorRalf Jung-7/+3
2024-07-29Reformat `use` declarations.Nicholas Nethercote-5/+4
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-14Add cache for `allocate_str`Adwin White-1/+13
2024-06-21interpret: use trace to reduce noiceLzu Tao-6/+6
2024-06-12Rollup merge of #126232 - RalfJung:dyn-trait-equality, r=oli-obkGuillaume Gomez-49/+0
interpret: dyn trait metadata check: equate traits in a proper way Hopefully fixes https://github.com/rust-lang/miri/issues/3541... unfortunately we don't have a testcase. The first commit is just a refactor without functional change. r? `@oli-obk`